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