28 template<
size_t...>
struct TemplateSequence { };
29 template<
size_t N,
size_t... S>
struct SequenceGenerator
30 : SequenceGenerator<N-1, N-1, S...> { };
31 template<
size_t... S>
struct SequenceGenerator<0, S...> {
32 typedef TemplateSequence<S...> Sequence;
35 template<
size_t N,
class... Types>
36 class TupleBucket { };
38 template<
size_t N,
class Type1,
class... Types>
39 class TupleBucket<N, Type1, Types...>
40 :
public TupleBucket<N+1, Types...> {
45 TupleBucket(Type1& type1, Types&... types)
46 : TupleBucket<N+1, Types...>(types...)
50 inline Type1& Get() {
return type1; }
51 inline const Type1& Get()
const {
return type1; }
61 template<
class... Types>
62 class Tuple :
public TupleBucket<0, Types...> {
68 template<
int ResolveAmbiguity=0>
69 Tuple(
const typename std::add_lvalue_reference<
70 typename std::remove_reference<Types>::type>::type... types)
71 : TupleBucket<0, Types...>(types...) { }
74 template<
bool ResolveAmbiguity=0>
75 Tuple(
typename std::add_rvalue_reference<
76 typename std::remove_reference<Types>::type>::type... types)
77 : TupleBucket<0, Types...>(types...) { }
81 return Apply(std::tie<Types...>);
86 template<
size_t N,
class Type1,
class... GTypes>
87 inline Type1& GetHelper(TupleBucket<N, Type1, GTypes...>& tup) {
90 template<
size_t N,
class Type1,
class... GTypes>
91 inline const Type1& GetHelper(
92 const TupleBucket<N, Type1, GTypes...>& tup)
const {
100 inline auto Get() -> decltype(this->GetHelper<N>(*
this)) {
101 return GetHelper<N>(*
this);
105 inline auto Get() const -> decltype(this->GetHelper<N>(*this)) {
106 return GetHelper<N>(*
this);
110 template<
size_t N,
class Val>
111 inline void Set(Val val) {
112 GetHelper<N>(*
this) = val;
117 template<
class Func,
size_t... Indices>
118 inline auto ApplyHelper(Func f, TemplateSequence<Indices...>)
119 -> decltype(f(this->Get<Indices>()...)) {
120 return f(Get<Indices>()...);
123 template<
class T,
size_t... Indices>
124 inline Data1D<T> AsDataHelper(TemplateSequence<Indices...>)
const {
125 return Data1D<T>{T(Get<Indices>())...};
135 -> decltype(this->ApplyHelper(f,
136 (
typename SequenceGenerator<
sizeof...(Types)>::Sequence()))) {
137 return ApplyHelper(f,
138 (
typename SequenceGenerator<
sizeof...(Types)>::Sequence()));
144 return AsDataHelper<T>(
145 (
typename SequenceGenerator<
sizeof...(Types)>::Sequence()));
149 inline void Get(Types&... types) {
155 template<
class... OtherTypes,
size_t... Indices,
size_t... OtherIndices>
156 inline Tuple<Types..., OtherTypes...> ConcatHelper
158 TemplateSequence<OtherIndices...>) {
159 return Tuple<Types..., OtherTypes...>(Get<Indices>()...,
160 other.template Get<OtherIndices>()...);
166 template<
class... OtherTypes>
167 inline Tuple<Types..., OtherTypes...>
operator+
168 (
Tuple<OtherTypes...>& other) {
169 return ConcatHelper(other,
170 typename SequenceGenerator<
sizeof...(Types)>::Sequence(),
171 typename SequenceGenerator<
sizeof...(OtherTypes)>::Sequence());
178 template<
class... Types>
180 return Tuple<Types...>(types...);
Provides a one-dimensional vector-like structure.
The version information and configuration settings for RC Lib.
Provides typedefs and routines for working with primitives.
A bounds-safe one-dimensional vector-like structure.
Definition: Data1D.h:49
An efficient Tuple class with Set, Get, and an Apply function to pass the tuple contents on to any fu...
Definition: Tuple.h:62
void Get(Types &... types)
Get all elements at once, by reference.
Definition: Tuple.h:149
auto Get() const -> decltype(this->GetHelper< N >(*this))
Return element N in the Tuple.
Definition: Tuple.h:105
Tuple(typename std::add_rvalue_reference< typename std::remove_reference< Types >::type >::type... types)
Construct by moving elements in.
Definition: Tuple.h:75
Tuple()
Default constructor, elements use default constructors.
Definition: Tuple.h:65
auto Get() -> decltype(this->GetHelper< N >(*this))
Return element N in the Tuple.
Definition: Tuple.h:100
Tuple(const typename std::add_lvalue_reference< typename std::remove_reference< Types >::type >::type... types)
Construct by const reference.
Definition: Tuple.h:69
void Set(Val val)
Set element N in the Tuple.
Definition: Tuple.h:111
std::tuple< Types... > GetStdTuple()
Returns a std::tuple of the same contents.
Definition: Tuple.h:80
Data1D< T > AsData() const
Return a Data1D array with each element constructed as type T.
Definition: Tuple.h:143
auto Apply(Func f) -> decltype(this->ApplyHelper(f,(typename SequenceGenerator< sizeof...(Types)>::Sequence())))
Call function f with each element of the Tuple as an argument.
Definition: Tuple.h:134
Tuple< Types... > MakeTuple(Types... types)
A convenience generator to make a Tuple from the given elements with type inference.
Definition: Tuple.h:179