|
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 |
|
@@ -11580,6 +11581,138 @@
|
11580 | 11581 | \end{codeblock}
|
11581 | 11582 | \end{itemdescr}
|
11582 | 11583 |
|
| 11584 | +\rSec1[alg.rand]{Specialized \tcode{<random>} algorithms} |
| 11585 | + |
| 11586 | +\rSec2[alg.rand.general]{General} |
| 11587 | + |
| 11588 | +\pnum |
| 11589 | +The contents specified in \ref{alg.rand} |
| 11590 | +are declared in the header \libheaderrefx{random}{rand.synopsis}. |
| 11591 | + |
| 11592 | +\rSec2[alg.rand.generate]{\tcode{generate_random}} |
| 11593 | + |
| 11594 | +\begin{itemdecl} |
| 11595 | +template<class R, class G> |
| 11596 | + requires @\libconcept{output_range}@<R, invoke_result_t<G&>> && @\libconcept{uniform_random_bit_generator}@<remove_cvref_t<G>> |
| 11597 | +constexpr borrowed_iterator_t<R> ranges::generate_random(R&& r, G&& g); |
| 11598 | +\end{itemdecl} |
| 11599 | + |
| 11600 | +\begin{itemdescr} |
| 11601 | +\pnum |
| 11602 | +\effects |
| 11603 | +\begin{itemize} |
| 11604 | +\item |
| 11605 | +Calls \tcode{g.generate_random(std::forward<R>(r))} |
| 11606 | +if this expression is well-formed. |
| 11607 | +\item |
| 11608 | +Otherwise, if \tcode{R} models \tcode{sized_range}, |
| 11609 | +fills \tcode{r} with \tcode{ranges::size(r)} values of |
| 11610 | +type \tcode{invoke_result_t<G\&>} by performing |
| 11611 | +an unspecified number of invocations of |
| 11612 | +the form \tcode{g()} or \tcode{g.generate_random(s)}, |
| 11613 | +if such an expression is well-formed for a value \tcode{N} and |
| 11614 | +an object \tcode{s} of type \tcode{span<invoke_result_t<G\&>, N>}. |
| 11615 | +\begin{note} |
| 11616 | +Values of \tcode{N} can differ between invocations. |
| 11617 | +\end{note} |
| 11618 | +\item |
| 11619 | +Otherwise, calls \tcode{ranges::generate(std::forward<R>(r), ref(g))}. |
| 11620 | +\end{itemize} |
| 11621 | + |
| 11622 | +\pnum |
| 11623 | +\returns |
| 11624 | +\tcode{ranges::end(r)}. |
| 11625 | + |
| 11626 | +\pnum |
| 11627 | +\remarks |
| 11628 | +The effects of \tcode{generate_random(r, g)} shall be equivalent to |
| 11629 | +\tcode{ranges::generate(std::for\-ward<R>(r), ref(g))}. |
| 11630 | +\begin{note} |
| 11631 | +This implies that \tcode{g.generate_random(a)} fills \tcode{a} |
| 11632 | +with the same values as produced by invocation of \tcode{g()}. |
| 11633 | +\end{note} |
| 11634 | +\end{itemdescr} |
| 11635 | + |
| 11636 | +\begin{itemdecl} |
| 11637 | +template<class G, @\libconcept{output_iterator}@<invoke_result_t<G&>> O, @\libconcept{sentinel_for}@<O> S> |
| 11638 | + requires @\libconcept{uniform_random_bit_generator}@<remove_cvref_t<G>> |
| 11639 | +constexpr O ranges::generate_random(O first, S last, G&& g); |
| 11640 | +\end{itemdecl} |
| 11641 | + |
| 11642 | +\begin{itemdescr} |
| 11643 | +\pnum |
| 11644 | +\effects |
| 11645 | +Equivalent to: |
| 11646 | +\begin{codeblock} |
| 11647 | +return generate_random(subrange<O, S>(std::move(first), last), g); |
| 11648 | +\end{codeblock} |
| 11649 | +\end{itemdescr} |
| 11650 | + |
| 11651 | +\begin{itemdecl} |
| 11652 | +template<class R, class G, class D> |
| 11653 | + requires @\libconcept{output_range}@<R, invoke_result_t<D&, G&>> && @\libconcept{invocable}@<D&, G&> && |
| 11654 | + @\libconcept{uniform_random_bit_generator}@<remove_cvref_t<G>> |
| 11655 | +constexpr borrowed_iterator_t<R> ranges::generate_random(R&& r, G&& g, D&& d); |
| 11656 | +\end{itemdecl} |
| 11657 | + |
| 11658 | +\begin{itemdescr} |
| 11659 | +\pnum |
| 11660 | +\effects |
| 11661 | +\begin{itemize} |
| 11662 | +\item |
| 11663 | +Calls \tcode{d.generate_random(std::forward<R>(r), g)} |
| 11664 | +if this expression is well-formed. |
| 11665 | +\item |
| 11666 | +Otherwise, if \tcode{R} models \tcode{sized_range}, |
| 11667 | +fills \tcode{r} with \tcode{ranges::size(r)} values of |
| 11668 | +type \tcode{invoke_result_t<D\&, G\&>} |
| 11669 | +by performing an unspecified number of invocations of |
| 11670 | +the form \tcode{invoke(d, g)} or \tcode{d.generate_random(s, g)}, |
| 11671 | +if such an expression is well-formed |
| 11672 | +for a value \tcode{N} and |
| 11673 | +an object \tcode{s} of type \tcode{span<invoke_result_t<D\&, G\&>, N>}. |
| 11674 | +\begin{note} |
| 11675 | +Values of N can differ between invocations. |
| 11676 | +\end{note} |
| 11677 | +\item |
| 11678 | +Otherwise, calls |
| 11679 | +\begin{codeblock} |
| 11680 | +ranges::generate(std::forward<R>(r), [&d, &g] { return invoke(d, g); }); |
| 11681 | +\end{codeblock} |
| 11682 | +\end{itemize} |
| 11683 | + |
| 11684 | +\pnum |
| 11685 | +\returns |
| 11686 | +\tcode{ranges::end(r)} |
| 11687 | + |
| 11688 | +\pnum |
| 11689 | +\remarks |
| 11690 | +The effects of \tcode{generate_random(r, g, d)} shall be equivalent to |
| 11691 | +\begin{codeblock} |
| 11692 | +ranges::generate(std::forward<R>(r), [&d, &g] { return invoke(d, g); })} |
| 11693 | +\end{codeblock} |
| 11694 | +\begin{note} |
| 11695 | +This implies that \tcode{d.generate_random(a, g)} |
| 11696 | +fills \tcode{a} with the values with the same random distribution |
| 11697 | +as produced by invocation of \tcode{invoke(d, g)}. |
| 11698 | +\end{note} |
| 11699 | +\end{itemdescr} |
| 11700 | + |
| 11701 | +\begin{itemdecl} |
| 11702 | +template<class G, class D, @\libconcept{output_iterator}@<invoke_result_t<D&, G&>> O, @\libconcept{sentinel_for}@<O> S> |
| 11703 | + requires @\libconcept{invocable}@<D&, G&> && @\libconcept{uniform_random_bit_generator}@<remove_cvref_t<G>> |
| 11704 | +constexpr O ranges::generate_random(O first, S last, G&& g, D&& d); |
| 11705 | +\end{itemdecl} |
| 11706 | + |
| 11707 | +\begin{itemdescr} |
| 11708 | +\pnum |
| 11709 | +\effects |
| 11710 | +Equivalent to: |
| 11711 | +\begin{codeblock} |
| 11712 | +return generate_random(subrange<O, S>(std::move(first), last), g, d); |
| 11713 | +\end{codeblock} |
| 11714 | +\end{itemdescr} |
| 11715 | + |
11583 | 11716 | \rSec1[alg.c.library]{C library algorithms}
|
11584 | 11717 |
|
11585 | 11718 | \pnum
|
|
0 commit comments