/Src/Dependencies/Boost/boost/range/algorithm/random_shuffle.hpp

http://hadesmem.googlecode.com/ · C++ Header · 68 lines · 43 code · 8 blank · 17 comment · 0 complexity · 1fc3fda9687fde79b569991cf77b16aa MD5 · raw file

  1. // Copyright Neil Groves 2009. Use, modification and
  2. // distribution is subject to the Boost Software License, Version
  3. // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. //
  6. //
  7. // For more information, see http://www.boost.org/libs/range/
  8. //
  9. #ifndef BOOST_RANGE_ALGORITHM_RANDOM_SHUFFLE_HPP_INCLUDED
  10. #define BOOST_RANGE_ALGORITHM_RANDOM_SHUFFLE_HPP_INCLUDED
  11. #include <boost/concept_check.hpp>
  12. #include <boost/range/begin.hpp>
  13. #include <boost/range/end.hpp>
  14. #include <boost/range/concepts.hpp>
  15. #include <algorithm>
  16. namespace boost
  17. {
  18. namespace range
  19. {
  20. /// \brief template function random_shuffle
  21. ///
  22. /// range-based version of the random_shuffle std algorithm
  23. ///
  24. /// \pre RandomAccessRange is a model of the RandomAccessRangeConcept
  25. /// \pre Generator is a model of the UnaryFunctionConcept
  26. template<class RandomAccessRange>
  27. inline RandomAccessRange& random_shuffle(RandomAccessRange& rng)
  28. {
  29. BOOST_RANGE_CONCEPT_ASSERT(( RandomAccessRangeConcept<RandomAccessRange> ));
  30. std::random_shuffle(boost::begin(rng), boost::end(rng));
  31. return rng;
  32. }
  33. /// \overload
  34. template<class RandomAccessRange>
  35. inline const RandomAccessRange& random_shuffle(const RandomAccessRange& rng)
  36. {
  37. BOOST_RANGE_CONCEPT_ASSERT(( RandomAccessRangeConcept<const RandomAccessRange> ));
  38. std::random_shuffle(boost::begin(rng), boost::end(rng));
  39. return rng;
  40. }
  41. /// \overload
  42. template<class RandomAccessRange, class Generator>
  43. inline RandomAccessRange& random_shuffle(RandomAccessRange& rng, Generator& gen)
  44. {
  45. BOOST_RANGE_CONCEPT_ASSERT(( RandomAccessRangeConcept<RandomAccessRange> ));
  46. std::random_shuffle(boost::begin(rng), boost::end(rng), gen);
  47. return rng;
  48. }
  49. /// \overload
  50. template<class RandomAccessRange, class Generator>
  51. inline const RandomAccessRange& random_shuffle(const RandomAccessRange& rng, Generator& gen)
  52. {
  53. BOOST_RANGE_CONCEPT_ASSERT(( RandomAccessRangeConcept<const RandomAccessRange> ));
  54. std::random_shuffle(boost::begin(rng), boost::end(rng), gen);
  55. return rng;
  56. }
  57. } // namespace range
  58. using range::random_shuffle;
  59. } // namespace boost
  60. #endif // include guard