permutation.hpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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_PERMUTATION_HPP_INCLUDED
  10. #define BOOST_RANGE_ALGORITHM_PERMUTATION_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 next_permutation
  21. ///
  22. /// range-based version of the next_permutation std algorithm
  23. ///
  24. /// \pre BidirectionalRange is a model of the BidirectionalRangeConcept
  25. /// \pre Compare is a model of the BinaryPredicateConcept
  26. template<class BidirectionalRange>
  27. inline bool next_permutation(BidirectionalRange& rng)
  28. {
  29. BOOST_RANGE_CONCEPT_ASSERT(( BidirectionalRangeConcept<BidirectionalRange> ));
  30. return std::next_permutation(boost::begin(rng), boost::end(rng));
  31. }
  32. /// \overload
  33. template<class BidirectionalRange>
  34. inline bool next_permutation(const BidirectionalRange& rng)
  35. {
  36. BOOST_RANGE_CONCEPT_ASSERT(( BidirectionalRangeConcept<const BidirectionalRange> ));
  37. return std::next_permutation(boost::begin(rng), boost::end(rng));
  38. }
  39. /// \overload
  40. template<class BidirectionalRange, class Compare>
  41. inline bool next_permutation(BidirectionalRange& rng, Compare comp_pred)
  42. {
  43. BOOST_RANGE_CONCEPT_ASSERT(( BidirectionalRangeConcept<BidirectionalRange> ));
  44. return std::next_permutation(boost::begin(rng), boost::end(rng),
  45. comp_pred);
  46. }
  47. /// \overload
  48. template<class BidirectionalRange, class Compare>
  49. inline bool next_permutation(const BidirectionalRange& rng,
  50. Compare comp_pred)
  51. {
  52. BOOST_RANGE_CONCEPT_ASSERT(( BidirectionalRangeConcept<const BidirectionalRange> ));
  53. return std::next_permutation(boost::begin(rng), boost::end(rng),
  54. comp_pred);
  55. }
  56. /// \brief template function prev_permutation
  57. ///
  58. /// range-based version of the prev_permutation std algorithm
  59. ///
  60. /// \pre BidirectionalRange is a model of the BidirectionalRangeConcept
  61. /// \pre Compare is a model of the BinaryPredicateConcept
  62. template<class BidirectionalRange>
  63. inline bool prev_permutation(BidirectionalRange& rng)
  64. {
  65. BOOST_RANGE_CONCEPT_ASSERT(( BidirectionalRangeConcept<BidirectionalRange> ));
  66. return std::prev_permutation(boost::begin(rng), boost::end(rng));
  67. }
  68. /// \overload
  69. template<class BidirectionalRange>
  70. inline bool prev_permutation(const BidirectionalRange& rng)
  71. {
  72. BOOST_RANGE_CONCEPT_ASSERT(( BidirectionalRangeConcept<const BidirectionalRange> ));
  73. return std::prev_permutation(boost::begin(rng), boost::end(rng));
  74. }
  75. /// \overload
  76. template<class BidirectionalRange, class Compare>
  77. inline bool prev_permutation(BidirectionalRange& rng, Compare comp_pred)
  78. {
  79. BOOST_RANGE_CONCEPT_ASSERT(( BidirectionalRangeConcept<BidirectionalRange> ));
  80. return std::prev_permutation(boost::begin(rng), boost::end(rng),
  81. comp_pred);
  82. }
  83. /// \overload
  84. template<class BidirectionalRange, class Compare>
  85. inline bool prev_permutation(const BidirectionalRange& rng,
  86. Compare comp_pred)
  87. {
  88. BOOST_RANGE_CONCEPT_ASSERT(( BidirectionalRangeConcept<const BidirectionalRange> ));
  89. return std::prev_permutation(boost::begin(rng), boost::end(rng),
  90. comp_pred);
  91. }
  92. } // namespace range
  93. using range::next_permutation;
  94. using range::prev_permutation;
  95. } // namespace boost
  96. #endif // include guard