/*============================================================================= Copyright (c) 2011-2013 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_SUB_ARRAY_CONTAINER_HPP #define SPROUT_SUB_ARRAY_CONTAINER_HPP #include #include #include #include #include #include #include namespace sprout { // // container_construct_traits // template struct container_construct_traits > { private: typedef typename sprout::sub_array::internal_type internal_type; typedef typename sprout::container_construct_traits::copied_type internal_copied_type; public: typedef sprout::sub_array copied_type; private: static SPROUT_CONSTEXPR copied_type make_impl(internal_copied_type const& internal_copied) { return copied_type(internal_copied, sprout::begin(internal_copied), sprout::end(internal_copied)); } template static SPROUT_CONSTEXPR copied_type remake_impl( Cont&& cont, typename sprout::container_traits >::difference_type size, internal_copied_type const& internal_copied ) { return copied_type( internal_copied, sprout::next(sprout::begin(internal_copied), sprout::internal_begin_offset(cont)), sprout::next(sprout::begin(internal_copied), sprout::internal_begin_offset(cont) + size) ); } public: template static SPROUT_CONSTEXPR copied_type deep_copy(Cont&& cont) { return copied_type( sprout::deep_copy(sprout::get_internal(cont)), sprout::internal_begin_offset(cont), sprout::internal_end_offset(cont) ); } template static SPROUT_CONSTEXPR copied_type make(Args&&... args) { return make_impl( sprout::make(sprout::forward(args)...) ); } template static SPROUT_CONSTEXPR copied_type remake(Cont&& cont, typename sprout::container_traits >::difference_type size, Args&&... args) { return remake_impl( sprout::forward(cont), size, sprout::remake(cont, size, sprout::forward(args)...) ); } }; // // container_transform_traits // template struct container_transform_traits > { public: template >::size_type Size> struct rebind_size { public: typedef sprout::sub_array< typename sprout::container_transform_traits< typename std::remove_reference::type >::template rebind_size::type > type; }; }; // // sub_container_traits // template struct sub_container_traits > { private: static typename sprout::sub_array::param_type call(sprout::sub_array& cont) { return cont.get_internal(); } static SPROUT_CONSTEXPR typename sprout::sub_array::const_param_type call(sprout::sub_array const& cont) { return cont.get_internal(); } public: template struct internal { public: typedef decltype(call(std::declval())) type; }; public: template static SPROUT_CONSTEXPR typename internal::type get_internal(Cont&& cont) { return call(sprout::forward(cont)); } }; } // namespace sprout #endif // #ifndef SPROUT_SUB_ARRAY_CONTAINER_HPP