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