equal_range.hpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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_EQUAL_RANGE_HPP_INCLUDED
  10. #define BOOST_RANGE_ALGORITHM_EQUAL_RANGE_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 equal_range
  21. ///
  22. /// range-based version of the equal_range std algorithm
  23. ///
  24. /// \pre ForwardRange is a model of the ForwardRangeConcept
  25. /// \pre SortPredicate is a model of the BinaryPredicateConcept
  26. template<class ForwardRange, class Value>
  27. inline std::pair<
  28. BOOST_DEDUCED_TYPENAME boost::range_iterator<ForwardRange>::type,
  29. BOOST_DEDUCED_TYPENAME boost::range_iterator<ForwardRange>::type
  30. >
  31. equal_range(ForwardRange& rng, const Value& val)
  32. {
  33. BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<ForwardRange> ));
  34. return std::equal_range(boost::begin(rng), boost::end(rng), val);
  35. }
  36. /// \overload
  37. template<class ForwardRange, class Value>
  38. inline std::pair<
  39. BOOST_DEDUCED_TYPENAME boost::range_iterator<const ForwardRange>::type,
  40. BOOST_DEDUCED_TYPENAME boost::range_iterator<const ForwardRange>::type
  41. >
  42. equal_range(const ForwardRange& rng, const Value& val)
  43. {
  44. BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<const ForwardRange> ));
  45. return std::equal_range(boost::begin(rng), boost::end(rng), val);
  46. }
  47. /// \overload
  48. template<class ForwardRange, class Value, class SortPredicate>
  49. inline std::pair<
  50. BOOST_DEDUCED_TYPENAME boost::range_iterator<ForwardRange>::type,
  51. BOOST_DEDUCED_TYPENAME boost::range_iterator<ForwardRange>::type
  52. >
  53. equal_range(ForwardRange& rng, const Value& val, SortPredicate pred)
  54. {
  55. BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<ForwardRange> ));
  56. return std::equal_range(boost::begin(rng), boost::end(rng), val, pred);
  57. }
  58. /// \overload
  59. template<class ForwardRange, class Value, class SortPredicate>
  60. inline std::pair<
  61. BOOST_DEDUCED_TYPENAME boost::range_iterator<const ForwardRange>::type,
  62. BOOST_DEDUCED_TYPENAME boost::range_iterator<const ForwardRange>::type
  63. >
  64. equal_range(const ForwardRange& rng, const Value& val, SortPredicate pred)
  65. {
  66. BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<const ForwardRange> ));
  67. return std::equal_range(boost::begin(rng), boost::end(rng), val, pred);
  68. }
  69. } // namespace range
  70. using range::equal_range;
  71. } // namespace boost
  72. #endif // include guard