1 #if !defined (RECURSIVE_UNION_93F14ED0_E99B_4CF3_8A9B_EBE084D9079C_H)
2 # define RECURSIVE_UNION_93F14ED0_E99B_4CF3_8A9B_EBE084D9079C_H
16 # include <type_traits>
61 template <
class T,
class... Ts>
67 -> decltype (u.v.get ()) {
73 -> decltype (u.v.get ()) {
79 -> decltype (u.v.get_pointer ()) {
80 return u.v.get_pointer ();
85 -> decltype (u.v.get_pointer ()) {
86 return u.v.get_pointer ();
121 template <
class T,
class... Ts>
161 template <
class R,
class T,
class... Ts>
168 class O,
class F,
class... Fs,
169 class = pgs::enable_if_t<is_callable<F, T>::value,
void>
172 return std::forward<F>(f)(t);
177 class F,
class O,
class... Fs,
178 class = pgs::enable_if_t<!is_callable<F, T>::value,
void>
185 class O,
class F,
class... Fs,
186 class = pgs::enable_if_t<is_callable<F, T>::value,
void>
189 return std::forward<F>(f)(t);
193 class F,
class O,
class... Fs,
194 class = pgs::enable_if_t<!is_callable<F, T>::value,
void>
209 template <
class T,
class... Ts>
216 class O,
class F,
class... Fs,
217 class = pgs::enable_if_t<is_callable<F, T>::value,
void>
220 std::forward<F>(f)(t);
225 class F,
class O,
class... Fs,
226 class = pgs::enable_if_t<!is_callable<F, T>::value,
void>
233 class O,
class F,
class... Fs,
234 class = pgs::enable_if_t<is_callable<F, T>::value,
void>
237 std::forward<F>(f)(t);
241 class F,
class O,
class... Fs,
242 class = pgs::enable_if_t<!is_callable<F, T>::value,
void>
276 struct mk_range : mk_range <Z, N - 1, N, Ns...>
280 struct mk_range<Z, Z, Ns...> {
281 using type = range<Z, Ns...>;
287 template <std::
size_t Z, std::
size_t N>
288 using range_t =
typename detail::mk_range<Z, N>::type;
296 template <
class R,
class... Ts>
305 template <
class... Fs>
315 template <
class... Fs>
329 template <
class... Ts>
338 template <
class... Fs>
348 template <
class... Fs>
379 template <
class... Fs>
386 o, u.v, std::forward<Fs>(fs)...);
390 u.r, i, std::forward<Fs>(fs)...);
395 template <
class... Fs>
402 o, u.
v, std::forward<Fs>(fs)...);
406 u.
r, i, std::forward<Fs>(fs)...);
437 template <
class... Fs>
444 o, u.v.get (), std::forward<Fs>(fs)...);
448 u.r, i, std::forward<Fs>(fs)...);
453 template <
class... Fs>
460 o, u.v.get (), std::forward<Fs>(fs)...);
464 u.r, i, std::forward<Fs>(fs)...);
493 template <
class... Fs>
501 o, u.v, std::forward<Fs>(fs)...);
505 u.r, i, std::forward<Fs>(fs)...);
510 template <
class... Fs>
518 o, u.
v, std::forward<Fs>(fs)...);
522 u.
r, i, std::forward<Fs>(fs)...);
556 template <
class... Fs>
563 o, u.v.get (), std::forward<Fs>(fs)...);
567 u.r, i, std::forward<Fs>(fs)...);
572 template <
class... Fs>
579 o, u.v.get (), std::forward<Fs>(fs)...);
583 u.r, i, std::forward<Fs>(fs)...);
604 # if defined(_MSC_VER)
605 # pragma warning(push)
606 # pragma warning(disable:4624)
607 # endif//defined (_MSC_VER)
613 template <
class T,
class... Ts>
623 template <
class... Args>
625 : v (
std::forward<Args>(args)...)
632 template <
class U,
class... Args,
637 noexcept (
std::is_nothrow_constructible<U, Args...>::value)
638 : v (
std::forward<Args>(args)...)
645 template <
class U,
class... Args,
653 std::is_nothrow_constructible<Ts...,
constructor<U>, Args...>::value
655 : r (t,
std::forward<Args>(args)...)
673 && noexcept (std::declval<recursive_union>().r.copy (i - 1, u.r))
694 std::is_nothrow_move_constructible<T>::value
696 i - 1,
std::move (u.r)))
715 && noexcept (std::declval<recursive_union>().r.destruct (i - 1))) {
734 return i == 0 ? v == rhs.v : r.compare (i - 1, rhs.r);
747 # if defined(_MSC_VER)
748 # pragma warning(pop)
749 # endif//defined (_MSC_VER)
static constexpr T const * ptr(recursive_union< T, Ts... > const &u)
Produce a const pointer to the value field of the provided union.
Definition: recursive_union.hpp:53
Primary template of a metafunction to classify a type as recursive_wrapper<> or not.
Definition: recursive_wrapper.hpp:29
invalid_sum_type_access(char const *what)
Construct from char const*
Definition: recursive_union.hpp:263
Parameter pack conjunction.
Definition: logical.hpp:83
recursive_union< Ts... > r
... recursive union
Definition: recursive_union.hpp:743
static result_type visit(recursive_union< T, Ts... > &u, std::size_t i, Fs &&...fs)
non-const overload (recursive_union&)
Definition: recursive_union.hpp:396
R result_type
The type returned by visit
Definition: recursive_union.hpp:434
static result_type visit(overload_tag< O >, T &t, F &&f, Fs &&...)
f is callable on t (of type T&)
Definition: recursive_union.hpp:236
static result_type visit(recursive_union< type, Ts... > const &u, std::size_t i, Fs &&...fs)
'const' overload ('recursive_union const& u')
Definition: recursive_union.hpp:495
void result_type
The type returned by visit
Definition: recursive_union.hpp:553
static constexpr auto ref(recursive_union< T, Ts... > const &u) -> decltype(recursive_union_indexer< I-1, Ts... >::ref(u.r))
Decrement I, strip off T and recurse.
Definition: recursive_union.hpp:102
static constexpr auto ptr(recursive_union< T, Ts... > &u) -> decltype(u.v.get_pointer())
Produce a non-const pointer to the object referred to by the value field of the provided union...
Definition: recursive_union.hpp:78
static result_type visit(recursive_union< U, Ts... > &u, std::size_t i, Fs &&...fs)
non-const overload (recursive_union&)
Definition: recursive_union.hpp:454
recursive_union(constructor< U >, Args &&...args) noexcept(std::is_nothrow_constructible< U, Args... >::value)
Construct (a recursive_wrapper) into v
Definition: recursive_union.hpp:636
void copy(std::size_t i, recursive_union const &u) noexcept( std::is_nothrow_copy_constructible< T >::value &&noexcept(std::declval< recursive_union >().r.copy(i-1, u.r)) )
Copy.
Definition: recursive_union.hpp:670
Primary template.
Definition: recursive_union.hpp:162
Definition: logical.hpp:13
static constexpr auto ptr(recursive_union< T, Ts... > const &u) -> decltype(recursive_union_dereference< is_recursive_wrapper< T >::value, T, Ts... >::ptr(u))
Dereference the value field to produce a const pointer.
Definition: recursive_union.hpp:143
invalid_sum_type_access(std::string const &what)
Construct from std::string const&
Definition: recursive_union.hpp:255
The purpose of this type is to walk a recursive_union<> and return the value field of the Ith union i...
Definition: recursive_union.hpp:93
~recursive_union()
Dtor.
Definition: recursive_union.hpp:659
recursive_union(constructor< U > t, Args &&...args) noexcept( std::is_nothrow_constructible< Ts..., constructor< U >, Args... >::value )
Construct into r
Definition: recursive_union.hpp:651
static result_type visit(overload_tag< O >, T const &t, F &&f, Fs &&...)
f is callable on t (of type T const&)
Definition: recursive_union.hpp:171
static result_type visit(overload_tag< O > o, T &t, F &&, Fs &&...fs)
f is not callable on t (of type T&)
Definition: recursive_union.hpp:196
static result_type visit(recursive_union< Ts... > const &, std::size_t, Fs &&...)
This definition applies when Ts... is empty.
Definition: recursive_union.hpp:339
R result_type
The return type of visit
Definition: recursive_union.hpp:164
static constexpr T * ptr(recursive_union< T, Ts... > &u)
Produce a non-const pointer to the value field of the provided union.
Definition: recursive_union.hpp:48
Dereference the value field in a recursive_union<>. This case handles values that are not recursive_w...
Definition: recursive_union.hpp:34
Partial specialization.
Definition: recursive_union.hpp:614
static result_type visit(recursive_union< Ts... > &, std::size_t, Fs &&...)
This definition applies when Ts... is empty.
Definition: recursive_union.hpp:316
recursive_union()
Default ctor.
Definition: recursive_union.hpp:617
R result_type
The return type of visit
Definition: recursive_union.hpp:299
Definition: type_traits.hpp:26
Conjunctions and disjunctions over predicate packs.
bool compare(size_t i, recursive_union const &rhs) const noexcept
Equality comparison.
Definition: recursive_union.hpp:732
void move(std::size_t i, recursive_union &&u) noexcept( std::is_nothrow_move_constructible< T >::value &&noexcept(std::declval< recursive_union >().r.move( i-1, std::move(u.r))) )
Move.
Definition: recursive_union.hpp:692
void destruct(std::size_t i) noexcept(std::is_nothrow_destructible< T >::value &&noexcept(std::declval< recursive_union >().r.destruct(i-1)))
Destruct.
Definition: recursive_union.hpp:713
static result_type visit(recursive_union< U, Ts... > const &u, std::size_t i, Fs &&...fs)
const overload (recursive_union const&)
Definition: recursive_union.hpp:557
void move(std::size_t, recursive_union &&)
move is a no-op
Definition: recursive_union.hpp:597
static constexpr auto ptr(recursive_union< T, Ts... > &u) -> decltype(recursive_union_indexer< I-1, Ts... >::ptr(u.r))
Decrement I, strip off T and recurse.
Definition: recursive_union.hpp:108
invalid_sum_type_access(std::string &&what)
Construct from std::string&&
Definition: recursive_union.hpp:259
A type to model an overload.
Definition: recursive_union.hpp:28
static result_type visit(overload_tag< O > o, T const &t, F &&, Fs &&...fs)
f is not callable on t (of type T const&), recurse
Definition: recursive_union.hpp:228
T type
The type held by the value.
Definition: recursive_union.hpp:432
bool compare(std::size_t, recursive_union const &) const
compare returns false
Definition: recursive_union.hpp:601
static auto ref(recursive_union< T, Ts... > &u) -> decltype(u.v.get())
Produce a non-const reference to the object referred to by the value field of the provided union...
Definition: recursive_union.hpp:66
T v
Value or...
Definition: recursive_union.hpp:742
R result_type
The return type of visit
Definition: recursive_union.hpp:376
static result_type visit(overload_tag< O > o, T &t, F &&, Fs &&...fs)
f is not callable on t (of type T&)
Definition: recursive_union.hpp:244
static constexpr auto ptr(recursive_union< T, Ts... > const &u) -> decltype(u.v.get_pointer())
Produce a const pointer to the object referred to by the value field of the provided union...
Definition: recursive_union.hpp:84
void result_type
The return type of visit
Definition: recursive_union.hpp:332
void result_type
return type of visit
Definition: recursive_union.hpp:212
static result_type visit(recursive_union< Ts... > &, std::size_t, Fs &&...)
This definition applies when Ts... is empty.
Definition: recursive_union.hpp:349
static result_type visit(recursive_union< type, Ts... > const &u, std::size_t i, Fs &&...fs)
const overload (recursive_union const&)
Definition: recursive_union.hpp:380
T type
The type of the value.
Definition: recursive_union.hpp:375
static constexpr auto ptr(recursive_union< T, Ts... > &u) -> decltype((recursive_union_dereference< is_recursive_wrapper< T >::value, T, Ts... >::ptr(u)))
Dereference the value field to produce a non-const pointer.
Definition: recursive_union.hpp:137
A workaround for the absence of recursive types.
static constexpr auto ref(recursive_union< T, Ts... > const &u) -> decltype(recursive_union_dereference< is_recursive_wrapper< T >::value, T, Ts... >::ref(u))
Dereference the value field to produce a const reference.
Definition: recursive_union.hpp:131
T type
The type held by the value.
Definition: recursive_union.hpp:551
Compile time sequence of integers.
Definition: recursive_union.hpp:271
Exception type raised on an invalid access into a recursive_union<>
Definition: recursive_union.hpp:253
A type to model a sum constructor.
Definition: recursive_union.hpp:22
At this time contains only a metafunction for determining if a given type F is "callable" on a parame...
types
Definition: recursive_wrapper.hpp:82
static result_type visit(recursive_union< T, Ts... > &u, std::size_t i, Fs &&...fs)
'non-const' overload ('recursive_union& u')
Definition: recursive_union.hpp:512
static result_type visit(recursive_union< U, Ts... > &u, std::size_t i, Fs &&...fs)
non-const overload (recursive_union&)
Definition: recursive_union.hpp:573
recursive union<> primary template
Definition: recursive_union.hpp:25
void result_type
The return type of visit
Definition: recursive_union.hpp:490
static result_type visit(overload_tag< O >, T &t, F &&f, Fs &&...)
f is callable on t (of type T&)
Definition: recursive_union.hpp:188
T type
The type of the value.
Definition: recursive_union.hpp:489
static auto ref(recursive_union< T, Ts... > const &u) -> decltype(u.v.get())
Produce a const reference to the object referred to by the value field of the provided union...
Definition: recursive_union.hpp:72
recursive_union(constructor< T >, Args &&...args)
Construct a T into v
Definition: recursive_union.hpp:624
static result_type visit(overload_tag< O >, T const &t, F &&f, Fs &&...)
f is callable on t (of type T const&)
Definition: recursive_union.hpp:219
static constexpr auto ref(recursive_union< T, Ts... > &u) -> decltype(recursive_union_dereference< is_recursive_wrapper< T >::value, T, Ts... >::ref(u))
Dereference the value field to produce a non-const reference.
Definition: recursive_union.hpp:125
static result_type visit(overload_tag< O > o, T const &t, F &&, Fs &&...fs)
f is not callable on t (of type T const&), recurse
Definition: recursive_union.hpp:180
static constexpr auto ref(recursive_union< T, Ts... > &u) -> decltype(recursive_union_indexer< I-1, Ts... >::ref(u.r))
Decrement I, strip off T and recurse.
Definition: recursive_union.hpp:96
static constexpr T const & ref(recursive_union< T, Ts... > const &u)
Produce a const reference to the value field of the provided union.
Definition: recursive_union.hpp:43
static result_type visit(recursive_union< Ts... > const &, std::size_t, Fs &&...)
This definition applies when Ts... is empty.
Definition: recursive_union.hpp:306
void copy(std::size_t, recursive_union const &)
copy is a no-op
Definition: recursive_union.hpp:595
void destruct(std::size_t)
destruct is a no-op
Definition: recursive_union.hpp:599
static constexpr T & ref(recursive_union< T, Ts... > &u)
Produce a non-const reference to the value field of the provided union.
Definition: recursive_union.hpp:38
static constexpr auto ptr(recursive_union< T, Ts... > const &u) -> decltype(recursive_union_indexer< I-1, Ts... >::ptr(u.r))
Decrement I, strip off T and recurse.
Definition: recursive_union.hpp:113
static result_type visit(recursive_union< U, Ts... > const &u, std::size_t i, Fs &&...fs)
const overload (recursive_union const&)
Definition: recursive_union.hpp:438