tomoto 0.6.0 → 0.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/LICENSE.txt +1 -1
- data/ext/tomoto/ct.cpp +1 -1
- data/ext/tomoto/dmr.cpp +1 -1
- data/ext/tomoto/dt.cpp +1 -1
- data/ext/tomoto/extconf.rb +4 -8
- data/ext/tomoto/gdmr.cpp +1 -1
- data/ext/tomoto/hdp.cpp +1 -1
- data/ext/tomoto/hlda.cpp +1 -1
- data/ext/tomoto/hpa.cpp +1 -1
- data/ext/tomoto/lda.cpp +29 -3
- data/ext/tomoto/llda.cpp +1 -1
- data/ext/tomoto/mglda.cpp +1 -1
- data/ext/tomoto/pa.cpp +1 -1
- data/ext/tomoto/plda.cpp +1 -1
- data/ext/tomoto/slda.cpp +1 -1
- data/lib/tomoto/lda.rb +1 -0
- data/lib/tomoto/version.rb +1 -1
- data/vendor/EigenRand/EigenRand/Core.h +6 -4
- data/vendor/EigenRand/EigenRand/CwiseHeteroBinaryOp.h +265 -0
- data/vendor/EigenRand/EigenRand/Dists/Basic.h +345 -12
- data/vendor/EigenRand/EigenRand/Dists/Discrete.h +381 -7
- data/vendor/EigenRand/EigenRand/Dists/GammaPoisson.h +4 -4
- data/vendor/EigenRand/EigenRand/Dists/NormalExp.h +576 -4
- data/vendor/EigenRand/EigenRand/EigenRand +4 -4
- data/vendor/EigenRand/EigenRand/Macro.h +3 -3
- data/vendor/EigenRand/EigenRand/MorePacketMath.h +31 -30
- data/vendor/EigenRand/EigenRand/MvDists/Multinomial.h +41 -29
- data/vendor/EigenRand/EigenRand/MvDists/MvNormal.h +19 -7
- data/vendor/EigenRand/EigenRand/PacketFilter.h +8 -5
- data/vendor/EigenRand/EigenRand/PacketRandomEngine.h +3 -3
- data/vendor/EigenRand/EigenRand/RandUtils.h +180 -5
- data/vendor/EigenRand/EigenRand/arch/AVX/MorePacketMath.h +42 -3
- data/vendor/EigenRand/EigenRand/arch/AVX/PacketFilter.h +3 -3
- data/vendor/EigenRand/EigenRand/arch/AVX/RandUtils.h +3 -3
- data/vendor/EigenRand/EigenRand/arch/AVX512/MorePacketMath.h +312 -0
- data/vendor/EigenRand/EigenRand/arch/AVX512/PacketFilter.h +79 -0
- data/vendor/EigenRand/EigenRand/arch/AVX512/RandUtils.h +147 -0
- data/vendor/EigenRand/EigenRand/arch/NEON/MorePacketMath.h +118 -3
- data/vendor/EigenRand/EigenRand/arch/NEON/PacketFilter.h +3 -3
- data/vendor/EigenRand/EigenRand/arch/NEON/RandUtils.h +21 -3
- data/vendor/EigenRand/EigenRand/arch/SSE/MorePacketMath.h +32 -4
- data/vendor/EigenRand/EigenRand/arch/SSE/PacketFilter.h +3 -3
- data/vendor/EigenRand/EigenRand/arch/SSE/RandUtils.h +3 -3
- data/vendor/EigenRand/EigenRand/doc.h +108 -157
- data/vendor/EigenRand/README.md +60 -272
- data/vendor/tomotopy/README.kr.rst +27 -5
- data/vendor/tomotopy/README.rst +27 -5
- data/vendor/tomotopy/README_pypi.rst +583 -0
- data/vendor/tomotopy/licenses_bundled/EigenRand +21 -0
- data/vendor/tomotopy/src/TopicModel/CT.h +1 -1
- data/vendor/tomotopy/src/TopicModel/CTModel.cpp +1 -1
- data/vendor/tomotopy/src/TopicModel/DMR.h +1 -1
- data/vendor/tomotopy/src/TopicModel/DMRModel.cpp +1 -1
- data/vendor/tomotopy/src/TopicModel/DT.h +1 -1
- data/vendor/tomotopy/src/TopicModel/DTModel.cpp +1 -1
- data/vendor/tomotopy/src/TopicModel/GDMR.h +1 -1
- data/vendor/tomotopy/src/TopicModel/GDMRModel.cpp +1 -1
- data/vendor/tomotopy/src/TopicModel/HDP.h +1 -1
- data/vendor/tomotopy/src/TopicModel/HDPModel.cpp +1 -1
- data/vendor/tomotopy/src/TopicModel/HLDA.h +1 -1
- data/vendor/tomotopy/src/TopicModel/HLDAModel.cpp +1 -1
- data/vendor/tomotopy/src/TopicModel/HPA.h +1 -1
- data/vendor/tomotopy/src/TopicModel/HPAModel.cpp +1 -1
- data/vendor/tomotopy/src/TopicModel/LDA.h +1 -1
- data/vendor/tomotopy/src/TopicModel/LDAModel.cpp +1 -1
- data/vendor/tomotopy/src/TopicModel/LDAModel.hpp +6 -6
- data/vendor/tomotopy/src/TopicModel/LLDA.h +1 -1
- data/vendor/tomotopy/src/TopicModel/LLDAModel.cpp +1 -1
- data/vendor/tomotopy/src/TopicModel/MGLDA.h +1 -1
- data/vendor/tomotopy/src/TopicModel/MGLDAModel.cpp +1 -1
- data/vendor/tomotopy/src/TopicModel/PA.h +1 -1
- data/vendor/tomotopy/src/TopicModel/PAModel.cpp +1 -1
- data/vendor/tomotopy/src/TopicModel/PLDA.h +1 -1
- data/vendor/tomotopy/src/TopicModel/PLDAModel.cpp +1 -1
- data/vendor/tomotopy/src/TopicModel/PT.h +1 -1
- data/vendor/tomotopy/src/TopicModel/PTModel.cpp +1 -1
- data/vendor/tomotopy/src/TopicModel/SLDA.h +1 -1
- data/vendor/tomotopy/src/TopicModel/SLDAModel.cpp +1 -1
- data/vendor/tomotopy/src/TopicModel/TopicModel.hpp +6 -6
- data/vendor/tomotopy/src/Utils/EigenAddonOps.hpp +41 -0
- data/vendor/tomotopy/src/Utils/ThreadPool.hpp +6 -6
- data/vendor/tomotopy/src/Utils/Utils.hpp +3 -3
- data/vendor/tomotopy/src/Utils/avx512_gamma.h +46 -0
- data/vendor/tomotopy/src/Utils/avx512_mathfun.h +99 -0
- metadata +10 -9
- data/vendor/variant/LICENSE +0 -25
- data/vendor/variant/LICENSE_1_0.txt +0 -23
- data/vendor/variant/README.md +0 -102
- data/vendor/variant/include/mapbox/optional.hpp +0 -74
- data/vendor/variant/include/mapbox/recursive_wrapper.hpp +0 -122
- data/vendor/variant/include/mapbox/variant.hpp +0 -974
- data/vendor/variant/include/mapbox/variant_io.hpp +0 -45
|
@@ -1,974 +0,0 @@
|
|
|
1
|
-
#ifndef MAPBOX_UTIL_VARIANT_HPP
|
|
2
|
-
#define MAPBOX_UTIL_VARIANT_HPP
|
|
3
|
-
|
|
4
|
-
#include <cassert>
|
|
5
|
-
#include <cstddef> // size_t
|
|
6
|
-
#include <new> // operator new
|
|
7
|
-
#include <stdexcept> // runtime_error
|
|
8
|
-
#include <string>
|
|
9
|
-
#include <tuple>
|
|
10
|
-
#include <type_traits>
|
|
11
|
-
#include <typeinfo>
|
|
12
|
-
#include <utility>
|
|
13
|
-
|
|
14
|
-
#include <mapbox/recursive_wrapper.hpp>
|
|
15
|
-
|
|
16
|
-
// clang-format off
|
|
17
|
-
// [[deprecated]] is only available in C++14, use this for the time being
|
|
18
|
-
#if __cplusplus <= 201103L
|
|
19
|
-
# ifdef __GNUC__
|
|
20
|
-
# define MAPBOX_VARIANT_DEPRECATED __attribute__((deprecated))
|
|
21
|
-
# elif defined(_MSC_VER)
|
|
22
|
-
# define MAPBOX_VARIANT_DEPRECATED __declspec(deprecated)
|
|
23
|
-
# else
|
|
24
|
-
# define MAPBOX_VARIANT_DEPRECATED
|
|
25
|
-
# endif
|
|
26
|
-
#else
|
|
27
|
-
# define MAPBOX_VARIANT_DEPRECATED [[deprecated]]
|
|
28
|
-
#endif
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
#ifdef _MSC_VER
|
|
32
|
-
// https://msdn.microsoft.com/en-us/library/bw1hbe6y.aspx
|
|
33
|
-
# ifdef NDEBUG
|
|
34
|
-
# define VARIANT_INLINE __forceinline
|
|
35
|
-
# else
|
|
36
|
-
# define VARIANT_INLINE //__declspec(noinline)
|
|
37
|
-
# endif
|
|
38
|
-
#else
|
|
39
|
-
# ifdef NDEBUG
|
|
40
|
-
# define VARIANT_INLINE //inline __attribute__((always_inline))
|
|
41
|
-
# else
|
|
42
|
-
# define VARIANT_INLINE __attribute__((noinline))
|
|
43
|
-
# endif
|
|
44
|
-
#endif
|
|
45
|
-
// clang-format on
|
|
46
|
-
|
|
47
|
-
// Exceptions
|
|
48
|
-
#if defined( __EXCEPTIONS) || defined( _MSC_VER)
|
|
49
|
-
#define HAS_EXCEPTIONS
|
|
50
|
-
#endif
|
|
51
|
-
|
|
52
|
-
#define VARIANT_MAJOR_VERSION 1
|
|
53
|
-
#define VARIANT_MINOR_VERSION 1
|
|
54
|
-
#define VARIANT_PATCH_VERSION 0
|
|
55
|
-
|
|
56
|
-
#define VARIANT_VERSION (VARIANT_MAJOR_VERSION * 100000) + (VARIANT_MINOR_VERSION * 100) + (VARIANT_PATCH_VERSION)
|
|
57
|
-
|
|
58
|
-
namespace mapbox {
|
|
59
|
-
namespace util {
|
|
60
|
-
|
|
61
|
-
// XXX This should derive from std::logic_error instead of std::runtime_error.
|
|
62
|
-
// See https://github.com/mapbox/variant/issues/48 for details.
|
|
63
|
-
class bad_variant_access : public std::runtime_error
|
|
64
|
-
{
|
|
65
|
-
|
|
66
|
-
public:
|
|
67
|
-
explicit bad_variant_access(const std::string& what_arg)
|
|
68
|
-
: runtime_error(what_arg) {}
|
|
69
|
-
|
|
70
|
-
explicit bad_variant_access(const char* what_arg)
|
|
71
|
-
: runtime_error(what_arg) {}
|
|
72
|
-
|
|
73
|
-
}; // class bad_variant_access
|
|
74
|
-
|
|
75
|
-
template <typename R = void>
|
|
76
|
-
struct MAPBOX_VARIANT_DEPRECATED static_visitor
|
|
77
|
-
{
|
|
78
|
-
using result_type = R;
|
|
79
|
-
|
|
80
|
-
protected:
|
|
81
|
-
static_visitor() {}
|
|
82
|
-
~static_visitor() {}
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
namespace detail {
|
|
86
|
-
|
|
87
|
-
static constexpr std::size_t invalid_value = std::size_t(-1);
|
|
88
|
-
|
|
89
|
-
template <typename T, typename... Types>
|
|
90
|
-
struct direct_type;
|
|
91
|
-
|
|
92
|
-
template <typename T, typename First, typename... Types>
|
|
93
|
-
struct direct_type<T, First, Types...>
|
|
94
|
-
{
|
|
95
|
-
static constexpr std::size_t index = std::is_same<T, First>::value
|
|
96
|
-
? sizeof...(Types)
|
|
97
|
-
: direct_type<T, Types...>::index;
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
template <typename T>
|
|
101
|
-
struct direct_type<T>
|
|
102
|
-
{
|
|
103
|
-
static constexpr std::size_t index = invalid_value;
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
#if __cpp_lib_logical_traits >= 201510L
|
|
107
|
-
|
|
108
|
-
using std::disjunction;
|
|
109
|
-
|
|
110
|
-
#else
|
|
111
|
-
|
|
112
|
-
template <typename...>
|
|
113
|
-
struct disjunction : std::false_type {};
|
|
114
|
-
|
|
115
|
-
template <typename B1>
|
|
116
|
-
struct disjunction<B1> : B1 {};
|
|
117
|
-
|
|
118
|
-
template <typename B1, typename B2>
|
|
119
|
-
struct disjunction<B1, B2> : std::conditional<B1::value, B1, B2>::type {};
|
|
120
|
-
|
|
121
|
-
template <typename B1, typename... Bs>
|
|
122
|
-
struct disjunction<B1, Bs...> : std::conditional<B1::value, B1, disjunction<Bs...>>::type {};
|
|
123
|
-
|
|
124
|
-
#endif
|
|
125
|
-
|
|
126
|
-
template <typename T, typename... Types>
|
|
127
|
-
struct convertible_type;
|
|
128
|
-
|
|
129
|
-
template <typename T, typename First, typename... Types>
|
|
130
|
-
struct convertible_type<T, First, Types...>
|
|
131
|
-
{
|
|
132
|
-
static constexpr std::size_t index = std::is_convertible<T, First>::value
|
|
133
|
-
? disjunction<std::is_convertible<T, Types>...>::value ? invalid_value : sizeof...(Types)
|
|
134
|
-
: convertible_type<T, Types...>::index;
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
template <typename T>
|
|
138
|
-
struct convertible_type<T>
|
|
139
|
-
{
|
|
140
|
-
static constexpr std::size_t index = invalid_value;
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
template <typename T, typename... Types>
|
|
144
|
-
struct value_traits
|
|
145
|
-
{
|
|
146
|
-
using value_type = typename std::remove_const<typename std::remove_reference<T>::type>::type;
|
|
147
|
-
static constexpr std::size_t direct_index = direct_type<value_type, Types...>::index;
|
|
148
|
-
static constexpr bool is_direct = direct_index != invalid_value;
|
|
149
|
-
static constexpr std::size_t index = is_direct ? direct_index : convertible_type<value_type, Types...>::index;
|
|
150
|
-
static constexpr bool is_valid = index != invalid_value;
|
|
151
|
-
static constexpr std::size_t tindex = is_valid ? sizeof...(Types)-index : 0;
|
|
152
|
-
using target_type = typename std::tuple_element<tindex, std::tuple<void, Types...>>::type;
|
|
153
|
-
};
|
|
154
|
-
|
|
155
|
-
template <typename T, typename R = void>
|
|
156
|
-
struct enable_if_type
|
|
157
|
-
{
|
|
158
|
-
using type = R;
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
template <typename F, typename V, typename Enable = void>
|
|
162
|
-
struct result_of_unary_visit
|
|
163
|
-
{
|
|
164
|
-
using type = typename std::result_of<F(V&)>::type;
|
|
165
|
-
};
|
|
166
|
-
|
|
167
|
-
template <typename F, typename V>
|
|
168
|
-
struct result_of_unary_visit<F, V, typename enable_if_type<typename F::result_type>::type>
|
|
169
|
-
{
|
|
170
|
-
using type = typename F::result_type;
|
|
171
|
-
};
|
|
172
|
-
|
|
173
|
-
template <typename F, typename V, typename Enable = void>
|
|
174
|
-
struct result_of_binary_visit
|
|
175
|
-
{
|
|
176
|
-
using type = typename std::result_of<F(V&, V&)>::type;
|
|
177
|
-
};
|
|
178
|
-
|
|
179
|
-
template <typename F, typename V>
|
|
180
|
-
struct result_of_binary_visit<F, V, typename enable_if_type<typename F::result_type>::type>
|
|
181
|
-
{
|
|
182
|
-
using type = typename F::result_type;
|
|
183
|
-
};
|
|
184
|
-
|
|
185
|
-
template <std::size_t arg1, std::size_t... others>
|
|
186
|
-
struct static_max;
|
|
187
|
-
|
|
188
|
-
template <std::size_t arg>
|
|
189
|
-
struct static_max<arg>
|
|
190
|
-
{
|
|
191
|
-
static const std::size_t value = arg;
|
|
192
|
-
};
|
|
193
|
-
|
|
194
|
-
template <std::size_t arg1, std::size_t arg2, std::size_t... others>
|
|
195
|
-
struct static_max<arg1, arg2, others...>
|
|
196
|
-
{
|
|
197
|
-
static const std::size_t value = arg1 >= arg2 ? static_max<arg1, others...>::value : static_max<arg2, others...>::value;
|
|
198
|
-
};
|
|
199
|
-
|
|
200
|
-
template <typename... Types>
|
|
201
|
-
struct variant_helper;
|
|
202
|
-
|
|
203
|
-
template <typename T, typename... Types>
|
|
204
|
-
struct variant_helper<T, Types...>
|
|
205
|
-
{
|
|
206
|
-
VARIANT_INLINE static void destroy(const std::size_t type_index, void* data)
|
|
207
|
-
{
|
|
208
|
-
if (type_index == sizeof...(Types))
|
|
209
|
-
{
|
|
210
|
-
reinterpret_cast<T*>(data)->~T();
|
|
211
|
-
}
|
|
212
|
-
else
|
|
213
|
-
{
|
|
214
|
-
variant_helper<Types...>::destroy(type_index, data);
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
VARIANT_INLINE static void move(const std::size_t old_type_index, void* old_value, void* new_value)
|
|
219
|
-
{
|
|
220
|
-
if (old_type_index == sizeof...(Types))
|
|
221
|
-
{
|
|
222
|
-
new (new_value) T(std::move(*reinterpret_cast<T*>(old_value)));
|
|
223
|
-
}
|
|
224
|
-
else
|
|
225
|
-
{
|
|
226
|
-
variant_helper<Types...>::move(old_type_index, old_value, new_value);
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
VARIANT_INLINE static void copy(const std::size_t old_type_index, const void* old_value, void* new_value)
|
|
231
|
-
{
|
|
232
|
-
if (old_type_index == sizeof...(Types))
|
|
233
|
-
{
|
|
234
|
-
new (new_value) T(*reinterpret_cast<const T*>(old_value));
|
|
235
|
-
}
|
|
236
|
-
else
|
|
237
|
-
{
|
|
238
|
-
variant_helper<Types...>::copy(old_type_index, old_value, new_value);
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
};
|
|
242
|
-
|
|
243
|
-
template <>
|
|
244
|
-
struct variant_helper<>
|
|
245
|
-
{
|
|
246
|
-
VARIANT_INLINE static void destroy(const std::size_t, void*) {}
|
|
247
|
-
VARIANT_INLINE static void move(const std::size_t, void*, void*) {}
|
|
248
|
-
VARIANT_INLINE static void copy(const std::size_t, const void*, void*) {}
|
|
249
|
-
};
|
|
250
|
-
|
|
251
|
-
template <typename T>
|
|
252
|
-
struct unwrapper
|
|
253
|
-
{
|
|
254
|
-
static T const& apply_const(T const& obj) { return obj; }
|
|
255
|
-
static T& apply(T& obj) { return obj; }
|
|
256
|
-
};
|
|
257
|
-
|
|
258
|
-
template <typename T>
|
|
259
|
-
struct unwrapper<recursive_wrapper<T>>
|
|
260
|
-
{
|
|
261
|
-
static auto apply_const(recursive_wrapper<T> const& obj)
|
|
262
|
-
-> typename recursive_wrapper<T>::type const&
|
|
263
|
-
{
|
|
264
|
-
return obj.get();
|
|
265
|
-
}
|
|
266
|
-
static auto apply(recursive_wrapper<T>& obj)
|
|
267
|
-
-> typename recursive_wrapper<T>::type&
|
|
268
|
-
{
|
|
269
|
-
return obj.get();
|
|
270
|
-
}
|
|
271
|
-
};
|
|
272
|
-
|
|
273
|
-
template <typename T>
|
|
274
|
-
struct unwrapper<std::reference_wrapper<T>>
|
|
275
|
-
{
|
|
276
|
-
static auto apply_const(std::reference_wrapper<T> const& obj)
|
|
277
|
-
-> typename std::reference_wrapper<T>::type const&
|
|
278
|
-
{
|
|
279
|
-
return obj.get();
|
|
280
|
-
}
|
|
281
|
-
static auto apply(std::reference_wrapper<T>& obj)
|
|
282
|
-
-> typename std::reference_wrapper<T>::type&
|
|
283
|
-
{
|
|
284
|
-
return obj.get();
|
|
285
|
-
}
|
|
286
|
-
};
|
|
287
|
-
|
|
288
|
-
template <typename F, typename V, typename R, typename... Types>
|
|
289
|
-
struct dispatcher;
|
|
290
|
-
|
|
291
|
-
template <typename F, typename V, typename R, typename T, typename... Types>
|
|
292
|
-
struct dispatcher<F, V, R, T, Types...>
|
|
293
|
-
{
|
|
294
|
-
VARIANT_INLINE static R apply_const(V const& v, F&& f)
|
|
295
|
-
{
|
|
296
|
-
if (v.template is<T>())
|
|
297
|
-
{
|
|
298
|
-
return f(unwrapper<T>::apply_const(v.template get_unchecked<T>()));
|
|
299
|
-
}
|
|
300
|
-
else
|
|
301
|
-
{
|
|
302
|
-
return dispatcher<F, V, R, Types...>::apply_const(v, std::forward<F>(f));
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
VARIANT_INLINE static R apply(V& v, F&& f)
|
|
307
|
-
{
|
|
308
|
-
if (v.template is<T>())
|
|
309
|
-
{
|
|
310
|
-
return f(unwrapper<T>::apply(v.template get_unchecked<T>()));
|
|
311
|
-
}
|
|
312
|
-
else
|
|
313
|
-
{
|
|
314
|
-
return dispatcher<F, V, R, Types...>::apply(v, std::forward<F>(f));
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
};
|
|
318
|
-
|
|
319
|
-
template <typename F, typename V, typename R, typename T>
|
|
320
|
-
struct dispatcher<F, V, R, T>
|
|
321
|
-
{
|
|
322
|
-
VARIANT_INLINE static R apply_const(V const& v, F&& f)
|
|
323
|
-
{
|
|
324
|
-
return f(unwrapper<T>::apply_const(v.template get_unchecked<T>()));
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
VARIANT_INLINE static R apply(V& v, F&& f)
|
|
328
|
-
{
|
|
329
|
-
return f(unwrapper<T>::apply(v.template get_unchecked<T>()));
|
|
330
|
-
}
|
|
331
|
-
};
|
|
332
|
-
|
|
333
|
-
template <typename F, typename V, typename R, typename T, typename... Types>
|
|
334
|
-
struct binary_dispatcher_rhs;
|
|
335
|
-
|
|
336
|
-
template <typename F, typename V, typename R, typename T0, typename T1, typename... Types>
|
|
337
|
-
struct binary_dispatcher_rhs<F, V, R, T0, T1, Types...>
|
|
338
|
-
{
|
|
339
|
-
VARIANT_INLINE static R apply_const(V const& lhs, V const& rhs, F&& f)
|
|
340
|
-
{
|
|
341
|
-
if (rhs.template is<T1>()) // call binary functor
|
|
342
|
-
{
|
|
343
|
-
return f(unwrapper<T0>::apply_const(lhs.template get_unchecked<T0>()),
|
|
344
|
-
unwrapper<T1>::apply_const(rhs.template get_unchecked<T1>()));
|
|
345
|
-
}
|
|
346
|
-
else
|
|
347
|
-
{
|
|
348
|
-
return binary_dispatcher_rhs<F, V, R, T0, Types...>::apply_const(lhs, rhs, std::forward<F>(f));
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
VARIANT_INLINE static R apply(V& lhs, V& rhs, F&& f)
|
|
353
|
-
{
|
|
354
|
-
if (rhs.template is<T1>()) // call binary functor
|
|
355
|
-
{
|
|
356
|
-
return f(unwrapper<T0>::apply(lhs.template get_unchecked<T0>()),
|
|
357
|
-
unwrapper<T1>::apply(rhs.template get_unchecked<T1>()));
|
|
358
|
-
}
|
|
359
|
-
else
|
|
360
|
-
{
|
|
361
|
-
return binary_dispatcher_rhs<F, V, R, T0, Types...>::apply(lhs, rhs, std::forward<F>(f));
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
};
|
|
365
|
-
|
|
366
|
-
template <typename F, typename V, typename R, typename T0, typename T1>
|
|
367
|
-
struct binary_dispatcher_rhs<F, V, R, T0, T1>
|
|
368
|
-
{
|
|
369
|
-
VARIANT_INLINE static R apply_const(V const& lhs, V const& rhs, F&& f)
|
|
370
|
-
{
|
|
371
|
-
return f(unwrapper<T0>::apply_const(lhs.template get_unchecked<T0>()),
|
|
372
|
-
unwrapper<T1>::apply_const(rhs.template get_unchecked<T1>()));
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
VARIANT_INLINE static R apply(V& lhs, V& rhs, F&& f)
|
|
376
|
-
{
|
|
377
|
-
return f(unwrapper<T0>::apply(lhs.template get_unchecked<T0>()),
|
|
378
|
-
unwrapper<T1>::apply(rhs.template get_unchecked<T1>()));
|
|
379
|
-
}
|
|
380
|
-
};
|
|
381
|
-
|
|
382
|
-
template <typename F, typename V, typename R, typename T, typename... Types>
|
|
383
|
-
struct binary_dispatcher_lhs;
|
|
384
|
-
|
|
385
|
-
template <typename F, typename V, typename R, typename T0, typename T1, typename... Types>
|
|
386
|
-
struct binary_dispatcher_lhs<F, V, R, T0, T1, Types...>
|
|
387
|
-
{
|
|
388
|
-
VARIANT_INLINE static R apply_const(V const& lhs, V const& rhs, F&& f)
|
|
389
|
-
{
|
|
390
|
-
if (lhs.template is<T1>()) // call binary functor
|
|
391
|
-
{
|
|
392
|
-
return f(unwrapper<T1>::apply_const(lhs.template get_unchecked<T1>()),
|
|
393
|
-
unwrapper<T0>::apply_const(rhs.template get_unchecked<T0>()));
|
|
394
|
-
}
|
|
395
|
-
else
|
|
396
|
-
{
|
|
397
|
-
return binary_dispatcher_lhs<F, V, R, T0, Types...>::apply_const(lhs, rhs, std::forward<F>(f));
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
VARIANT_INLINE static R apply(V& lhs, V& rhs, F&& f)
|
|
402
|
-
{
|
|
403
|
-
if (lhs.template is<T1>()) // call binary functor
|
|
404
|
-
{
|
|
405
|
-
return f(unwrapper<T1>::apply(lhs.template get_unchecked<T1>()),
|
|
406
|
-
unwrapper<T0>::apply(rhs.template get_unchecked<T0>()));
|
|
407
|
-
}
|
|
408
|
-
else
|
|
409
|
-
{
|
|
410
|
-
return binary_dispatcher_lhs<F, V, R, T0, Types...>::apply(lhs, rhs, std::forward<F>(f));
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
};
|
|
414
|
-
|
|
415
|
-
template <typename F, typename V, typename R, typename T0, typename T1>
|
|
416
|
-
struct binary_dispatcher_lhs<F, V, R, T0, T1>
|
|
417
|
-
{
|
|
418
|
-
VARIANT_INLINE static R apply_const(V const& lhs, V const& rhs, F&& f)
|
|
419
|
-
{
|
|
420
|
-
return f(unwrapper<T1>::apply_const(lhs.template get_unchecked<T1>()),
|
|
421
|
-
unwrapper<T0>::apply_const(rhs.template get_unchecked<T0>()));
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
VARIANT_INLINE static R apply(V& lhs, V& rhs, F&& f)
|
|
425
|
-
{
|
|
426
|
-
return f(unwrapper<T1>::apply(lhs.template get_unchecked<T1>()),
|
|
427
|
-
unwrapper<T0>::apply(rhs.template get_unchecked<T0>()));
|
|
428
|
-
}
|
|
429
|
-
};
|
|
430
|
-
|
|
431
|
-
template <typename F, typename V, typename R, typename... Types>
|
|
432
|
-
struct binary_dispatcher;
|
|
433
|
-
|
|
434
|
-
template <typename F, typename V, typename R, typename T, typename... Types>
|
|
435
|
-
struct binary_dispatcher<F, V, R, T, Types...>
|
|
436
|
-
{
|
|
437
|
-
VARIANT_INLINE static R apply_const(V const& v0, V const& v1, F&& f)
|
|
438
|
-
{
|
|
439
|
-
if (v0.template is<T>())
|
|
440
|
-
{
|
|
441
|
-
if (v1.template is<T>())
|
|
442
|
-
{
|
|
443
|
-
return f(unwrapper<T>::apply_const(v0.template get_unchecked<T>()),
|
|
444
|
-
unwrapper<T>::apply_const(v1.template get_unchecked<T>())); // call binary functor
|
|
445
|
-
}
|
|
446
|
-
else
|
|
447
|
-
{
|
|
448
|
-
return binary_dispatcher_rhs<F, V, R, T, Types...>::apply_const(v0, v1, std::forward<F>(f));
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
else if (v1.template is<T>())
|
|
452
|
-
{
|
|
453
|
-
return binary_dispatcher_lhs<F, V, R, T, Types...>::apply_const(v0, v1, std::forward<F>(f));
|
|
454
|
-
}
|
|
455
|
-
return binary_dispatcher<F, V, R, Types...>::apply_const(v0, v1, std::forward<F>(f));
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
VARIANT_INLINE static R apply(V& v0, V& v1, F&& f)
|
|
459
|
-
{
|
|
460
|
-
if (v0.template is<T>())
|
|
461
|
-
{
|
|
462
|
-
if (v1.template is<T>())
|
|
463
|
-
{
|
|
464
|
-
return f(unwrapper<T>::apply(v0.template get_unchecked<T>()),
|
|
465
|
-
unwrapper<T>::apply(v1.template get_unchecked<T>())); // call binary functor
|
|
466
|
-
}
|
|
467
|
-
else
|
|
468
|
-
{
|
|
469
|
-
return binary_dispatcher_rhs<F, V, R, T, Types...>::apply(v0, v1, std::forward<F>(f));
|
|
470
|
-
}
|
|
471
|
-
}
|
|
472
|
-
else if (v1.template is<T>())
|
|
473
|
-
{
|
|
474
|
-
return binary_dispatcher_lhs<F, V, R, T, Types...>::apply(v0, v1, std::forward<F>(f));
|
|
475
|
-
}
|
|
476
|
-
return binary_dispatcher<F, V, R, Types...>::apply(v0, v1, std::forward<F>(f));
|
|
477
|
-
}
|
|
478
|
-
};
|
|
479
|
-
|
|
480
|
-
template <typename F, typename V, typename R, typename T>
|
|
481
|
-
struct binary_dispatcher<F, V, R, T>
|
|
482
|
-
{
|
|
483
|
-
VARIANT_INLINE static R apply_const(V const& v0, V const& v1, F&& f)
|
|
484
|
-
{
|
|
485
|
-
return f(unwrapper<T>::apply_const(v0.template get_unchecked<T>()),
|
|
486
|
-
unwrapper<T>::apply_const(v1.template get_unchecked<T>())); // call binary functor
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
VARIANT_INLINE static R apply(V& v0, V& v1, F&& f)
|
|
490
|
-
{
|
|
491
|
-
return f(unwrapper<T>::apply(v0.template get_unchecked<T>()),
|
|
492
|
-
unwrapper<T>::apply(v1.template get_unchecked<T>())); // call binary functor
|
|
493
|
-
}
|
|
494
|
-
};
|
|
495
|
-
|
|
496
|
-
// comparator functors
|
|
497
|
-
struct equal_comp
|
|
498
|
-
{
|
|
499
|
-
template <typename T>
|
|
500
|
-
bool operator()(T const& lhs, T const& rhs) const
|
|
501
|
-
{
|
|
502
|
-
return lhs == rhs;
|
|
503
|
-
}
|
|
504
|
-
};
|
|
505
|
-
|
|
506
|
-
struct less_comp
|
|
507
|
-
{
|
|
508
|
-
template <typename T>
|
|
509
|
-
bool operator()(T const& lhs, T const& rhs) const
|
|
510
|
-
{
|
|
511
|
-
return lhs < rhs;
|
|
512
|
-
}
|
|
513
|
-
};
|
|
514
|
-
|
|
515
|
-
template <typename Variant, typename Comp>
|
|
516
|
-
class comparer
|
|
517
|
-
{
|
|
518
|
-
public:
|
|
519
|
-
explicit comparer(Variant const& lhs) noexcept
|
|
520
|
-
: lhs_(lhs) {}
|
|
521
|
-
comparer& operator=(comparer const&) = delete;
|
|
522
|
-
// visitor
|
|
523
|
-
template <typename T>
|
|
524
|
-
bool operator()(T const& rhs_content) const
|
|
525
|
-
{
|
|
526
|
-
T const& lhs_content = lhs_.template get_unchecked<T>();
|
|
527
|
-
return Comp()(lhs_content, rhs_content);
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
private:
|
|
531
|
-
Variant const& lhs_;
|
|
532
|
-
};
|
|
533
|
-
|
|
534
|
-
} // namespace detail
|
|
535
|
-
|
|
536
|
-
struct no_init
|
|
537
|
-
{
|
|
538
|
-
};
|
|
539
|
-
|
|
540
|
-
template <typename... Types>
|
|
541
|
-
class variant
|
|
542
|
-
{
|
|
543
|
-
static_assert(sizeof...(Types) > 0, "Template parameter type list of variant can not be empty");
|
|
544
|
-
static_assert(!detail::disjunction<std::is_reference<Types>...>::value, "Variant can not hold reference types. Maybe use std::reference_wrapper?");
|
|
545
|
-
|
|
546
|
-
private:
|
|
547
|
-
static const std::size_t data_size = detail::static_max<sizeof(Types)...>::value;
|
|
548
|
-
static const std::size_t data_align = detail::static_max<alignof(Types)...>::value;
|
|
549
|
-
public:
|
|
550
|
-
struct adapted_variant_tag;
|
|
551
|
-
using types = std::tuple<Types...>;
|
|
552
|
-
private:
|
|
553
|
-
using first_type = typename std::tuple_element<0, types>::type;
|
|
554
|
-
using data_type = typename std::aligned_storage<data_size, data_align>::type;
|
|
555
|
-
using helper_type = detail::variant_helper<Types...>;
|
|
556
|
-
|
|
557
|
-
std::size_t type_index;
|
|
558
|
-
data_type data;
|
|
559
|
-
|
|
560
|
-
public:
|
|
561
|
-
VARIANT_INLINE variant() noexcept(std::is_nothrow_default_constructible<first_type>::value)
|
|
562
|
-
: type_index(sizeof...(Types)-1)
|
|
563
|
-
{
|
|
564
|
-
static_assert(std::is_default_constructible<first_type>::value, "First type in variant must be default constructible to allow default construction of variant");
|
|
565
|
-
new (&data) first_type();
|
|
566
|
-
}
|
|
567
|
-
|
|
568
|
-
VARIANT_INLINE variant(no_init) noexcept
|
|
569
|
-
: type_index(detail::invalid_value) {}
|
|
570
|
-
|
|
571
|
-
// http://isocpp.org/blog/2012/11/universal-references-in-c11-scott-meyers
|
|
572
|
-
template <typename T, typename Traits = detail::value_traits<T, Types...>,
|
|
573
|
-
typename Enable = typename std::enable_if<Traits::is_valid && !std::is_same<variant<Types...>, typename Traits::value_type>::value>::type >
|
|
574
|
-
VARIANT_INLINE variant(T&& val) noexcept(std::is_nothrow_constructible<typename Traits::target_type, T&&>::value)
|
|
575
|
-
: type_index(Traits::index)
|
|
576
|
-
{
|
|
577
|
-
new (&data) typename Traits::target_type(std::forward<T>(val));
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
VARIANT_INLINE variant(variant<Types...> const& old)
|
|
581
|
-
: type_index(old.type_index)
|
|
582
|
-
{
|
|
583
|
-
helper_type::copy(old.type_index, &old.data, &data);
|
|
584
|
-
}
|
|
585
|
-
|
|
586
|
-
VARIANT_INLINE variant(variant<Types...>&& old) noexcept(std::is_nothrow_move_constructible<types>::value)
|
|
587
|
-
: type_index(old.type_index)
|
|
588
|
-
{
|
|
589
|
-
helper_type::move(old.type_index, &old.data, &data);
|
|
590
|
-
}
|
|
591
|
-
|
|
592
|
-
private:
|
|
593
|
-
VARIANT_INLINE void copy_assign(variant<Types...> const& rhs)
|
|
594
|
-
{
|
|
595
|
-
helper_type::destroy(type_index, &data);
|
|
596
|
-
type_index = detail::invalid_value;
|
|
597
|
-
helper_type::copy(rhs.type_index, &rhs.data, &data);
|
|
598
|
-
type_index = rhs.type_index;
|
|
599
|
-
}
|
|
600
|
-
|
|
601
|
-
VARIANT_INLINE void move_assign(variant<Types...>&& rhs)
|
|
602
|
-
{
|
|
603
|
-
helper_type::destroy(type_index, &data);
|
|
604
|
-
type_index = detail::invalid_value;
|
|
605
|
-
helper_type::move(rhs.type_index, &rhs.data, &data);
|
|
606
|
-
type_index = rhs.type_index;
|
|
607
|
-
}
|
|
608
|
-
|
|
609
|
-
public:
|
|
610
|
-
VARIANT_INLINE variant<Types...>& operator=(variant<Types...>&& other)
|
|
611
|
-
{
|
|
612
|
-
move_assign(std::move(other));
|
|
613
|
-
return *this;
|
|
614
|
-
}
|
|
615
|
-
|
|
616
|
-
VARIANT_INLINE variant<Types...>& operator=(variant<Types...> const& other)
|
|
617
|
-
{
|
|
618
|
-
copy_assign(other);
|
|
619
|
-
return *this;
|
|
620
|
-
}
|
|
621
|
-
|
|
622
|
-
// conversions
|
|
623
|
-
// move-assign
|
|
624
|
-
template <typename T>
|
|
625
|
-
VARIANT_INLINE variant<Types...>& operator=(T&& rhs) noexcept
|
|
626
|
-
{
|
|
627
|
-
variant<Types...> temp(std::forward<T>(rhs));
|
|
628
|
-
move_assign(std::move(temp));
|
|
629
|
-
return *this;
|
|
630
|
-
}
|
|
631
|
-
|
|
632
|
-
// copy-assign
|
|
633
|
-
template <typename T>
|
|
634
|
-
VARIANT_INLINE variant<Types...>& operator=(T const& rhs)
|
|
635
|
-
{
|
|
636
|
-
variant<Types...> temp(rhs);
|
|
637
|
-
copy_assign(temp);
|
|
638
|
-
return *this;
|
|
639
|
-
}
|
|
640
|
-
|
|
641
|
-
template <typename T, typename std::enable_if<
|
|
642
|
-
(detail::direct_type<T, Types...>::index != detail::invalid_value)>::type* = nullptr>
|
|
643
|
-
VARIANT_INLINE bool is() const
|
|
644
|
-
{
|
|
645
|
-
return type_index == detail::direct_type<T, Types...>::index;
|
|
646
|
-
}
|
|
647
|
-
|
|
648
|
-
template <typename T,typename std::enable_if<
|
|
649
|
-
(detail::direct_type<recursive_wrapper<T>, Types...>::index != detail::invalid_value)>::type* = nullptr>
|
|
650
|
-
VARIANT_INLINE bool is() const
|
|
651
|
-
{
|
|
652
|
-
return type_index == detail::direct_type<recursive_wrapper<T>, Types...>::index;
|
|
653
|
-
}
|
|
654
|
-
|
|
655
|
-
VARIANT_INLINE bool valid() const
|
|
656
|
-
{
|
|
657
|
-
return type_index != detail::invalid_value;
|
|
658
|
-
}
|
|
659
|
-
|
|
660
|
-
template <typename T, typename... Args>
|
|
661
|
-
VARIANT_INLINE void set(Args&&... args)
|
|
662
|
-
{
|
|
663
|
-
helper_type::destroy(type_index, &data);
|
|
664
|
-
type_index = detail::invalid_value;
|
|
665
|
-
new (&data) T(std::forward<Args>(args)...);
|
|
666
|
-
type_index = detail::direct_type<T, Types...>::index;
|
|
667
|
-
}
|
|
668
|
-
|
|
669
|
-
// get_unchecked<T>()
|
|
670
|
-
template <typename T, typename std::enable_if<
|
|
671
|
-
(detail::direct_type<T, Types...>::index != detail::invalid_value)>::type* = nullptr>
|
|
672
|
-
VARIANT_INLINE T& get_unchecked()
|
|
673
|
-
{
|
|
674
|
-
return *reinterpret_cast<T*>(&data);
|
|
675
|
-
}
|
|
676
|
-
|
|
677
|
-
#ifdef HAS_EXCEPTIONS
|
|
678
|
-
// get<T>()
|
|
679
|
-
template <typename T, typename std::enable_if<
|
|
680
|
-
(detail::direct_type<T, Types...>::index != detail::invalid_value)>::type* = nullptr>
|
|
681
|
-
VARIANT_INLINE T& get()
|
|
682
|
-
{
|
|
683
|
-
if (type_index == detail::direct_type<T, Types...>::index)
|
|
684
|
-
{
|
|
685
|
-
return *reinterpret_cast<T*>(&data);
|
|
686
|
-
}
|
|
687
|
-
else
|
|
688
|
-
{
|
|
689
|
-
throw bad_variant_access("in get<T>()");
|
|
690
|
-
}
|
|
691
|
-
}
|
|
692
|
-
#endif
|
|
693
|
-
|
|
694
|
-
template <typename T, typename std::enable_if<
|
|
695
|
-
(detail::direct_type<T, Types...>::index != detail::invalid_value)>::type* = nullptr>
|
|
696
|
-
VARIANT_INLINE T const& get_unchecked() const
|
|
697
|
-
{
|
|
698
|
-
return *reinterpret_cast<T const*>(&data);
|
|
699
|
-
}
|
|
700
|
-
|
|
701
|
-
#ifdef HAS_EXCEPTIONS
|
|
702
|
-
template <typename T, typename std::enable_if<
|
|
703
|
-
(detail::direct_type<T, Types...>::index != detail::invalid_value)>::type* = nullptr>
|
|
704
|
-
VARIANT_INLINE T const& get() const
|
|
705
|
-
{
|
|
706
|
-
if (type_index == detail::direct_type<T, Types...>::index)
|
|
707
|
-
{
|
|
708
|
-
return *reinterpret_cast<T const*>(&data);
|
|
709
|
-
}
|
|
710
|
-
else
|
|
711
|
-
{
|
|
712
|
-
throw bad_variant_access("in get<T>()");
|
|
713
|
-
}
|
|
714
|
-
}
|
|
715
|
-
#endif
|
|
716
|
-
|
|
717
|
-
// get_unchecked<T>() - T stored as recursive_wrapper<T>
|
|
718
|
-
template <typename T, typename std::enable_if<
|
|
719
|
-
(detail::direct_type<recursive_wrapper<T>, Types...>::index != detail::invalid_value)>::type* = nullptr>
|
|
720
|
-
VARIANT_INLINE T& get_unchecked()
|
|
721
|
-
{
|
|
722
|
-
return (*reinterpret_cast<recursive_wrapper<T>*>(&data)).get();
|
|
723
|
-
}
|
|
724
|
-
|
|
725
|
-
#ifdef HAS_EXCEPTIONS
|
|
726
|
-
// get<T>() - T stored as recursive_wrapper<T>
|
|
727
|
-
template <typename T, typename std::enable_if<
|
|
728
|
-
(detail::direct_type<recursive_wrapper<T>, Types...>::index != detail::invalid_value)>::type* = nullptr>
|
|
729
|
-
VARIANT_INLINE T& get()
|
|
730
|
-
{
|
|
731
|
-
if (type_index == detail::direct_type<recursive_wrapper<T>, Types...>::index)
|
|
732
|
-
{
|
|
733
|
-
return (*reinterpret_cast<recursive_wrapper<T>*>(&data)).get();
|
|
734
|
-
}
|
|
735
|
-
else
|
|
736
|
-
{
|
|
737
|
-
throw bad_variant_access("in get<T>()");
|
|
738
|
-
}
|
|
739
|
-
}
|
|
740
|
-
#endif
|
|
741
|
-
|
|
742
|
-
template <typename T, typename std::enable_if<
|
|
743
|
-
(detail::direct_type<recursive_wrapper<T>, Types...>::index != detail::invalid_value)>::type* = nullptr>
|
|
744
|
-
VARIANT_INLINE T const& get_unchecked() const
|
|
745
|
-
{
|
|
746
|
-
return (*reinterpret_cast<recursive_wrapper<T> const*>(&data)).get();
|
|
747
|
-
}
|
|
748
|
-
|
|
749
|
-
#ifdef HAS_EXCEPTIONS
|
|
750
|
-
template <typename T, typename std::enable_if<
|
|
751
|
-
(detail::direct_type<recursive_wrapper<T>, Types...>::index != detail::invalid_value)>::type* = nullptr>
|
|
752
|
-
VARIANT_INLINE T const& get() const
|
|
753
|
-
{
|
|
754
|
-
if (type_index == detail::direct_type<recursive_wrapper<T>, Types...>::index)
|
|
755
|
-
{
|
|
756
|
-
return (*reinterpret_cast<recursive_wrapper<T> const*>(&data)).get();
|
|
757
|
-
}
|
|
758
|
-
else
|
|
759
|
-
{
|
|
760
|
-
throw bad_variant_access("in get<T>()");
|
|
761
|
-
}
|
|
762
|
-
}
|
|
763
|
-
#endif
|
|
764
|
-
|
|
765
|
-
// get_unchecked<T>() - T stored as std::reference_wrapper<T>
|
|
766
|
-
template <typename T, typename std::enable_if<
|
|
767
|
-
(detail::direct_type<std::reference_wrapper<T>, Types...>::index != detail::invalid_value)>::type* = nullptr>
|
|
768
|
-
VARIANT_INLINE T& get_unchecked()
|
|
769
|
-
{
|
|
770
|
-
return (*reinterpret_cast<std::reference_wrapper<T>*>(&data)).get();
|
|
771
|
-
}
|
|
772
|
-
|
|
773
|
-
#ifdef HAS_EXCEPTIONS
|
|
774
|
-
// get<T>() - T stored as std::reference_wrapper<T>
|
|
775
|
-
template <typename T, typename std::enable_if<
|
|
776
|
-
(detail::direct_type<std::reference_wrapper<T>, Types...>::index != detail::invalid_value)>::type* = nullptr>
|
|
777
|
-
VARIANT_INLINE T& get()
|
|
778
|
-
{
|
|
779
|
-
if (type_index == detail::direct_type<std::reference_wrapper<T>, Types...>::index)
|
|
780
|
-
{
|
|
781
|
-
return (*reinterpret_cast<std::reference_wrapper<T>*>(&data)).get();
|
|
782
|
-
}
|
|
783
|
-
else
|
|
784
|
-
{
|
|
785
|
-
throw bad_variant_access("in get<T>()");
|
|
786
|
-
}
|
|
787
|
-
}
|
|
788
|
-
#endif
|
|
789
|
-
|
|
790
|
-
template <typename T, typename std::enable_if<
|
|
791
|
-
(detail::direct_type<std::reference_wrapper<T const>, Types...>::index != detail::invalid_value)>::type* = nullptr>
|
|
792
|
-
VARIANT_INLINE T const& get_unchecked() const
|
|
793
|
-
{
|
|
794
|
-
return (*reinterpret_cast<std::reference_wrapper<T const> const*>(&data)).get();
|
|
795
|
-
}
|
|
796
|
-
|
|
797
|
-
#ifdef HAS_EXCEPTIONS
|
|
798
|
-
template <typename T, typename std::enable_if<
|
|
799
|
-
(detail::direct_type<std::reference_wrapper<T const>, Types...>::index != detail::invalid_value)>::type* = nullptr>
|
|
800
|
-
VARIANT_INLINE T const& get() const
|
|
801
|
-
{
|
|
802
|
-
if (type_index == detail::direct_type<std::reference_wrapper<T const>, Types...>::index)
|
|
803
|
-
{
|
|
804
|
-
return (*reinterpret_cast<std::reference_wrapper<T const> const*>(&data)).get();
|
|
805
|
-
}
|
|
806
|
-
else
|
|
807
|
-
{
|
|
808
|
-
throw bad_variant_access("in get<T>()");
|
|
809
|
-
}
|
|
810
|
-
}
|
|
811
|
-
#endif
|
|
812
|
-
|
|
813
|
-
// This function is deprecated because it returns an internal index field.
|
|
814
|
-
// Use which() instead.
|
|
815
|
-
MAPBOX_VARIANT_DEPRECATED VARIANT_INLINE std::size_t get_type_index() const
|
|
816
|
-
{
|
|
817
|
-
return type_index;
|
|
818
|
-
}
|
|
819
|
-
|
|
820
|
-
VARIANT_INLINE int which() const noexcept
|
|
821
|
-
{
|
|
822
|
-
return static_cast<int>(sizeof...(Types)-type_index - 1);
|
|
823
|
-
}
|
|
824
|
-
|
|
825
|
-
template <typename T, typename std::enable_if<
|
|
826
|
-
(detail::direct_type<T, Types...>::index != detail::invalid_value)>::type* = nullptr>
|
|
827
|
-
VARIANT_INLINE static constexpr int which() noexcept
|
|
828
|
-
{
|
|
829
|
-
return static_cast<int>(sizeof...(Types)-detail::direct_type<T, Types...>::index - 1);
|
|
830
|
-
}
|
|
831
|
-
|
|
832
|
-
// visitor
|
|
833
|
-
// unary
|
|
834
|
-
template <typename F, typename V, typename R = typename detail::result_of_unary_visit<F, first_type>::type>
|
|
835
|
-
auto VARIANT_INLINE static visit(V const& v, F&& f)
|
|
836
|
-
-> decltype(detail::dispatcher<F, V, R, Types...>::apply_const(v, std::forward<F>(f)))
|
|
837
|
-
{
|
|
838
|
-
return detail::dispatcher<F, V, R, Types...>::apply_const(v, std::forward<F>(f));
|
|
839
|
-
}
|
|
840
|
-
// non-const
|
|
841
|
-
template <typename F, typename V, typename R = typename detail::result_of_unary_visit<F, first_type>::type>
|
|
842
|
-
auto VARIANT_INLINE static visit(V& v, F&& f)
|
|
843
|
-
-> decltype(detail::dispatcher<F, V, R, Types...>::apply(v, std::forward<F>(f)))
|
|
844
|
-
{
|
|
845
|
-
return detail::dispatcher<F, V, R, Types...>::apply(v, std::forward<F>(f));
|
|
846
|
-
}
|
|
847
|
-
|
|
848
|
-
// binary
|
|
849
|
-
// const
|
|
850
|
-
template <typename F, typename V, typename R = typename detail::result_of_binary_visit<F, first_type>::type>
|
|
851
|
-
auto VARIANT_INLINE static binary_visit(V const& v0, V const& v1, F&& f)
|
|
852
|
-
-> decltype(detail::binary_dispatcher<F, V, R, Types...>::apply_const(v0, v1, std::forward<F>(f)))
|
|
853
|
-
{
|
|
854
|
-
return detail::binary_dispatcher<F, V, R, Types...>::apply_const(v0, v1, std::forward<F>(f));
|
|
855
|
-
}
|
|
856
|
-
// non-const
|
|
857
|
-
template <typename F, typename V, typename R = typename detail::result_of_binary_visit<F, first_type>::type>
|
|
858
|
-
auto VARIANT_INLINE static binary_visit(V& v0, V& v1, F&& f)
|
|
859
|
-
-> decltype(detail::binary_dispatcher<F, V, R, Types...>::apply(v0, v1, std::forward<F>(f)))
|
|
860
|
-
{
|
|
861
|
-
return detail::binary_dispatcher<F, V, R, Types...>::apply(v0, v1, std::forward<F>(f));
|
|
862
|
-
}
|
|
863
|
-
|
|
864
|
-
~variant() noexcept // no-throw destructor
|
|
865
|
-
{
|
|
866
|
-
helper_type::destroy(type_index, &data);
|
|
867
|
-
}
|
|
868
|
-
|
|
869
|
-
// comparison operators
|
|
870
|
-
// equality
|
|
871
|
-
VARIANT_INLINE bool operator==(variant const& rhs) const
|
|
872
|
-
{
|
|
873
|
-
assert(valid() && rhs.valid());
|
|
874
|
-
if (this->which() != rhs.which())
|
|
875
|
-
{
|
|
876
|
-
return false;
|
|
877
|
-
}
|
|
878
|
-
detail::comparer<variant, detail::equal_comp> visitor(*this);
|
|
879
|
-
return visit(rhs, visitor);
|
|
880
|
-
}
|
|
881
|
-
|
|
882
|
-
VARIANT_INLINE bool operator!=(variant const& rhs) const
|
|
883
|
-
{
|
|
884
|
-
return !(*this == rhs);
|
|
885
|
-
}
|
|
886
|
-
|
|
887
|
-
// less than
|
|
888
|
-
VARIANT_INLINE bool operator<(variant const& rhs) const
|
|
889
|
-
{
|
|
890
|
-
assert(valid() && rhs.valid());
|
|
891
|
-
if (this->which() != rhs.which())
|
|
892
|
-
{
|
|
893
|
-
return this->which() < rhs.which();
|
|
894
|
-
}
|
|
895
|
-
detail::comparer<variant, detail::less_comp> visitor(*this);
|
|
896
|
-
return visit(rhs, visitor);
|
|
897
|
-
}
|
|
898
|
-
VARIANT_INLINE bool operator>(variant const& rhs) const
|
|
899
|
-
{
|
|
900
|
-
return rhs < *this;
|
|
901
|
-
}
|
|
902
|
-
VARIANT_INLINE bool operator<=(variant const& rhs) const
|
|
903
|
-
{
|
|
904
|
-
return !(*this > rhs);
|
|
905
|
-
}
|
|
906
|
-
VARIANT_INLINE bool operator>=(variant const& rhs) const
|
|
907
|
-
{
|
|
908
|
-
return !(*this < rhs);
|
|
909
|
-
}
|
|
910
|
-
};
|
|
911
|
-
|
|
912
|
-
// unary visitor interface
|
|
913
|
-
// const
|
|
914
|
-
template <typename F, typename V>
|
|
915
|
-
auto VARIANT_INLINE apply_visitor(F&& f, V const& v) -> decltype(V::visit(v, std::forward<F>(f)))
|
|
916
|
-
{
|
|
917
|
-
return V::visit(v, std::forward<F>(f));
|
|
918
|
-
}
|
|
919
|
-
|
|
920
|
-
// non-const
|
|
921
|
-
template <typename F, typename V>
|
|
922
|
-
auto VARIANT_INLINE apply_visitor(F&& f, V& v) -> decltype(V::visit(v, std::forward<F>(f)))
|
|
923
|
-
{
|
|
924
|
-
return V::visit(v, std::forward<F>(f));
|
|
925
|
-
}
|
|
926
|
-
|
|
927
|
-
// binary visitor interface
|
|
928
|
-
// const
|
|
929
|
-
template <typename F, typename V>
|
|
930
|
-
auto VARIANT_INLINE apply_visitor(F&& f, V const& v0, V const& v1) -> decltype(V::binary_visit(v0, v1, std::forward<F>(f)))
|
|
931
|
-
{
|
|
932
|
-
return V::binary_visit(v0, v1, std::forward<F>(f));
|
|
933
|
-
}
|
|
934
|
-
|
|
935
|
-
// non-const
|
|
936
|
-
template <typename F, typename V>
|
|
937
|
-
auto VARIANT_INLINE apply_visitor(F&& f, V& v0, V& v1) -> decltype(V::binary_visit(v0, v1, std::forward<F>(f)))
|
|
938
|
-
{
|
|
939
|
-
return V::binary_visit(v0, v1, std::forward<F>(f));
|
|
940
|
-
}
|
|
941
|
-
|
|
942
|
-
// getter interface
|
|
943
|
-
|
|
944
|
-
#ifdef HAS_EXCEPTIONS
|
|
945
|
-
template <typename ResultType, typename T>
|
|
946
|
-
auto get(T& var)->decltype(var.template get<ResultType>())
|
|
947
|
-
{
|
|
948
|
-
return var.template get<ResultType>();
|
|
949
|
-
}
|
|
950
|
-
#endif
|
|
951
|
-
|
|
952
|
-
template <typename ResultType, typename T>
|
|
953
|
-
ResultType& get_unchecked(T& var)
|
|
954
|
-
{
|
|
955
|
-
return var.template get_unchecked<ResultType>();
|
|
956
|
-
}
|
|
957
|
-
|
|
958
|
-
#ifdef HAS_EXCEPTIONS
|
|
959
|
-
template <typename ResultType, typename T>
|
|
960
|
-
auto get(T const& var)->decltype(var.template get<ResultType>())
|
|
961
|
-
{
|
|
962
|
-
return var.template get<ResultType>();
|
|
963
|
-
}
|
|
964
|
-
#endif
|
|
965
|
-
|
|
966
|
-
template <typename ResultType, typename T>
|
|
967
|
-
ResultType const& get_unchecked(T const& var)
|
|
968
|
-
{
|
|
969
|
-
return var.template get_unchecked<ResultType>();
|
|
970
|
-
}
|
|
971
|
-
} // namespace util
|
|
972
|
-
} // namespace mapbox
|
|
973
|
-
|
|
974
|
-
#endif // MAPBOX_UTIL_VARIANT_HPP
|