File indexing completed on 2025-01-18 10:09:42
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef RANGES_V3_ACTION_SHUFFLE_HPP
0015 #define RANGES_V3_ACTION_SHUFFLE_HPP
0016
0017 #include <range/v3/range_fwd.hpp>
0018
0019 #include <range/v3/action/action.hpp>
0020 #include <range/v3/algorithm/shuffle.hpp>
0021 #include <range/v3/functional/bind.hpp>
0022 #include <range/v3/functional/bind_back.hpp>
0023 #include <range/v3/functional/invoke.hpp>
0024 #include <range/v3/iterator/concepts.hpp>
0025 #include <range/v3/iterator/traits.hpp>
0026 #include <range/v3/utility/static_const.hpp>
0027
0028 #include <range/v3/detail/prologue.hpp>
0029
0030 namespace ranges
0031 {
0032
0033
0034 namespace actions
0035 {
0036 struct shuffle_fn
0037 {
0038 template(typename Gen)(
0039 requires uniform_random_bit_generator<Gen>)
0040 constexpr auto operator()(Gen & gen) const
0041 {
0042 return make_action_closure(
0043 bind_back(shuffle_fn{}, detail::reference_wrapper_<Gen>(gen)));
0044 }
0045
0046 template(typename Gen)(
0047 requires uniform_random_bit_generator<Gen>)
0048 constexpr auto operator()(Gen && gen) const
0049 {
0050 return make_action_closure(
0051 bind_back(shuffle_fn{}, static_cast<Gen &&>(gen)));
0052 }
0053
0054 template(typename Rng, typename Gen)(
0055 requires random_access_range<Rng> AND permutable<iterator_t<Rng>> AND
0056 uniform_random_bit_generator<std::remove_reference_t<Gen>> AND
0057 convertible_to<invoke_result_t<Gen &>, range_difference_t<Rng>>)
0058 Rng operator()(Rng && rng, Gen && gen) const
0059 {
0060 ranges::shuffle(rng, static_cast<Gen &&>(gen));
0061 return static_cast<Rng &&>(rng);
0062 }
0063
0064
0065 template<typename Rng, typename T>
0066 invoke_result_t<shuffle_fn, Rng, T &>
0067 operator()(Rng && rng, detail::reference_wrapper_<T> r) const
0068 {
0069 return (*this)(static_cast<Rng &&>(rng), r.get());
0070 }
0071
0072 };
0073
0074
0075
0076 RANGES_INLINE_VARIABLE(shuffle_fn, shuffle)
0077 }
0078
0079 }
0080
0081 #include <range/v3/detail/epilogue.hpp>
0082
0083 #endif