unique.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_UNIQUE_HPP_INCLUDED
  10. #define BOOST_RANGE_ALGORITHM_UNIQUE_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 unique
  22. ///
  23. /// range-based version of the unique std algorithm
  24. ///
  25. /// \pre Rng meets the requirements for a Forward range
  26. template< range_return_value re, class ForwardRange >
  27. inline BOOST_DEDUCED_TYPENAME range_return<ForwardRange,re>::type
  28. unique( ForwardRange& rng )
  29. {
  30. BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<ForwardRange> ));
  31. return range_return<ForwardRange,re>::
  32. pack( std::unique( boost::begin(rng),
  33. boost::end(rng)), rng );
  34. }
  35. /// \overload
  36. template< range_return_value re, class ForwardRange >
  37. inline BOOST_DEDUCED_TYPENAME range_return<const ForwardRange,re>::type
  38. unique( const ForwardRange& rng )
  39. {
  40. BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<const ForwardRange> ));
  41. return range_return<const ForwardRange,re>::
  42. pack( std::unique( boost::begin(rng),
  43. boost::end(rng)), rng );
  44. }
  45. /// \overload
  46. template< range_return_value re, class ForwardRange, class BinaryPredicate >
  47. inline BOOST_DEDUCED_TYPENAME range_return<ForwardRange,re>::type
  48. unique( ForwardRange& rng, BinaryPredicate pred )
  49. {
  50. BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<ForwardRange> ));
  51. return range_return<ForwardRange,re>::
  52. pack(std::unique(boost::begin(rng), boost::end(rng), pred),
  53. rng);
  54. }
  55. /// \overload
  56. template< range_return_value re, class ForwardRange, class BinaryPredicate >
  57. inline BOOST_DEDUCED_TYPENAME range_return<const ForwardRange,re>::type
  58. unique( const ForwardRange& rng, BinaryPredicate pred )
  59. {
  60. BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<const ForwardRange> ));
  61. return range_return<const ForwardRange,re>::
  62. pack(std::unique(boost::begin(rng), boost::end(rng), pred),
  63. rng);
  64. }
  65. /// \overload
  66. template< class ForwardRange >
  67. inline BOOST_DEDUCED_TYPENAME range_return<ForwardRange, return_begin_found>::type
  68. unique( ForwardRange& rng )
  69. {
  70. BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<ForwardRange> ));
  71. return ::boost::range::unique<return_begin_found>(rng);
  72. }
  73. /// \overload
  74. template< class ForwardRange >
  75. inline BOOST_DEDUCED_TYPENAME range_return<const ForwardRange, return_begin_found>::type
  76. unique( const ForwardRange& rng )
  77. {
  78. BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<const ForwardRange> ));
  79. return ::boost::range::unique<return_begin_found>(rng);
  80. }
  81. /// \overload
  82. template< class ForwardRange, class BinaryPredicate >
  83. inline BOOST_DEDUCED_TYPENAME range_return<ForwardRange, return_begin_found>::type
  84. unique( ForwardRange& rng, BinaryPredicate pred )
  85. {
  86. BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<ForwardRange> ));
  87. return ::boost::range::unique<return_begin_found>(rng, pred);
  88. }
  89. /// \overload
  90. template< class ForwardRange, class BinaryPredicate >
  91. inline BOOST_DEDUCED_TYPENAME range_return<const ForwardRange, return_begin_found>::type
  92. unique( const ForwardRange& rng, BinaryPredicate pred )
  93. {
  94. BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<const ForwardRange> ));
  95. return ::boost::range::unique<return_begin_found>(rng, pred);
  96. }
  97. } // namespace range
  98. using range::unique;
  99. } // namespace boost
  100. #endif // include guard