/*============================================================================= Copyright (c) 2011-2016 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_SET_UNION_HPP #define SPROUT_RANGE_ADAPTOR_SET_UNION_HPP #include #include #include #include #include #include #include #include #include #include #include namespace sprout { namespace adaptors { // // set_union_range // template > class set_union_range : public sprout::adaptors::detail::jointed_range_default< LRange, RRange, sprout::set_union_iterator< typename sprout::container_traits::iterator, typename sprout::container_traits::iterator, Compare > > { public: typedef sprout::adaptors::detail::jointed_range_default< LRange, RRange, sprout::set_union_iterator< typename sprout::container_traits::iterator, typename sprout::container_traits::iterator, Compare > > base_type; typedef typename base_type::range1_type range1_type; typedef typename base_type::range2_type range2_type; typedef typename base_type::iterator iterator; public: SPROUT_CONSTEXPR set_union_range() SPROUT_DEFAULTED_DEFAULT_CONSTRUCTOR_DECL set_union_range(set_union_range const&) = default; SPROUT_CONSTEXPR set_union_range(range1_type& range1, range2_type& range2, Compare comp = Compare()) : base_type( iterator(sprout::begin(range1), sprout::end(range1), sprout::begin(range2), sprout::end(range2), comp), iterator(sprout::end(range1), sprout::end(range1), sprout::end(range2), sprout::end(range2), comp) ) {} }; // // set_union_holder // template > class set_union_holder { public: typedef RRange range2_type; typedef Compare compare_type; private: sprout::value_holder range_; Compare comp_; public: SPROUT_CONSTEXPR set_union_holder() SPROUT_DEFAULTED_DEFAULT_CONSTRUCTOR_DECL set_union_holder(set_union_holder const&) = default; explicit SPROUT_CONSTEXPR set_union_holder(range2_type& range, Compare comp = Compare()) : range_(range) , comp_(comp) {} SPROUT_CONSTEXPR range2_type& range() const { return range_; } SPROUT_CONSTEXPR Compare compare() const { return comp_; } }; // // set_union_forwarder // class set_union_forwarder { public: template SPROUT_CONSTEXPR sprout::adaptors::set_union_holder< typename std::remove_reference::type>::type > operator()(RRange&& range) const { return sprout::adaptors::set_union_holder< typename std::remove_reference::type>::type >( sprout::lvalue_forward(range) ); } template SPROUT_CONSTEXPR sprout::adaptors::set_union_holder< typename std::remove_reference::type>::type, Compare > operator()(RRange&& range, Compare comp) const { return sprout::adaptors::set_union_holder< typename std::remove_reference::type>::type, Compare >( sprout::lvalue_forward(range), comp ); } }; // // set_union // namespace { SPROUT_STATIC_CONSTEXPR sprout::adaptors::set_union_forwarder set_union = {}; } // anonymous-namespace // // operator| // template inline SPROUT_CONSTEXPR sprout::adaptors::set_union_range< typename std::remove_reference::type>::type, RRange, Compare > operator|(LRange&& lhs, sprout::adaptors::set_union_holder const& rhs) { return sprout::adaptors::set_union_range< typename std::remove_reference::type>::type, RRange, Compare >( sprout::lvalue_forward(lhs), rhs.range(), rhs.compare() ); } } // namespace adaptors // // container_construct_traits // template struct container_construct_traits > : public sprout::container_construct_traits::base_type> {}; } // namespace sprout #endif // #ifndef SPROUT_RANGE_ADAPTOR_SET_UNION_HPP