2012-03-31 07:24:13 +00:00
|
|
|
#ifndef SPROUT_CONTAINER_CONTAINER_TRAITS_CONSTRUCT_TRAITS_HPP
|
|
|
|
#define SPROUT_CONTAINER_CONTAINER_TRAITS_CONSTRUCT_TRAITS_HPP
|
|
|
|
|
2013-01-13 16:13:48 +00:00
|
|
|
#include <type_traits>
|
2012-03-31 07:24:13 +00:00
|
|
|
#include <sprout/config.hpp>
|
|
|
|
#include <sprout/container/container_traits.hpp>
|
2013-01-16 18:53:17 +00:00
|
|
|
#include <sprout/container/internal_begin.hpp>
|
|
|
|
#include <sprout/container/internal_end.hpp>
|
|
|
|
#include <sprout/container/internal_begin_offset.hpp>
|
|
|
|
#include <sprout/container/internal_end_offset.hpp>
|
|
|
|
#include <sprout/container/internal_begin_offset_backward.hpp>
|
|
|
|
#include <sprout/container/internal_end_offset_backward.hpp>
|
|
|
|
#include <sprout/iterator/remake_iterator.hpp>
|
2013-02-26 07:14:04 +00:00
|
|
|
#include <sprout/iterator/type_traits/category.hpp>
|
2012-03-31 07:24:13 +00:00
|
|
|
#include <sprout/utility/forward.hpp>
|
2013-02-26 03:39:03 +00:00
|
|
|
#include <sprout/tpp/algorithm/all_of.hpp>
|
2012-03-31 07:24:13 +00:00
|
|
|
|
|
|
|
namespace sprout {
|
|
|
|
//
|
|
|
|
// container_construct_traits
|
|
|
|
//
|
|
|
|
template<typename Container>
|
|
|
|
struct container_construct_traits;
|
|
|
|
|
|
|
|
namespace detail {
|
|
|
|
template<typename Container, typename... Args>
|
2013-01-13 16:13:48 +00:00
|
|
|
inline SPROUT_CONSTEXPR typename std::enable_if<
|
|
|
|
sprout::is_fixed_container<Container>::value,
|
|
|
|
typename sprout::container_construct_traits<Container>::copied_type
|
|
|
|
>::type
|
2012-03-31 07:24:13 +00:00
|
|
|
default_make_container(Args&&... args) {
|
|
|
|
typedef typename sprout::container_construct_traits<Container>::copied_type copied_type;
|
|
|
|
return copied_type{{sprout::forward<Args>(args)...}};
|
|
|
|
}
|
2013-01-13 16:13:48 +00:00
|
|
|
template<typename Container, typename... Args>
|
|
|
|
inline SPROUT_CONSTEXPR typename std::enable_if<
|
|
|
|
!sprout::is_fixed_container<Container>::value,
|
|
|
|
typename sprout::container_construct_traits<Container>::copied_type
|
|
|
|
>::type
|
|
|
|
default_make_container(Args&&... args) {
|
|
|
|
typedef typename sprout::container_construct_traits<Container>::copied_type copied_type;
|
|
|
|
return copied_type{sprout::forward<Args>(args)...};
|
|
|
|
}
|
|
|
|
|
2013-01-16 18:53:17 +00:00
|
|
|
template<typename Container, typename Cont, typename... Args>
|
|
|
|
inline SPROUT_CONSTEXPR typename std::enable_if<
|
|
|
|
sprout::is_fixed_container<Container>::value,
|
|
|
|
typename sprout::container_construct_traits<Container>::copied_type
|
|
|
|
>::type
|
2013-07-22 13:00:09 +00:00
|
|
|
default_remake_container(Cont&&, typename sprout::container_traits<Container>::difference_type, Args&&... args) {
|
2013-01-16 18:53:17 +00:00
|
|
|
return sprout::container_construct_traits<Container>::make(sprout::forward<Args>(args)...);
|
|
|
|
}
|
|
|
|
template<typename Container, typename Cont, typename... Args>
|
|
|
|
inline SPROUT_CONSTEXPR typename std::enable_if<
|
2013-02-26 03:39:03 +00:00
|
|
|
!sprout::is_fixed_container<Container>::value
|
|
|
|
&& !(sizeof...(Args) == 2 && sprout::tpp::all_of<sprout::is_input_iterator<typename std::remove_reference<Args>::type>...>::value)
|
|
|
|
,
|
2013-01-16 18:53:17 +00:00
|
|
|
typename sprout::container_construct_traits<Container>::copied_type
|
|
|
|
>::type
|
2013-07-22 13:00:09 +00:00
|
|
|
default_remake_container(Cont&&, typename sprout::container_traits<Container>::difference_type, Args&&... args) {
|
2013-01-16 18:53:17 +00:00
|
|
|
return sprout::container_construct_traits<Container>::make(sprout::forward<Args>(args)...);
|
|
|
|
}
|
|
|
|
template<typename Container, typename Cont, typename InputIterator>
|
|
|
|
inline SPROUT_CONSTEXPR typename std::enable_if<
|
|
|
|
!sprout::is_fixed_container<Container>::value,
|
|
|
|
typename sprout::container_construct_traits<Container>::copied_type
|
|
|
|
>::type
|
2013-07-22 13:00:09 +00:00
|
|
|
default_remake_container(Cont&& cont, typename sprout::container_traits<Container>::difference_type, InputIterator first, InputIterator last) {
|
2013-01-16 18:53:17 +00:00
|
|
|
typedef typename sprout::container_construct_traits<Container>::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)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2013-01-13 16:13:48 +00:00
|
|
|
template<typename Container>
|
|
|
|
struct container_construct_traits_impl {
|
|
|
|
public:
|
|
|
|
typedef Container copied_type;
|
|
|
|
public:
|
|
|
|
template<typename Cont>
|
|
|
|
static SPROUT_CONSTEXPR copied_type
|
|
|
|
deep_copy(Cont&& cont) {
|
|
|
|
return sprout::forward<Cont>(cont);
|
|
|
|
}
|
|
|
|
template<typename... Args>
|
|
|
|
static SPROUT_CONSTEXPR copied_type
|
|
|
|
make(Args&&... args) {
|
|
|
|
return sprout::detail::default_make_container<Container>(sprout::forward<Args>(args)...);
|
|
|
|
}
|
|
|
|
template<typename Cont, typename... Args>
|
|
|
|
static SPROUT_CONSTEXPR copied_type
|
|
|
|
remake(Cont&& cont, typename sprout::container_traits<Container>::difference_type size, Args&&... args) {
|
2013-01-16 18:53:17 +00:00
|
|
|
return sprout::detail::default_remake_container<Container>(
|
|
|
|
sprout::forward<Cont>(cont), size,
|
|
|
|
sprout::forward<Args>(args)...
|
|
|
|
);
|
2013-01-13 16:13:48 +00:00
|
|
|
}
|
|
|
|
};
|
2012-03-31 07:24:13 +00:00
|
|
|
} // namespace detail
|
|
|
|
|
|
|
|
template<typename Container>
|
2013-01-13 16:13:48 +00:00
|
|
|
struct container_construct_traits
|
|
|
|
: public sprout::detail::container_construct_traits_impl<Container>
|
|
|
|
{};
|
2012-03-31 07:24:13 +00:00
|
|
|
template<typename Container>
|
|
|
|
struct container_construct_traits<Container const>
|
|
|
|
: public sprout::container_construct_traits<Container>
|
|
|
|
{};
|
|
|
|
} // namespace sprout
|
|
|
|
|
|
|
|
#endif // #ifndef SPROUT_CONTAINER_CONTAINER_CONSTRUCT_TRAITS_HPP
|