2011-11-03 17:11:19 +00:00
|
|
|
#ifndef SPROUT_TUPLE_TRAITS_HPP
|
|
|
|
#define SPROUT_TUPLE_TRAITS_HPP
|
|
|
|
|
|
|
|
#include <sprout/config.hpp>
|
2012-03-31 07:24:13 +00:00
|
|
|
#include <sprout/index_tuple.hpp>
|
2011-11-03 17:11:19 +00:00
|
|
|
#include <sprout/tuple/tuple.hpp>
|
2011-11-06 01:56:57 +00:00
|
|
|
#include <sprout/type/rebind_types.hpp>
|
2012-07-15 12:20:56 +00:00
|
|
|
#include <sprout/utility/forward.hpp>
|
2011-11-03 17:11:19 +00:00
|
|
|
|
2011-12-06 10:55:08 +00:00
|
|
|
namespace sprout {
|
|
|
|
namespace types {
|
|
|
|
//
|
|
|
|
// rebind_types
|
|
|
|
//
|
|
|
|
template<typename... Ts>
|
|
|
|
struct rebind_types<sprout::tuples::tuple<Ts...> > {
|
|
|
|
public:
|
|
|
|
template<typename... Types>
|
|
|
|
struct apply {
|
|
|
|
public:
|
|
|
|
typedef sprout::tuples::tuple<Types...> type;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
} // namespace types
|
|
|
|
|
|
|
|
using sprout::types::rebind_types;
|
|
|
|
} // namespace sprout
|
|
|
|
|
2011-11-03 17:11:19 +00:00
|
|
|
namespace sprout {
|
|
|
|
namespace tuples {
|
|
|
|
//
|
|
|
|
// rebind_types
|
|
|
|
//
|
|
|
|
template<typename Tuple>
|
2011-11-06 01:56:57 +00:00
|
|
|
struct rebind_types
|
|
|
|
: public sprout::types::rebind_types<Tuple>
|
|
|
|
{};
|
2011-11-03 17:11:19 +00:00
|
|
|
|
|
|
|
//
|
2012-03-31 07:24:13 +00:00
|
|
|
// tuple_construct_traits
|
2011-11-03 17:11:19 +00:00
|
|
|
//
|
|
|
|
template<typename Tuple>
|
2012-03-31 07:24:13 +00:00
|
|
|
struct tuple_construct_traits;
|
|
|
|
|
|
|
|
namespace detail {
|
|
|
|
template<typename Tuple, typename IndexTuple>
|
|
|
|
struct default_copied;
|
|
|
|
template<typename Tuple, sprout::index_t... Indexes>
|
|
|
|
struct default_copied<Tuple, sprout::index_tuple<Indexes...> > {
|
|
|
|
public:
|
|
|
|
typedef typename sprout::tuples::rebind_types<Tuple>::template apply<
|
|
|
|
typename std::decay<
|
|
|
|
typename sprout::tuples::tuple_element<Indexes, Tuple>::type
|
|
|
|
>::type...
|
|
|
|
>::type type;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename Tuple, typename... Args>
|
|
|
|
SPROUT_CONSTEXPR typename sprout::tuples::tuple_construct_traits<Tuple>::copied_type
|
|
|
|
default_make_tuple(Args&&... args) {
|
|
|
|
typedef typename sprout::tuples::tuple_construct_traits<Tuple>::copied_type copied_type;
|
|
|
|
return copied_type(sprout::forward<Args>(args)...);
|
2011-11-03 17:11:19 +00:00
|
|
|
}
|
2012-03-31 07:24:13 +00:00
|
|
|
} // namespace detail
|
2011-11-03 17:11:19 +00:00
|
|
|
|
|
|
|
template<typename Tuple>
|
2012-03-31 07:24:13 +00:00
|
|
|
struct tuple_construct_traits {
|
2011-11-03 17:11:19 +00:00
|
|
|
public:
|
2012-03-31 07:24:13 +00:00
|
|
|
typedef typename sprout::tuples::detail::default_copied<
|
|
|
|
Tuple,
|
|
|
|
typename sprout::index_range<0, sprout::tuples::tuple_size<Tuple>::value>::type
|
|
|
|
>::type copied_type;
|
|
|
|
public:
|
|
|
|
template<typename Tup>
|
|
|
|
static SPROUT_CONSTEXPR copied_type deep_copy(Tup&& tup) {
|
|
|
|
return sprout::forward<Tup>(tup);
|
|
|
|
}
|
2011-11-03 17:11:19 +00:00
|
|
|
template<typename... Args>
|
2012-03-31 07:24:13 +00:00
|
|
|
static SPROUT_CONSTEXPR copied_type make(Args&&... args) {
|
|
|
|
return sprout::tuples::detail::default_make_tuple<Tuple>(sprout::forward<Args>(args)...);
|
2011-11-03 17:11:19 +00:00
|
|
|
}
|
2012-03-31 07:24:13 +00:00
|
|
|
template<typename Tup, typename... Args>
|
|
|
|
static SPROUT_CONSTEXPR copied_type remake(
|
|
|
|
Tup&& tup,
|
2011-11-03 17:11:19 +00:00
|
|
|
Args&&... args
|
2012-03-31 07:24:13 +00:00
|
|
|
)
|
2011-11-03 17:11:19 +00:00
|
|
|
{
|
2012-03-31 07:24:13 +00:00
|
|
|
return make(sprout::forward<Args>(args)...);
|
2011-11-03 17:11:19 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
template<typename Tuple>
|
2012-03-31 07:24:13 +00:00
|
|
|
struct tuple_construct_traits<Tuple const>
|
|
|
|
: public sprout::tuples::tuple_construct_traits<Tuple>
|
2011-11-03 17:11:19 +00:00
|
|
|
{};
|
|
|
|
} // namespace tuples
|
|
|
|
|
2012-03-31 07:24:13 +00:00
|
|
|
using sprout::tuples::tuple_construct_traits;
|
2011-11-03 17:11:19 +00:00
|
|
|
} // namespace sprout
|
|
|
|
|
|
|
|
#endif // #ifndef SPROUT_TUPLE_TRAITS_HPP
|