partition.hpp 2.4 KB

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