Chris@16
|
1 // Boost.Range library
|
Chris@16
|
2 //
|
Chris@16
|
3 // Copyright Thorsten Ottosen, Neil Groves 2006 - 2008. Use, modification and
|
Chris@16
|
4 // distribution is subject to the Boost Software License, Version
|
Chris@16
|
5 // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
6 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
7 //
|
Chris@16
|
8 // For more information, see http://www.boost.org/libs/range/
|
Chris@16
|
9 //
|
Chris@16
|
10
|
Chris@16
|
11 #ifndef BOOST_RANGE_ADAPTOR_UNIQUED_IMPL_HPP
|
Chris@16
|
12 #define BOOST_RANGE_ADAPTOR_UNIQUED_IMPL_HPP
|
Chris@16
|
13
|
Chris@16
|
14 #include <boost/range/adaptor/adjacent_filtered.hpp>
|
Chris@101
|
15 #include <boost/range/concepts.hpp>
|
Chris@16
|
16
|
Chris@16
|
17 namespace boost
|
Chris@16
|
18 {
|
Chris@16
|
19
|
Chris@16
|
20 namespace range_detail
|
Chris@16
|
21 {
|
Chris@16
|
22 struct unique_forwarder { };
|
Chris@16
|
23
|
Chris@16
|
24 struct unique_not_equal_to
|
Chris@16
|
25 {
|
Chris@16
|
26 typedef bool result_type;
|
Chris@16
|
27
|
Chris@16
|
28 template< class T >
|
Chris@16
|
29 bool operator()( const T& l, const T& r ) const
|
Chris@16
|
30 {
|
Chris@16
|
31 return !(l == r);
|
Chris@16
|
32 }
|
Chris@16
|
33 };
|
Chris@16
|
34
|
Chris@16
|
35 template<class ForwardRng>
|
Chris@16
|
36 class uniqued_range : public adjacent_filtered_range<unique_not_equal_to, ForwardRng, true>
|
Chris@16
|
37 {
|
Chris@16
|
38 typedef adjacent_filtered_range<unique_not_equal_to, ForwardRng, true> base;
|
Chris@16
|
39 public:
|
Chris@16
|
40 explicit uniqued_range(ForwardRng& rng)
|
Chris@16
|
41 : base(unique_not_equal_to(), rng)
|
Chris@16
|
42 {
|
Chris@16
|
43 }
|
Chris@16
|
44 };
|
Chris@16
|
45
|
Chris@16
|
46 template< class ForwardRng >
|
Chris@16
|
47 inline uniqued_range<ForwardRng>
|
Chris@16
|
48 operator|( ForwardRng& r,
|
Chris@16
|
49 unique_forwarder )
|
Chris@16
|
50 {
|
Chris@101
|
51 BOOST_RANGE_CONCEPT_ASSERT((ForwardRangeConcept<ForwardRng>));
|
Chris@16
|
52 return uniqued_range<ForwardRng>(r);
|
Chris@16
|
53 }
|
Chris@16
|
54
|
Chris@16
|
55 template< class ForwardRng >
|
Chris@16
|
56 inline uniqued_range<const ForwardRng>
|
Chris@16
|
57 operator|( const ForwardRng& r,
|
Chris@16
|
58 unique_forwarder )
|
Chris@16
|
59 {
|
Chris@101
|
60 BOOST_RANGE_CONCEPT_ASSERT((ForwardRangeConcept<const ForwardRng>));
|
Chris@16
|
61 return uniqued_range<const ForwardRng>(r);
|
Chris@16
|
62 }
|
Chris@16
|
63
|
Chris@16
|
64 } // 'range_detail'
|
Chris@16
|
65
|
Chris@16
|
66 using range_detail::uniqued_range;
|
Chris@16
|
67
|
Chris@16
|
68 namespace adaptors
|
Chris@16
|
69 {
|
Chris@16
|
70 namespace
|
Chris@16
|
71 {
|
Chris@16
|
72 const range_detail::unique_forwarder uniqued =
|
Chris@16
|
73 range_detail::unique_forwarder();
|
Chris@16
|
74 }
|
Chris@16
|
75
|
Chris@16
|
76 template<class ForwardRange>
|
Chris@16
|
77 inline uniqued_range<ForwardRange>
|
Chris@16
|
78 unique(ForwardRange& rng)
|
Chris@16
|
79 {
|
Chris@101
|
80 BOOST_RANGE_CONCEPT_ASSERT((ForwardRangeConcept<ForwardRange>));
|
Chris@16
|
81 return uniqued_range<ForwardRange>(rng);
|
Chris@16
|
82 }
|
Chris@16
|
83
|
Chris@16
|
84 template<class ForwardRange>
|
Chris@16
|
85 inline uniqued_range<const ForwardRange>
|
Chris@16
|
86 unique(const ForwardRange& rng)
|
Chris@16
|
87 {
|
Chris@101
|
88 BOOST_RANGE_CONCEPT_ASSERT((
|
Chris@101
|
89 ForwardRangeConcept<const ForwardRange>));
|
Chris@101
|
90
|
Chris@16
|
91 return uniqued_range<const ForwardRange>(rng);
|
Chris@16
|
92 }
|
Chris@16
|
93 } // 'adaptors'
|
Chris@16
|
94
|
Chris@16
|
95 }
|
Chris@16
|
96
|
Chris@16
|
97 #endif
|