/
tuple.hpp
105 lines (69 loc) · 3.38 KB
/
tuple.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/* This file is part of the ivl C++ library <http://image.ntua.gr/ivl>.
A C++ template library extending syntax towards mathematical notation.
Copyright (C) 2012 Yannis Avrithis <iavr@image.ntua.gr>
Copyright (C) 2012 Kimon Kontosis <kimonas@image.ntua.gr>
ivl is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License
version 3 as published by the Free Software Foundation.
Alternatively, you can redistribute it and/or modify it under the terms
of the GNU General Public License version 2 as published by the Free
Software Foundation.
ivl is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
and a copy of the GNU Lesser General Public License along
with ivl. If not, see <http://www.gnu.org/licenses/>. */
//-----------------------------------------------------------------------------
#ifndef IVL_CORE_TUPLE_STORE_TUPLE_HPP
#define IVL_CORE_TUPLE_STORE_TUPLE_HPP
#include <ivl/ivl>
//-----------------------------------------------------------------------------
namespace ivl {
//-----------------------------------------------------------------------------
namespace tuples {
//-----------------------------------------------------------------------------
namespace details {
//-----------------------------------------------------------------------------
template <typename P, typename I = sz_rng_of_p <P> >
struct tuple_impl;
template <typename... E, size_t... I>
class tuple_impl <pack <E...>, sizes <I...> > :
public pre_tuple <E...>
{
using B = pre_tuple <E...>;
public:
explicit INLINE constexpr tuple_impl(_true) : B() { }
template <typename... A>
explicit INLINE constexpr tuple_impl(_true, A&&... a) : B(fwd <A>(a)...) { }
template <typename T>
INLINE constexpr tuple_impl(T&& t) : B(_at._<I>(fwd <T>(t))...) { }
};
//-----------------------------------------------------------------------------
template <typename... E>
class collection <tag::tuple, E...> : public tuple_impl <pack <E...> >
{
using P = pack <E...>;
using B = tuple_impl <P>;
public:
using B::base_type::operator=;
template <typename A = int, only_if <_and <is_cons <E>...>{}, A> = 0>
INLINE constexpr collection() : B(yes) { }
template <typename... A, only_if <tup_conv <pack <A...>, P>{}> = 0>
INLINE constexpr collection(A&&... a) : B(yes, fwd <A>(a)...) { }
template <typename... A, only_if <tup_explicit <P, pack <A...> >{}> = 0>
explicit INLINE constexpr collection(A&&... a) : B(yes, fwd <A>(a)...) { }
template <typename T, only_if <tup_tup_conv <T, P>{}> = 0>
INLINE constexpr collection(T&& t) : B(fwd <T>(t)) { }
template <typename T, only_if <tup_tup_explicit <P, T>{}> = 0>
explicit INLINE constexpr collection(T&& t) : B(fwd <T>(t)) { }
};
//-----------------------------------------------------------------------------
} // namespace details
//-----------------------------------------------------------------------------
} // namespace tuples
//-----------------------------------------------------------------------------
} // namespace ivl
//-----------------------------------------------------------------------------
#endif // IVL_CORE_TUPLE_STORE_TUPLE_HPP