/*============================================================================= Copyright (c) 2011-2015 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_CONTAINER_CONTAINER_TRAITS_CONSTRUCT_TRAITS_HPP #define SPROUT_CONTAINER_CONTAINER_TRAITS_CONSTRUCT_TRAITS_HPP #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace sprout { // // container_construct_traits // namespace detail { template inline SPROUT_CONSTEXPR typename std::enable_if< sprout::is_fixed_container::value, typename sprout::container_construct_traits::copied_type >::type default_make_container(Args&&... args) { typedef typename sprout::container_construct_traits::copied_type copied_type; return copied_type{{SPROUT_FORWARD(Args, args)...}}; } template inline SPROUT_CONSTEXPR typename std::enable_if< !sprout::is_fixed_container::value, typename sprout::container_construct_traits::copied_type >::type default_make_container(Args&&... args) { typedef typename sprout::container_construct_traits::copied_type copied_type; return copied_type{SPROUT_FORWARD(Args, args)...}; } template inline SPROUT_CONSTEXPR typename std::enable_if< sprout::is_fixed_container::value, typename sprout::container_construct_traits::copied_type >::type default_remake_container(Cont&&, typename sprout::container_traits::difference_type, Args&&... args) { return sprout::container_construct_traits::make(SPROUT_FORWARD(Args, args)...); } template inline SPROUT_CONSTEXPR typename std::enable_if< !sprout::is_fixed_container::value && !(sizeof...(Args) == 2 && sprout::tpp::all_of::type>...>::value) , typename sprout::container_construct_traits::copied_type >::type default_remake_container(Cont&&, typename sprout::container_traits::difference_type, Args&&... args) { return sprout::container_construct_traits::make(SPROUT_FORWARD(Args, args)...); } template inline SPROUT_CONSTEXPR typename std::enable_if< !sprout::is_fixed_container::value, typename sprout::container_construct_traits::copied_type >::type default_remake_container(Cont&& cont, typename sprout::container_traits::difference_type, InputIterator first, InputIterator last) { typedef typename sprout::container_construct_traits::copied_type copied_type; return copied_type( sprout::make_remake_iterator( sprout::internal_begin(cont), first, first, last, sprout::internal_begin_offset(cont), sprout::internal_end_offset(cont) ), sprout::make_remake_iterator( sprout::internal_end(cont), last, first, last, sprout::internal_begin_offset_backward(cont), sprout::internal_end_offset_backward(cont) ) ); } template struct container_construct_traits_impl { public: typedef Container copied_type; public: template static SPROUT_CONSTEXPR copied_type deep_copy(Cont&& cont) { return SPROUT_FORWARD(Cont, cont); } template static SPROUT_CONSTEXPR copied_type make(Args&&... args) { return sprout::detail::default_make_container(SPROUT_FORWARD(Args, args)...); } template static SPROUT_CONSTEXPR copied_type remake(Cont&& cont, typename sprout::container_traits::difference_type size, Args&&... args) { return sprout::detail::default_remake_container( SPROUT_FORWARD(Cont, cont), size, SPROUT_FORWARD(Args, args)... ); } }; } // namespace detail template struct container_construct_traits : public sprout::detail::container_construct_traits_impl {}; template struct container_construct_traits : public sprout::container_construct_traits {}; } // namespace sprout #endif // #ifndef SPROUT_CONTAINER_CONTAINER_CONSTRUCT_TRAITS_HPP