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