xref: /freebsd/contrib/llvm-project/libcxx/include/__algorithm/ranges_sample.h (revision b3edf4467982447620505a28fc82e38a414c07dc)
161cfbce3SDimitry Andric //===----------------------------------------------------------------------===//
261cfbce3SDimitry Andric //
361cfbce3SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
461cfbce3SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
561cfbce3SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
661cfbce3SDimitry Andric //
761cfbce3SDimitry Andric //===----------------------------------------------------------------------===//
861cfbce3SDimitry Andric 
961cfbce3SDimitry Andric #ifndef _LIBCPP___ALGORITHM_RANGES_SAMPLE_H
1061cfbce3SDimitry Andric #define _LIBCPP___ALGORITHM_RANGES_SAMPLE_H
1161cfbce3SDimitry Andric 
1261cfbce3SDimitry Andric #include <__algorithm/iterator_operations.h>
1361cfbce3SDimitry Andric #include <__algorithm/sample.h>
1461cfbce3SDimitry Andric #include <__algorithm/uniform_random_bit_generator_adaptor.h>
1561cfbce3SDimitry Andric #include <__config>
1661cfbce3SDimitry Andric #include <__iterator/concepts.h>
1761cfbce3SDimitry Andric #include <__iterator/incrementable_traits.h>
1861cfbce3SDimitry Andric #include <__iterator/iterator_traits.h>
1961cfbce3SDimitry Andric #include <__random/uniform_random_bit_generator.h>
2061cfbce3SDimitry Andric #include <__ranges/access.h>
2161cfbce3SDimitry Andric #include <__ranges/concepts.h>
2206c3fb27SDimitry Andric #include <__type_traits/remove_reference.h>
2361cfbce3SDimitry Andric #include <__utility/forward.h>
2461cfbce3SDimitry Andric #include <__utility/move.h>
2561cfbce3SDimitry Andric 
2661cfbce3SDimitry Andric #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2761cfbce3SDimitry Andric #  pragma GCC system_header
2861cfbce3SDimitry Andric #endif
2961cfbce3SDimitry Andric 
30*b3edf446SDimitry Andric _LIBCPP_PUSH_MACROS
31*b3edf446SDimitry Andric #include <__undef_macros>
32*b3edf446SDimitry Andric 
3306c3fb27SDimitry Andric #if _LIBCPP_STD_VER >= 20
3461cfbce3SDimitry Andric 
3561cfbce3SDimitry Andric _LIBCPP_BEGIN_NAMESPACE_STD
3661cfbce3SDimitry Andric 
3761cfbce3SDimitry Andric namespace ranges {
3861cfbce3SDimitry Andric namespace __sample {
3961cfbce3SDimitry Andric 
4061cfbce3SDimitry Andric struct __fn {
4161cfbce3SDimitry Andric   template <input_iterator _Iter, sentinel_for<_Iter> _Sent, weakly_incrementable _OutIter, class _Gen>
4206c3fb27SDimitry Andric     requires(forward_iterator<_Iter> || random_access_iterator<_OutIter>) && indirectly_copyable<_Iter, _OutIter> &&
4361cfbce3SDimitry Andric             uniform_random_bit_generator<remove_reference_t<_Gen>>
4406c3fb27SDimitry Andric   _LIBCPP_HIDE_FROM_ABI _OutIter
4506c3fb27SDimitry Andric   operator()(_Iter __first, _Sent __last, _OutIter __out_first, iter_difference_t<_Iter> __n, _Gen&& __gen) const {
4661cfbce3SDimitry Andric     _ClassicGenAdaptor<_Gen> __adapted_gen(__gen);
4761cfbce3SDimitry Andric     return std::__sample<_RangeAlgPolicy>(
4861cfbce3SDimitry Andric         std::move(__first), std::move(__last), std::move(__out_first), __n, __adapted_gen);
4961cfbce3SDimitry Andric   }
5061cfbce3SDimitry Andric 
5161cfbce3SDimitry Andric   template <input_range _Range, weakly_incrementable _OutIter, class _Gen>
5261cfbce3SDimitry Andric     requires(forward_range<_Range> || random_access_iterator<_OutIter>) &&
5306c3fb27SDimitry Andric             indirectly_copyable<iterator_t<_Range>, _OutIter> && uniform_random_bit_generator<remove_reference_t<_Gen>>
5406c3fb27SDimitry Andric   _LIBCPP_HIDE_FROM_ABI _OutIter
5506c3fb27SDimitry Andric   operator()(_Range&& __range, _OutIter __out_first, range_difference_t<_Range> __n, _Gen&& __gen) const {
5606c3fb27SDimitry Andric     return (*this)(
5706c3fb27SDimitry Andric         ranges::begin(__range), ranges::end(__range), std::move(__out_first), __n, std::forward<_Gen>(__gen));
5861cfbce3SDimitry Andric   }
5961cfbce3SDimitry Andric };
6061cfbce3SDimitry Andric 
6161cfbce3SDimitry Andric } // namespace __sample
6261cfbce3SDimitry Andric 
6361cfbce3SDimitry Andric inline namespace __cpo {
6461cfbce3SDimitry Andric inline constexpr auto sample = __sample::__fn{};
6561cfbce3SDimitry Andric } // namespace __cpo
6661cfbce3SDimitry Andric } // namespace ranges
6761cfbce3SDimitry Andric 
6861cfbce3SDimitry Andric _LIBCPP_END_NAMESPACE_STD
6961cfbce3SDimitry Andric 
7006c3fb27SDimitry Andric #endif // _LIBCPP_STD_VER >= 20
7161cfbce3SDimitry Andric 
72*b3edf446SDimitry Andric _LIBCPP_POP_MACROS
73*b3edf446SDimitry Andric 
7461cfbce3SDimitry Andric #endif // _LIBCPP___ALGORITHM_RANGES_SAMPLE_H
75