|
24 | 24 | \ref{alg.sorting} & Sorting and related operations & \\ \rowsep
|
25 | 25 | \ref{numeric.ops} & Generalized numeric operations & \tcode{<numeric>} \\ \rowsep
|
26 | 26 | \ref{specialized.algorithms} & Specialized \tcode{<memory>} algorithms & \tcode{<memory>} \\ \rowsep
|
| 27 | +\ref{alg.rand} & Specialized \tcode{<random>} algorithms & \tcode{<random>} \\ \rowsep |
27 | 28 | \ref{alg.c.library} & C library algorithms & \tcode{<cstdlib>} \\
|
28 | 29 | \end{libsumtab}
|
29 | 30 |
|
@@ -11667,6 +11668,138 @@
|
11667 | 11668 | \end{codeblock}
|
11668 | 11669 | \end{itemdescr}
|
11669 | 11670 |
|
| 11671 | +\rSec1[alg.rand]{Specialized \tcode{<random>} algorithms} |
| 11672 | + |
| 11673 | +\rSec2[alg.rand.general]{General} |
| 11674 | + |
| 11675 | +\pnum |
| 11676 | +The contents specified in \ref{alg.rand} |
| 11677 | +are declared in the header \libheaderrefx{random}{rand.synopsis}. |
| 11678 | + |
| 11679 | +\rSec2[alg.rand.generate]{\tcode{generate_random}} |
| 11680 | + |
| 11681 | +\begin{itemdecl} |
| 11682 | +template<class R, class G> |
| 11683 | + requires @\libconcept{output_range}@<R, invoke_result_t<G&>> && @\libconcept{uniform_random_bit_generator}@<remove_cvref_t<G>> |
| 11684 | +constexpr borrowed_iterator_t<R> ranges::generate_random(R&& r, G&& g); |
| 11685 | +\end{itemdecl} |
| 11686 | + |
| 11687 | +\begin{itemdescr} |
| 11688 | +\pnum |
| 11689 | +\effects |
| 11690 | +\begin{itemize} |
| 11691 | +\item |
| 11692 | +Calls \tcode{g.generate_random(std::forward<R>(r))} |
| 11693 | +if this expression is well-formed. |
| 11694 | +\item |
| 11695 | +Otherwise, if \tcode{R} models \tcode{sized_range}, |
| 11696 | +fills \tcode{r} with \tcode{ranges::size(r)} values of |
| 11697 | +type \tcode{invoke_result_t<G\&>} by performing |
| 11698 | +an unspecified number of invocations of |
| 11699 | +the form \tcode{g()} or \tcode{g.generate_random(s)}, |
| 11700 | +if such an expression is well-formed for a value \tcode{N} and |
| 11701 | +an object \tcode{s} of type \tcode{span<invoke_result_t<G\&>, N>}. |
| 11702 | +\begin{note} |
| 11703 | +Values of \tcode{N} can differ between invocations. |
| 11704 | +\end{note} |
| 11705 | +\item |
| 11706 | +Otherwise, calls \tcode{ranges::generate(std::forward<R>(r), ref(g))}. |
| 11707 | +\end{itemize} |
| 11708 | + |
| 11709 | +\pnum |
| 11710 | +\returns |
| 11711 | +\tcode{ranges::end(r)}. |
| 11712 | + |
| 11713 | +\pnum |
| 11714 | +\remarks |
| 11715 | +The effects of \tcode{generate_random(r, g)} shall be equivalent to |
| 11716 | +\tcode{ranges::generate(std::for\-ward<R>(r), ref(g))}. |
| 11717 | +\begin{note} |
| 11718 | +This implies that \tcode{g.generate_random(a)} fills \tcode{a} |
| 11719 | +with the same values as produced by invocation of \tcode{g()}. |
| 11720 | +\end{note} |
| 11721 | +\end{itemdescr} |
| 11722 | + |
| 11723 | +\begin{itemdecl} |
| 11724 | +template<class G, @\libconcept{output_iterator}@<invoke_result_t<G&>> O, @\libconcept{sentinel_for}@<O> S> |
| 11725 | + requires @\libconcept{uniform_random_bit_generator}@<remove_cvref_t<G>> |
| 11726 | +constexpr O ranges::generate_random(O first, S last, G&& g); |
| 11727 | +\end{itemdecl} |
| 11728 | + |
| 11729 | +\begin{itemdescr} |
| 11730 | +\pnum |
| 11731 | +\effects |
| 11732 | +Equivalent to: |
| 11733 | +\begin{codeblock} |
| 11734 | +return generate_random(subrange<O, S>(std::move(first), last), g); |
| 11735 | +\end{codeblock} |
| 11736 | +\end{itemdescr} |
| 11737 | + |
| 11738 | +\begin{itemdecl} |
| 11739 | +template<class R, class G, class D> |
| 11740 | + requires @\libconcept{output_range}@<R, invoke_result_t<D&, G&>> && @\libconcept{invocable}@<D&, G&> && |
| 11741 | + @\libconcept{uniform_random_bit_generator}@<remove_cvref_t<G>> |
| 11742 | +constexpr borrowed_iterator_t<R> ranges::generate_random(R&& r, G&& g, D&& d); |
| 11743 | +\end{itemdecl} |
| 11744 | + |
| 11745 | +\begin{itemdescr} |
| 11746 | +\pnum |
| 11747 | +\effects |
| 11748 | +\begin{itemize} |
| 11749 | +\item |
| 11750 | +Calls \tcode{d.generate_random(std::forward<R>(r), g)} |
| 11751 | +if this expression is well-formed. |
| 11752 | +\item |
| 11753 | +Otherwise, if \tcode{R} models \tcode{sized_range}, |
| 11754 | +fills \tcode{r} with \tcode{ranges::size(r)} values of |
| 11755 | +type \tcode{invoke_result_t<D\&, G\&>} |
| 11756 | +by performing an unspecified number of invocations of |
| 11757 | +the form \tcode{invoke(d, g)} or \tcode{d.generate_random(s, g)}, |
| 11758 | +if such an expression is well-formed |
| 11759 | +for a value \tcode{N} and |
| 11760 | +an object \tcode{s} of type \tcode{span<invoke_result_t<D\&, G\&>, N>}. |
| 11761 | +\begin{note} |
| 11762 | +Values of N can differ between invocations. |
| 11763 | +\end{note} |
| 11764 | +\item |
| 11765 | +Otherwise, calls |
| 11766 | +\begin{codeblock} |
| 11767 | +ranges::generate(std::forward<R>(r), [&d, &g] { return invoke(d, g); }); |
| 11768 | +\end{codeblock} |
| 11769 | +\end{itemize} |
| 11770 | + |
| 11771 | +\pnum |
| 11772 | +\returns |
| 11773 | +\tcode{ranges::end(r)} |
| 11774 | + |
| 11775 | +\pnum |
| 11776 | +\remarks |
| 11777 | +The effects of \tcode{generate_random(r, g, d)} shall be equivalent to |
| 11778 | +\begin{codeblock} |
| 11779 | +ranges::generate(std::forward<R>(r), [&d, &g] { return invoke(d, g); })} |
| 11780 | +\end{codeblock} |
| 11781 | +\begin{note} |
| 11782 | +This implies that \tcode{d.generate_random(a, g)} |
| 11783 | +fills \tcode{a} with the values with the same random distribution |
| 11784 | +as produced by invocation of \tcode{invoke(d, g)}. |
| 11785 | +\end{note} |
| 11786 | +\end{itemdescr} |
| 11787 | + |
| 11788 | +\begin{itemdecl} |
| 11789 | +template<class G, class D, @\libconcept{output_iterator}@<invoke_result_t<D&, G&>> O, @\libconcept{sentinel_for}@<O> S> |
| 11790 | + requires @\libconcept{invocable}@<D&, G&> && @\libconcept{uniform_random_bit_generator}@<remove_cvref_t<G>> |
| 11791 | +constexpr O ranges::generate_random(O first, S last, G&& g, D&& d); |
| 11792 | +\end{itemdecl} |
| 11793 | + |
| 11794 | +\begin{itemdescr} |
| 11795 | +\pnum |
| 11796 | +\effects |
| 11797 | +Equivalent to: |
| 11798 | +\begin{codeblock} |
| 11799 | +return generate_random(subrange<O, S>(std::move(first), last), g, d); |
| 11800 | +\end{codeblock} |
| 11801 | +\end{itemdescr} |
| 11802 | + |
11670 | 11803 | \rSec1[alg.c.library]{C library algorithms}
|
11671 | 11804 |
|
11672 | 11805 | \pnum
|
|
0 commit comments