/*============================================================================= Copyright (c) 2011-2019 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_FILLED_HPP #define SPROUT_RANGE_ADAPTOR_FILLED_HPP #include #include #include #include #include #include #include #include #include #include namespace sprout { namespace adaptors { // // filled_range // template class filled_range : public sprout::adaptors::detail::adapted_range_default< Range, sprout::value_iterator::value_type> > { public: typedef sprout::adaptors::detail::adapted_range_default< Range, sprout::value_iterator::value_type> > base_type; typedef typename base_type::range_type range_type; typedef typename base_type::iterator iterator; typedef typename base_type::value_type value_type; public: SPROUT_CONSTEXPR filled_range() SPROUT_DEFAULTED_DEFAULT_CONSTRUCTOR_DECL filled_range(filled_range const&) = default; SPROUT_CONSTEXPR filled_range( range_type& range, value_type const& value ) : base_type( iterator(value, sprout::size(range)), iterator(value, 0) ) {} }; // // fill_holder // template class fill_holder { public: typedef T value_type; private: value_type value_; public: explicit SPROUT_CONSTEXPR fill_holder(value_type const& value) : value_(value) {} SPROUT_CONSTEXPR value_type const& value() const { return value_; } }; // // filled_forwarder // class filled_forwarder { public: template SPROUT_CONSTEXPR sprout::adaptors::fill_holder operator()(T const& value) const { return sprout::adaptors::fill_holder(value); } }; // // filled // namespace { SPROUT_STATIC_CONSTEXPR sprout::adaptors::filled_forwarder filled = {}; } // anonymous-namespace // // operator| // template inline SPROUT_CONSTEXPR sprout::adaptors::filled_range< typename std::remove_reference::type>::type > operator|(Range&& lhs, sprout::adaptors::fill_holder const& rhs) { return sprout::adaptors::filled_range< typename std::remove_reference::type>::type >( sprout::lvalue_forward(lhs), rhs.value() ); } } // namespace adaptors // // container_construct_traits // template struct container_construct_traits > : public sprout::container_construct_traits::base_type> {}; } // namespace sprout #endif // #ifndef SPROUT_RANGE_ADAPTOR_FILLED_HPP