mirror of
https://github.com/bolero-MURAKAMI/Sprout
synced 2025-08-03 12:49:50 +00:00
fix: copy - support STL container
This commit is contained in:
parent
1ed18456b3
commit
d99a7d1436
7 changed files with 189 additions and 90 deletions
|
@ -1,6 +1,7 @@
|
|||
#ifndef SPROUT_CONTAINER_CONTAINER_TRAITS_CONSTRUCT_TRAITS_HPP
|
||||
#define SPROUT_CONTAINER_CONTAINER_TRAITS_CONSTRUCT_TRAITS_HPP
|
||||
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/container/container_traits.hpp>
|
||||
#include <sprout/utility/forward.hpp>
|
||||
|
@ -14,34 +15,51 @@ namespace sprout {
|
|||
|
||||
namespace detail {
|
||||
template<typename Container, typename... Args>
|
||||
inline SPROUT_CONSTEXPR typename sprout::container_construct_traits<Container>::copied_type
|
||||
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)...}};
|
||||
}
|
||||
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)...};
|
||||
}
|
||||
|
||||
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) {
|
||||
return make(sprout::forward<Args>(args)...);
|
||||
}
|
||||
};
|
||||
} // namespace detail
|
||||
|
||||
template<typename Container>
|
||||
struct container_construct_traits {
|
||||
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) {
|
||||
return make(sprout::forward<Args>(args)...);
|
||||
}
|
||||
};
|
||||
struct container_construct_traits
|
||||
: public sprout::detail::container_construct_traits_impl<Container>
|
||||
{};
|
||||
template<typename Container>
|
||||
struct container_construct_traits<Container const>
|
||||
: public sprout::container_construct_traits<Container>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue