13 #ifndef OGLPLUS_OPT_LIST_INIT_HPP
14 #define OGLPLUS_OPT_LIST_INIT_HPP
16 #include <type_traits>
24 template <
typename T, std::
size_t I>
25 class ListInitializerBase
29 const ListInitializerBase<
T, I-1>* _prev;
31 friend class ListInitializerBase<
T, I+1>;
33 template <
typename RandomAccessContainer>
34 void _init(RandomAccessContainer& dest)
const
40 template <
typename BackInsertionContainer>
41 void _push_back(BackInsertionContainer& dest)
const
43 _prev->_push_back(dest);
44 dest.push_back(_value);
47 ListInitializerBase(
T value,
const ListInitializerBase<T, I-1>* prev)
54 class ListInitializerBase<
T, 0>
59 friend class ListInitializerBase<
T, 1>;
62 template <
typename RandomAccessContainer>
63 void _init(RandomAccessContainer& dest)
const
68 template <
typename BackInsertionContainer>
69 void _push_back(BackInsertionContainer& dest)
const
71 dest.push_back(_value);
74 ListInitializerBase(
T value)
79 template <
typename T, std::
size_t I>
81 :
public ListInitializerBase<T, I>
84 typedef ListInitializerBase<T, I> _base;
86 friend class ListInitializer<
T, I-1>;
89 static decltype(X(), std::true_type()) _has_def_ctr(X*);
91 static std::false_type _has_def_ctr(...);
93 static std::array<
T, I+1> _result_of_get(std::true_type);
95 static std::vector<T> _result_of_get(std::false_type);
97 typedef decltype(_result_of_get(_has_def_ctr((T*)0))) ResultOfGet;
100 void _do_get(std::array<X, I+1>& result)
const
105 void _do_get(std::vector<T>& result)
const
107 this->_push_back(result);
110 template <
typename StdContainer>
111 StdContainer _do_get_as(StdContainer*, std::true_type)
const
113 return StdContainer(Get());
116 template <
typename StdContainer>
117 StdContainer _do_get_as(StdContainer*, std::false_type)
const
120 return StdContainer(tmp.begin(), tmp.end());
124 ListInitializer(
const ListInitializer&);
126 ListInitializer(
T value,
const ListInitializer<T, I-1>* prev)
130 ListInitializer(
T value)
134 ListInitializer(ListInitializer&& temp)
138 ListInitializer<T, I+1> operator()(
T value)
const
140 return ListInitializer<T, I+1>(value,
this);
143 ResultOfGet Get(
void)
const
146 this->_do_get(result);
150 template <
typename StdContainer>
151 StdContainer As(
void)
const
153 return this->_do_get_as(
154 (StdContainer*)
nullptr,
155 typename std::is_convertible<
162 std::vector<T> AsVector(
void)
const
164 return As<std::vector<T>>();
190 template <
typename T>
192 :
public aux::ListInitializer<T, 0>
196 : aux::ListInitializer<T, 0>(value)
220 template <
typename T>
221 inline aux::ListInitializer<T, 0>
List(T value)
223 return aux::ListInitializer<T, 0>(value);
228 #endif // include guard
Helper class template that can be used for static container initialization.
Definition: list_init.hpp:191
aux::ListInitializer< T, 0 > List(T value)
Helper function template that can be used for static container initialization.
Definition: list_init.hpp:221