#ifndef SPROUT_RANGE_ADAPTOR_TRANSFORMD_HPP #define SPROUT_RANGE_ADAPTOR_TRANSFORMD_HPP #include #include #include #include #include #include #include #include #include #include #include #include namespace sprout { namespace adaptors { // // transformed_range // template class transformed_range : public sprout::range::range_container< sprout::transform_iterator< BinaryFunction, typename sprout::container_traits::iterator, typename sprout::container_traits::iterator > > , public sprout::detail::container_nosy_static_size , public sprout::detail::container_nosy_fixed_size { public: typedef BinaryFunction functor_type; typedef LRange range_type; typedef RRange range2_type; typedef sprout::range::range_container< sprout::transform_iterator< BinaryFunction, typename sprout::container_traits::iterator, typename sprout::container_traits::iterator > > base_type; typedef typename base_type::iterator iterator; typedef typename base_type::size_type size_type; public: transformed_range() = default; transformed_range(transformed_range const&) = default; SPROUT_CONSTEXPR transformed_range(functor_type func, range_type& range1, range2_type& range2) : base_type( iterator(sprout::begin(range1), sprout::begin(range2), func), iterator(sprout::end(range1), sprout::end(range2), func) ) {} }; template class transformed_range : public sprout::range::range_container< sprout::transform_iterator< UnaryFunction, typename sprout::container_traits::iterator > > , public sprout::detail::container_nosy_static_size , public sprout::detail::container_nosy_fixed_size { public: typedef UnaryFunction functor_type; typedef Range range_type; typedef sprout::range::range_container< sprout::transform_iterator< UnaryFunction, typename sprout::container_traits::iterator > > base_type; typedef typename base_type::iterator iterator; public: transformed_range() = default; transformed_range(transformed_range const&) = default; SPROUT_CONSTEXPR transformed_range(functor_type func, range_type& range) : base_type( iterator(sprout::begin(range), func), iterator(sprout::end(range), func) ) {} }; // // transform_holder // template class transform_holder { public: typedef BinaryFunction functor_type; typedef RRange range2_type; private: functor_type func_; sprout::value_holder range_; public: transform_holder() = default; transform_holder(transform_holder const&) = default; SPROUT_CONSTEXPR transform_holder(functor_type func, range2_type& range) : func_(func) , range_(range) {} SPROUT_CONSTEXPR functor_type functor() const { return func_; } SPROUT_CONSTEXPR range2_type& range() const { return range_; } }; template class transform_holder { public: typedef UnaryFunction functor_type; private: functor_type func_; public: transform_holder() = default; transform_holder(transform_holder const&) = default; explicit SPROUT_CONSTEXPR transform_holder(functor_type func) : func_(func) {} SPROUT_CONSTEXPR functor_type functor() const { return func_; } }; // // transformed_forwarder // class transformed_forwarder { public: template SPROUT_CONSTEXPR sprout::adaptors::transform_holder< BinaryFunction, typename std::remove_reference::type>::type > operator()(RRange&& range, BinaryFunction func) { return sprout::adaptors::transform_holder< BinaryFunction, typename std::remove_reference::type>::type >( func, sprout::lvalue_forward(range) ); } template SPROUT_CONSTEXPR sprout::adaptors::transform_holder operator()(UnaryFunction func) { return sprout::adaptors::transform_holder(func); } }; // // transformed // namespace { SPROUT_STATIC_CONSTEXPR sprout::adaptors::transformed_forwarder transformed{}; } // anonymous-namespace // // operator| // template inline SPROUT_CONSTEXPR sprout::adaptors::transformed_range< BinaryFunction, typename std::remove_reference::type>::type, RRange > operator|(LRange&& lhs, sprout::adaptors::transform_holder const& rhs) { return sprout::adaptors::transformed_range< BinaryFunction, typename std::remove_reference::type>::type, RRange >( rhs.functor(), sprout::lvalue_forward(lhs), rhs.range() ); } template inline SPROUT_CONSTEXPR sprout::adaptors::transformed_range< UnaryFunction, typename std::remove_reference::type>::type > operator|(Range&& lhs, sprout::adaptors::transform_holder const& rhs) { return sprout::adaptors::transformed_range< UnaryFunction, typename std::remove_reference::type>::type >( rhs.functor(), sprout::lvalue_forward(lhs) ); } } // namespace adaptors // // container_construct_traits // template struct container_construct_traits > { public: typedef typename sprout::container_construct_traits::copied_type copied_type; public: template static SPROUT_CONSTEXPR copied_type deep_copy(Cont&& cont) { return sprout::range::fixed::copy(sprout::forward(cont), sprout::pit()); } template static SPROUT_CONSTEXPR copied_type make(Args&&... args) { return sprout::make(sprout::forward(args)...); } template static SPROUT_CONSTEXPR copied_type remake( Cont&& cont, typename sprout::container_traits >::difference_type size, Args&&... args ) { return sprout::remake(sprout::forward(cont), size, sprout::forward(args)...); } }; } // namespace sprout #endif // #ifndef SPROUT_RANGE_ADAPTOR_TRANSFORMD_HPP