stable_partition.hpp 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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_STABLE_PARTITION_HPP_INCLUDED
  10. #define BOOST_RANGE_ALGORITHM_STABLE_PARTITION_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 <boost/range/detail/range_return.hpp>
  16. #include <algorithm>
  17. namespace boost
  18. {
  19. namespace range
  20. {
  21. /// \brief template function stable_partition
  22. ///
  23. /// range-based version of the stable_partition std algorithm
  24. ///
  25. /// \pre BidirectionalRange is a model of the BidirectionalRangeConcept
  26. /// \pre UnaryPredicate is a model of the UnaryPredicateConcept
  27. template<class BidirectionalRange, class UnaryPredicate>
  28. inline BOOST_DEDUCED_TYPENAME range_iterator<BidirectionalRange>::type
  29. stable_partition(BidirectionalRange& rng, UnaryPredicate pred)
  30. {
  31. BOOST_RANGE_CONCEPT_ASSERT(( BidirectionalRangeConcept<BidirectionalRange> ));
  32. return std::stable_partition(boost::begin(rng), boost::end(rng), pred);
  33. }
  34. /// \overload
  35. template<class BidirectionalRange, class UnaryPredicate>
  36. inline BOOST_DEDUCED_TYPENAME range_iterator<const BidirectionalRange>::type
  37. stable_partition(const BidirectionalRange& rng, UnaryPredicate pred)
  38. {
  39. BOOST_RANGE_CONCEPT_ASSERT(( BidirectionalRangeConcept<const BidirectionalRange> ));
  40. return std::stable_partition(boost::begin(rng),boost::end(rng),pred);
  41. }
  42. // range_return overloads
  43. template<range_return_value re, class BidirectionalRange, class UnaryPredicate>
  44. inline BOOST_DEDUCED_TYPENAME range_return<BidirectionalRange,re>::type
  45. stable_partition(BidirectionalRange& rng, UnaryPredicate pred)
  46. {
  47. BOOST_RANGE_CONCEPT_ASSERT(( BidirectionalRangeConcept<BidirectionalRange> ));
  48. return range_return<BidirectionalRange,re>::pack(
  49. std::stable_partition(boost::begin(rng), boost::end(rng), pred),
  50. rng);
  51. }
  52. /// \overload
  53. template<range_return_value re, class BidirectionalRange, class UnaryPredicate>
  54. inline BOOST_DEDUCED_TYPENAME range_return<const BidirectionalRange,re>::type
  55. stable_partition(const BidirectionalRange& rng, UnaryPredicate pred)
  56. {
  57. BOOST_RANGE_CONCEPT_ASSERT(( BidirectionalRangeConcept<const BidirectionalRange> ));
  58. return range_return<const BidirectionalRange,re>::pack(
  59. std::stable_partition(boost::begin(rng),boost::end(rng),pred),
  60. rng);
  61. }
  62. } // namespace range
  63. using range::stable_partition;
  64. } // namespace boost
  65. #endif // include guard