16bdb6422SKonstantin Varlamov //===----------------------------------------------------------------------===// 26bdb6422SKonstantin Varlamov // 36bdb6422SKonstantin Varlamov // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 46bdb6422SKonstantin Varlamov // See https://llvm.org/LICENSE.txt for license information. 56bdb6422SKonstantin Varlamov // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 66bdb6422SKonstantin Varlamov // 76bdb6422SKonstantin Varlamov //===----------------------------------------------------------------------===// 86bdb6422SKonstantin Varlamov 96bdb6422SKonstantin Varlamov #ifndef _LIBCPP___ALGORITHM_RANGES_SAMPLE_H 106bdb6422SKonstantin Varlamov #define _LIBCPP___ALGORITHM_RANGES_SAMPLE_H 116bdb6422SKonstantin Varlamov 126bdb6422SKonstantin Varlamov #include <__algorithm/iterator_operations.h> 136bdb6422SKonstantin Varlamov #include <__algorithm/sample.h> 146bdb6422SKonstantin Varlamov #include <__algorithm/uniform_random_bit_generator_adaptor.h> 156bdb6422SKonstantin Varlamov #include <__config> 166bdb6422SKonstantin Varlamov #include <__iterator/concepts.h> 176bdb6422SKonstantin Varlamov #include <__iterator/incrementable_traits.h> 186bdb6422SKonstantin Varlamov #include <__iterator/iterator_traits.h> 196bdb6422SKonstantin Varlamov #include <__random/uniform_random_bit_generator.h> 206bdb6422SKonstantin Varlamov #include <__ranges/access.h> 216bdb6422SKonstantin Varlamov #include <__ranges/concepts.h> 22e698c595SNikolas Klauser #include <__type_traits/remove_reference.h> 236bdb6422SKonstantin Varlamov #include <__utility/forward.h> 246bdb6422SKonstantin Varlamov #include <__utility/move.h> 256bdb6422SKonstantin Varlamov 266bdb6422SKonstantin Varlamov #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 276bdb6422SKonstantin Varlamov # pragma GCC system_header 286bdb6422SKonstantin Varlamov #endif 296bdb6422SKonstantin Varlamov 307b462251SLouis Dionne _LIBCPP_PUSH_MACROS 317b462251SLouis Dionne #include <__undef_macros> 327b462251SLouis Dionne 334f15267dSNikolas Klauser #if _LIBCPP_STD_VER >= 20 346bdb6422SKonstantin Varlamov 356bdb6422SKonstantin Varlamov _LIBCPP_BEGIN_NAMESPACE_STD 366bdb6422SKonstantin Varlamov 376bdb6422SKonstantin Varlamov namespace ranges { 38*d10dc5a0SChristopher Di Bella struct __sample { 396bdb6422SKonstantin Varlamov template <input_iterator _Iter, sentinel_for<_Iter> _Sent, weakly_incrementable _OutIter, class _Gen> 405aa03b64SLouis Dionne requires(forward_iterator<_Iter> || random_access_iterator<_OutIter>) && indirectly_copyable<_Iter, _OutIter> && 416bdb6422SKonstantin Varlamov uniform_random_bit_generator<remove_reference_t<_Gen>> 425aa03b64SLouis Dionne _LIBCPP_HIDE_FROM_ABI _OutIter 435aa03b64SLouis Dionne operator()(_Iter __first, _Sent __last, _OutIter __out_first, iter_difference_t<_Iter> __n, _Gen&& __gen) const { 446bdb6422SKonstantin Varlamov _ClassicGenAdaptor<_Gen> __adapted_gen(__gen); 456bdb6422SKonstantin Varlamov return std::__sample<_RangeAlgPolicy>( 466bdb6422SKonstantin Varlamov std::move(__first), std::move(__last), std::move(__out_first), __n, __adapted_gen); 476bdb6422SKonstantin Varlamov } 486bdb6422SKonstantin Varlamov 496bdb6422SKonstantin Varlamov template <input_range _Range, weakly_incrementable _OutIter, class _Gen> 506bdb6422SKonstantin Varlamov requires(forward_range<_Range> || random_access_iterator<_OutIter>) && 515aa03b64SLouis Dionne indirectly_copyable<iterator_t<_Range>, _OutIter> && uniform_random_bit_generator<remove_reference_t<_Gen>> 525aa03b64SLouis Dionne _LIBCPP_HIDE_FROM_ABI _OutIter 535aa03b64SLouis Dionne operator()(_Range&& __range, _OutIter __out_first, range_difference_t<_Range> __n, _Gen&& __gen) const { 545aa03b64SLouis Dionne return (*this)( 555aa03b64SLouis Dionne ranges::begin(__range), ranges::end(__range), std::move(__out_first), __n, std::forward<_Gen>(__gen)); 566bdb6422SKonstantin Varlamov } 576bdb6422SKonstantin Varlamov }; 586bdb6422SKonstantin Varlamov 596bdb6422SKonstantin Varlamov inline namespace __cpo { 60*d10dc5a0SChristopher Di Bella inline constexpr auto sample = __sample{}; 616bdb6422SKonstantin Varlamov } // namespace __cpo 626bdb6422SKonstantin Varlamov } // namespace ranges 636bdb6422SKonstantin Varlamov 646bdb6422SKonstantin Varlamov _LIBCPP_END_NAMESPACE_STD 656bdb6422SKonstantin Varlamov 664f15267dSNikolas Klauser #endif // _LIBCPP_STD_VER >= 20 676bdb6422SKonstantin Varlamov 687b462251SLouis Dionne _LIBCPP_POP_MACROS 697b462251SLouis Dionne 706bdb6422SKonstantin Varlamov #endif // _LIBCPP___ALGORITHM_RANGES_SAMPLE_H 71