13 template <std::
size_t TIndex,
typename TValue>
26 value = std::forward<T>(t);
30 using ReturnType = std::conditional_t<std::is_rvalue_reference<TValue>::value, TValue&&, TValue&>;
47 return std::forward<TValue>(value);
51 template <
typename TSequence,
typename... TArgs>
54 template <std::size_t... TIndices,
typename... TArgs>
57 static_assert(
sizeof...(TIndices) ==
sizeof...(TArgs),
"Internal error in tuple");
59 template <std::
size_t TIndex>
65 template <
typename... Ts,
66 typename = std::enable_if_t<AllTrue<std::is_constructible<TArgs, Ts>::value...>::value>>
70 template <
typename... Ts>
72 :
TupleValue<TIndices, TArgs>(other.template get<TIndices>())... {}
74 template <
typename... Ts>
76 :
TupleValue<TIndices, TArgs>(other.template forward<TIndices>())... {}
78 template <std::
size_t TIndex>
79 INLINE constexpr decltype(
auto) get() {
83 template <std::
size_t TIndex>
84 INLINE constexpr decltype(
auto) get()
const {
88 template <std::
size_t TIndex>
89 INLINE constexpr decltype(
auto) forward() {
94 template <
typename... Ts, std::size_t TIndex, std::size_t... TIdxs>
96 this->get<TIndex>() = other.template get<TIndex>();
97 copyAssign(other, std::index_sequence<TIdxs...>());
100 template <
typename... Ts>
103 template <
typename... Ts, std::size_t TIndex, std::size_t... TIdxs>
105 this->get<TIndex>() = other.template get<TIndex>();
106 copyAssign(other, std::index_sequence<TIdxs...>());
109 template <
typename... Ts>
112 template <
typename... Ts, std::size_t TIndex, std::size_t... TIdxs>
114 this->get<TIndex>() = other.template forward<TIndex>();
115 moveAssign(std::move(other), std::index_sequence<TIdxs...>());
118 template <
typename... Ts>
121 template <
typename... Ts, std::size_t TIndex, std::size_t... TIdxs>
123 return this->get<TIndex>() == other.template get<TIndex>() &&
124 isEqual(other, std::index_sequence<TIdxs...>());
127 template <
typename... Ts>
135 template <
typename T>
137 static constexpr
bool value =
false;
145 template <
typename... TArgs>
148 using Sequence = std::index_sequence_for<TArgs...>;
154 template <
typename... Ts,
155 typename = std::enable_if_t<AllTrue<std::is_constructible<TArgs, Ts>::value...>::value>>
157 :
Impl(
std::forward<Ts>(args)...) {}
165 template <
typename... Ts>
169 template <
typename... Ts>
176 this->copyAssign(other, Sequence());
182 this->copyAssign(other, Sequence());
189 this->copyAssign(std::move(other), Sequence());
194 template <
typename... Ts>
196 static_assert(
sizeof...(Ts) ==
sizeof...(TArgs),
"Cannot assign tuples of different sizes");
197 this->copyAssign(other, Sequence());
202 template <
typename... Ts>
204 static_assert(
sizeof...(Ts) ==
sizeof...(TArgs),
"Cannot assign tuples of different sizes");
205 this->copyAssign(other, Sequence());
210 template <
typename... Ts>
212 static_assert(
sizeof...(Ts) ==
sizeof...(TArgs),
"Cannot assign tuples of different sizes");
213 this->moveAssign(std::move(other), Sequence());
220 template <std::
size_t TIndex>
222 static_assert(
unsigned(TIndex) <
sizeof...(TArgs),
"Index out of bounds.");
223 return Impl::template get<TIndex>();
227 template <std::
size_t TIndex>
229 static_assert(
unsigned(TIndex) <
sizeof...(TArgs),
"Index out of bounds.");
230 return Impl::template get<TIndex>();
236 template <std::
size_t TIndex>
238 static_assert(
unsigned(TIndex) <
sizeof...(TArgs),
"Index out of bounds.");
239 return Impl::template forward<TIndex>();
244 template <
typename Type>
246 constexpr std::size_t index =
getTypeIndex<Type, TArgs...>;
247 static_assert(index != -1,
"Type not stored in tuple");
248 return Impl::template get<index>();
252 template <
typename Type>
254 constexpr std::size_t index =
getTypeIndex<Type, TArgs...>;
255 static_assert(index != -1,
"Type not stored in tuple");
256 return Impl::template get<index>();
260 template <
typename Type>
262 constexpr std::size_t index =
getTypeIndex<Type, TArgs...>;
263 static_assert(index != -1,
"Type not stored in tuple");
264 return Impl::template forward<index>();
269 return sizeof...(TArgs);
274 return Impl::isEqual(other, Sequence());
278 return !Impl::isEqual(other, Sequence());
282 template <
typename... TArgs>
286 template <
typename... TArgs>
290 template <
typename... TArgs>
297 template <
typename... TArgs>
303 template <
typename... TArgs>
305 return Tuple<TArgs&...>(args...);
311 template <
typename... TArgs>
313 return Tuple<TArgs&&...>(std::forward<TArgs>(args)...);
318 template <
typename T>
325 template <
typename... Ts1,
typename... Ts2, std::size_t... TIdxs>
327 std::index_sequence<TIdxs...>,
329 return Tuple<Ts1..., Ts2...>(tuple.template get<TIdxs>()..., std::forward<Ts2>(values)...);
332 template <
typename... Ts1,
typename... Ts2, std::size_t... TIdxs>
334 std::index_sequence<TIdxs...>,
336 return Tuple<Ts1..., Ts2...>(std::move(tuple).template get<TIdxs>()..., std::forward<Ts2>(values)...);
339 template <
typename... Ts1,
typename... Ts2, std::size_t... TIdxs1, std::size_t... TIdxs2>
342 std::index_sequence<TIdxs1...>,
343 std::index_sequence<TIdxs2...>) {
344 return Tuple<Ts1..., Ts2...>(t1.template get<TIdxs1>()..., t2.template get<TIdxs2>()...);
350 template <
typename... Ts1,
typename... Ts2>
352 return Detail::appendImpl(tuple, std::index_sequence_for<Ts1...>(), std::forward<Ts2>(values)...);
356 template <
typename... Ts1,
typename... Ts2>
359 std::move(tuple), std::index_sequence_for<Ts1...>(), std::forward<Ts2>(values)...);
363 template <
typename... Ts1,
typename... Ts2>
365 return Detail::appendImpl(t1, t2, std::index_sequence_for<Ts1...>(), std::index_sequence_for<Ts2...>());
370 template <
typename TTuple,
typename Type>
372 static constexpr
bool value =
false;
374 template <
typename... TArgs,
typename Type>
380 template <
typename TTuple, std::
size_t TIndex>
382 template <
typename... TArgs, std::size_t TIndex>
386 template <
typename... TArgs, std::size_t TIndex>
390 template <
typename... TArgs, std::size_t TIndex>
394 template <
typename... TArgs, std::size_t TIndex>
399 template <
typename TTuple, std::
size_t TIndex>
404 template <
typename TFunctor,
typename TTuple>
409 template <std::
size_t TIndex>
415 template <
typename TFunctor,
typename TTuple,
template <
class>
class TTrait>
420 template <std::
size_t TIndex>
421 INLINE std::enable_if_t<TTrait<TupleElement<TTuple, TIndex>>::value>
visit() {
425 template <std::
size_t TIndex>
426 INLINE std::enable_if_t<!TTrait<TupleElement<TTuple, TIndex>>::value>
visit() {}
432 template <
typename TFunctor,
typename... TArgs>
435 staticFor<0,
sizeof...(TArgs) - 1>(std::move(visitor));
439 template <
typename TFunctor,
typename... TArgs>
442 staticFor<0,
sizeof...(TArgs) - 1>(std::move(visitor));
446 template <
typename TFunctor,
typename... TArgs>
449 std::forward<TFunctor>(functor) };
450 staticFor<0,
sizeof...(TArgs) - 1>(std::move(visitor));
454 template <
template <
class T>
class TTrait,
typename TFunctor,
typename... TArgs>
457 std::forward<TFunctor>(functor) };
458 staticFor<0,
sizeof...(TArgs) - 1>(std::move(visitor));
463 template <
template <
class T>
class TTrait,
typename TFunctor,
typename... TArgs>
466 std::forward<TFunctor>(functor) };
467 staticFor<0,
sizeof...(TArgs) - 1>(std::move(visitor));
472 template <
typename TFunctor,
typename TTuple, std::size_t... TIndices>
473 INLINE decltype(
auto)
applyImpl(TTuple&& tuple, TFunctor&& functor,
std::index_sequence<TIndices...>) {
474 return functor(std::forward<TTuple>(tuple).
template get<TIndices>()...);
479 template <
typename TFunctor,
typename... TArgs>
481 return Detail::applyImpl(tuple, std::forward<TFunctor>(functor), std::index_sequence_for<TArgs...>());
485 template <
typename TFunctor,
typename... TArgs>
487 return Detail::applyImpl(tuple, std::forward<TFunctor>(functor), std::index_sequence_for<TArgs...>());
491 template <
typename TFunctor,
typename... TArgs>
494 std::move(tuple), std::forward<TFunctor>(functor), std::index_sequence_for<TArgs...>());
#define INLINE
Macros for conditional compilation based on selected compiler.
INLINE void staticFor(TVisitor &&visitor)
#define NAMESPACE_SPH_END
Few non-standard type traits.
typename TypeSelector< n, TArgs... >::Type SelectType
constexpr int getTypeIndex
INLINE Tuple< TArgs &... > tieToTuple(TArgs &... args)
Creates a tuple of l-value references. Use IGNORE placeholder to omit one or more parameters.
INLINE void forEachIf(Tuple< TArgs... > &tuple, TFunctor &&functor)
Iterates over elements of the tuple and executes a functor if given type traits has value == true.
constexpr INLINE Tuple< Ts1..., Ts2... > append(const Tuple< Ts1... > &tuple, Ts2 &&... values)
decltype(auto) INLINE apply(Tuple< TArgs... > &tuple, TFunctor &&functor)
Expands arguments stored in tuple into parameter pack of a functor.
const struct Ignore IGNORE
INLINE void forEach(Tuple< TArgs... > &tuple, TFunctor &&functor)
INLINE Tuple< TArgs &&... > forwardAsTuple(TArgs &&... args)
INLINE auto makeTuple(TArgs &&... args)
Creates a tuple from a pack of values, utilizing type deduction.
typename TupleElementType< TTuple, TIndex >::Type TupleElement
INLINE bool isEqual(const TupleImpl< Ts... > &UNUSED(other), std::index_sequence<>) const
constexpr INLINE TupleImpl(Ts &&... args)
constexpr INLINE TupleImpl(const TupleImpl< Ts... > &other)
INLINE void copyAssign(TupleImpl< Ts... > &UNUSED(other), std::index_sequence<>)
INLINE void moveAssign(const TupleImpl< Ts... > &UNUSED(other), std::index_sequence<>)
constexpr INLINE TupleImpl(TupleImpl< Ts... > &&other)
constexpr TupleImpl()=default
INLINE bool isEqual(const TupleImpl< Ts... > &other, std::index_sequence< TIndex, TIdxs... >) const
INLINE void copyAssign(const TupleImpl< Ts... > &UNUSED(other), std::index_sequence<>)
INLINE void copyAssign(TupleImpl< Ts... > &other, std::index_sequence< TIndex, TIdxs... >)
INLINE void moveAssign(TupleImpl< Ts... > &&other, std::index_sequence< TIndex, TIdxs... >)
INLINE void copyAssign(const TupleImpl< Ts... > &other, std::index_sequence< TIndex, TIdxs... >)
constexpr TupleValue()=default
constexpr INLINE TupleValue(T &&value)
constexpr INLINE ReturnType get()
Return r-value reference if TValue is an r-value reference, otherwise returns l-value reference.
std::conditional_t< std::is_rvalue_reference< TValue >::value, TValue &&, TValue & > ReturnType
constexpr INLINE const TValue & get() const
constexpr INLINE TValue && forward()
constexpr INLINE TupleValue & operator=(T &&t)
Heterogeneous container capable of storing a fixed number of values.
INLINE Tuple & operator=(Tuple< Ts... > &other)
Assigns tuple of generally different types. Same rules as above apply.
static constexpr INLINE std::size_t size() noexcept
Returns the number of elements in tuple.
constexpr INLINE Tuple(Tuple &&other)
constexpr INLINE Tuple()=default
constexpr INLINE bool operator!=(const Tuple &other) const
constexpr decltype(auto) INLINE get() &
constexpr INLINE Tuple(Tuple< Ts... > &&other)
constexpr INLINE Tuple(Ts &&... args)
INLINE Tuple & operator=(Tuple< Ts... > &&other)
Assigns tuple of generally different types. Same rules as above apply.
INLINE Tuple & operator=(const Tuple &other)
Assign conts l-value reference of tuple. All values are copied.
INLINE Tuple & operator=(const Tuple< Ts... > &other)
Assigns tuple of generally different types. Same rules as above apply.
INLINE Tuple & operator=(Tuple &&other)
constexpr INLINE Tuple(const Tuple &other)
constexpr INLINE Tuple(const Tuple< Ts... > &other)
constexpr INLINE bool operator==(const Tuple &other) const
INLINE Tuple & operator=(Tuple &other)
decltype(auto) INLINE applyImpl(TTuple &&tuple, TFunctor &&functor, std::index_sequence< TIndices... >)
constexpr INLINE Tuple< Ts1..., Ts2... > appendImpl(const Tuple< Ts1... > &tuple, std::index_sequence< TIdxs... >, Ts2 &&... values)
Overload of std::swap for Sph::Array.
INLINE std::enable_if_t< TTrait< TupleElement< TTuple, TIndex > >::value > visit()
INLINE std::enable_if_t<!TTrait< TupleElement< TTuple, TIndex > >::value > visit()
Placeholder for unused variables in tieToTuple.
const Ignore & operator=(T &&) const
Useful type trait, checking whether given type is a Tuple.
static constexpr bool value
static constexpr bool value
SelectType< TIndex, TArgs... > Type
SelectType< TIndex, TArgs... > Type
SelectType< TIndex, TArgs... > Type
SelectType< TIndex, TArgs... > Type
Gets type of tuple element given its index.