/*============================================================================= Copyright (c) 2011-2014 Bolero MURAKAMI https://github.com/bolero-MURAKAMI/Sprout Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) =============================================================================*/ #ifndef SPROUT_RANGE_ADAPTOR_UNIQUED_HPP #define SPROUT_RANGE_ADAPTOR_UNIQUED_HPP #include #include #include #include #include #include #include #include #include #include #include namespace sprout { namespace adaptors { // // uniqued_range // template class uniqued_range : public sprout::adaptors::detail::adapted_range_default< Range, sprout::adjacent_filter_iterator< sprout::unique_filter, typename sprout::container_traits::iterator > > { public: typedef Predicate predicate_type; typedef sprout::adaptors::detail::adapted_range_default< Range, sprout::adjacent_filter_iterator< sprout::unique_filter, typename sprout::container_traits::iterator > > base_type; typedef typename base_type::range_type range_type; typedef typename base_type::iterator iterator; public: uniqued_range() = default; uniqued_range(uniqued_range const&) = default; SPROUT_CONSTEXPR uniqued_range(range_type& range, Predicate pred) : base_type( iterator(typename iterator::predicate_type(pred), sprout::begin(range), sprout::end(range)), iterator(typename iterator::predicate_type(pred), sprout::end(range), sprout::end(range)) ) {} }; // // unique_holder // template > class unique_holder { public: typedef Predicate predicate_type; private: Predicate pred_; public: SPROUT_CONSTEXPR unique_holder() : pred_() {} explicit SPROUT_CONSTEXPR unique_holder(Predicate pred) : pred_(pred) {} SPROUT_CONSTEXPR Predicate const& predicate() const { return pred_; } }; // // uniqued_forwarder // class uniqued_forwarder { public: template SPROUT_CONSTEXPR sprout::adaptors::unique_holder operator()(Predicate pred) const { return sprout::adaptors::unique_holder(pred); } }; // // uniqued // namespace { SPROUT_STATIC_CONSTEXPR sprout::adaptors::uniqued_forwarder uniqued = {}; } // anonymous-namespace // // operator| // template inline SPROUT_CONSTEXPR sprout::adaptors::uniqued_range< Predicate, typename std::remove_reference::type>::type > operator|(Range&& lhs, sprout::adaptors::unique_holder const& rhs) { return sprout::adaptors::uniqued_range< Predicate, typename std::remove_reference::type>::type >( sprout::lvalue_forward(lhs), rhs.predicate() ); } template inline SPROUT_CONSTEXPR sprout::adaptors::uniqued_range< sprout::equal_to<>, typename std::remove_reference::type>::type > operator|(Range&& lhs, sprout::adaptors::uniqued_forwarder const&) { return sprout::adaptors::uniqued_range< sprout::equal_to<>, typename std::remove_reference::type>::type >( sprout::lvalue_forward(lhs), sprout::equal_to<>() ); } } // namespace adaptors // // container_construct_traits // template struct container_construct_traits > : public sprout::container_construct_traits::base_type> {}; } // namespace sprout #endif // #ifndef SPROUT_RANGE_ADAPTOR_UNIQUED_HPP