Horizon
shuffle.hpp
Go to the documentation of this file.
1 // Range v3 library
3 //
4 // Copyright Filip Matzner 2015
5 //
6 // Use, modification and distribution is subject to the
7 // Boost Software License, Version 1.0. (See accompanying
8 // file LICENSE_1_0.txt or copy at
9 // http://www.boost.org/LICENSE_1_0.txt)
10 //
11 // Project home: https://github.com/ericniebler/range-v3
12 //
13 
14 #ifndef RANGES_V3_ACTION_SHUFFLE_HPP
15 #define RANGES_V3_ACTION_SHUFFLE_HPP
16 
17 #include <range/v3/range_fwd.hpp>
18 
26 #include <range/v3/utility/static_const.hpp>
27 
28 #include <range/v3/detail/prologue.hpp>
29 
30 namespace ranges
31 {
34  namespace actions
35  {
36  struct shuffle_fn
37  {
38  template(typename Gen)(
39  requires uniform_random_bit_generator<Gen>)
40  constexpr auto operator()(Gen & gen) const
41  {
42  return make_action_closure(
43  bind_back(shuffle_fn{}, detail::reference_wrapper_<Gen>(gen)));
44  }
45 
46  template(typename Gen)(
47  requires uniform_random_bit_generator<Gen>)
48  constexpr auto operator()(Gen && gen) const
49  {
50  return make_action_closure(
51  bind_back(shuffle_fn{}, static_cast<Gen &&>(gen)));
52  }
53 
54  template(typename Rng, typename Gen)(
55  requires random_access_range<Rng> AND permutable<iterator_t<Rng>> AND
56  uniform_random_bit_generator<std::remove_reference_t<Gen>> AND
57  convertible_to<invoke_result_t<Gen &>, range_difference_t<Rng>>)
58  Rng operator()(Rng && rng, Gen && gen) const
59  {
60  ranges::shuffle(rng, static_cast<Gen &&>(gen));
61  return static_cast<Rng &&>(rng);
62  }
63 
65  template<typename Rng, typename T>
66  invoke_result_t<shuffle_fn, Rng, T &> //
67  operator()(Rng && rng, detail::reference_wrapper_<T> r) const
68  {
69  return (*this)(static_cast<Rng &&>(rng), r.get());
70  }
72  };
73 
77  } // namespace actions
79 } // namespace ranges
80 
81 #include <range/v3/detail/epilogue.hpp>
82 
83 #endif
CPP_concept permutable
\concept permutable
Definition: concepts.hpp:840
CPP_concept uniform_random_bit_generator
\concept uniform_random_bit_generator
Definition: random.hpp:99
decltype(begin(declval(Rng &))) iterator_t
Definition: access.hpp:698
RANGES_INLINE_VARIABLE(detail::to_container_fn< detail::from_range< std::vector >>, to_vector) template< template< typename... > class ContT > auto to(RANGES_HIDDEN_DETAIL(detail
For initializing a container of the specified type with the elements of an Range.
Definition: conversion.hpp:399
defer< bind_back, Fn, Ts... > bind_back
Definition: meta.hpp:994
Definition: shuffle.hpp:37