/// \file // Range v3 library // // Copyright Filip Matzner 2015 // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_ACTION_SHUFFLE_HPP #define RANGES_V3_ACTION_SHUFFLE_HPP #include #include #include #include #include #include #include #include #include namespace ranges { /// \addtogroup group-actions /// @{ namespace actions { struct shuffle_fn { private: friend action_access; template static auto CPP_fun(bind)(shuffle_fn shuffle, Gen && gen)( // requires uniform_random_bit_generator) { return bind_back(shuffle, static_cast(gen)); } #ifdef RANGES_WORKAROUND_MSVC_OLD_LAMBDA template struct lamduh { Gen & gen_; template auto operator()(Rng && rng) const -> invoke_result_t { return shuffle_fn{}(static_cast(rng), gen_); } }; template static lamduh CPP_fun(bind)(shuffle_fn, Gen & gen)( // requires uniform_random_bit_generator) { return {gen}; } #else // ^^^ workaround / no workaround vvv template static auto CPP_fun(bind)(shuffle_fn, Gen & gen)( // requires uniform_random_bit_generator) { return [&gen](auto && rng) -> invoke_result_t { return shuffle_fn{}(static_cast(rng), gen); }; } #endif // RANGES_WORKAROUND_MSVC_OLD_LAMBDA public: template auto operator()(Rng && rng, Gen && gen) const -> CPP_ret(Rng)( // requires random_access_range && permutable> && uniform_random_bit_generator> && convertible_to, range_difference_t>) { ranges::shuffle(rng, static_cast(gen)); return static_cast(rng); } }; /// \ingroup group-actions /// \relates shuffle_fn /// \sa `action` RANGES_INLINE_VARIABLE(action, shuffle) } // namespace actions /// @} } // namespace ranges #endif