20 #define mt_unused(Param) (void)Param;
21 #define mt_unpackEval(...) mt::pass(((__VA_ARGS__), 0)...)
27 template<
class... Args>
void pass(Args...) {}
29 template<
class T, T val>
using Value = std::integral_constant<T, val>;
31 template<
class...>
struct True : std::true_type {};
39 template<
int>
struct tag {
tag() =
default;
tag(
int) {} };
42 template<
class T>
using addRef = std::add_lvalue_reference<T>;
44 template<
class T>
using removeRef = std::remove_reference<T>;
46 template<
class T>
using addPtr = std::add_pointer<T>;
48 template<
class T>
using removePtr = std::remove_pointer<T>;
62 template<
bool b,
class T =
void>
using disable_if = std::enable_if<!b, T>;
69 template<
class Base,
class Derived>
struct is_base_of : std::is_base_of<typename removeRef<Base>::type, typename removeRef<Derived>::type> {};
72 template<
class T,
template<
class...>
class Template>
74 template<
template<
class...>
class Template,
class... Param>
81 template<
class Func,
class... Args>
84 template<
class F>
static auto test(
void*) -> decltype(declval<F>()(declval<Args>()...), std::true_type());
85 template<
class F>
static std::false_type test(...);
93 template<
int cur,
int end,
class... Ts>
struct typeAt;
94 template<
int cur,
int end,
class T,
class... Ts>
struct typeAt<cur, end, T, Ts...> :
typeAt<cur+1, end, Ts...> {};
95 template<
int cur,
class T,
class... Ts>
struct typeAt<cur, cur, T, Ts...> {
typedef T type; };
96 template<
int cur,
int end>
struct typeAt<cur, end> {};
98 template<
int cur,
class Match,
class... Ts>
struct typeIndex;
99 template<
int cur,
class Match,
class T,
class... Ts>
struct typeIndex<cur, Match, T, Ts...> :
typeIndex<cur+1, Match, Ts...> {};
100 template<
int cur,
class T,
class... Ts>
struct typeIndex<cur, T, T, Ts...> :
Value<int, cur> {};
101 template<
int cur,
class Match>
struct typeIndex<cur, Match> :
Value<int, -1> {};
111 template<
szt... Ints>
using idxseq = std::index_sequence<Ints...>;
118 template<
class Func,
class Tuple,
szt... Seq>
123 template<
class Func,
class Tuple>
128 template<
class Array>
using arraySize =
Value<
szt,
sizeof(Array) /
sizeof(
typename Array::value_type)>;
131 template<
class T,
class... Ts>
132 auto make_array(T&& t, Ts&&... ts) -> array<T,
sizeof...(Ts)+1> {
return {forward<T>(t), forward<Ts>(ts)...}; }
136 template<
class Func,
class... Funcs>
137 void exec(Func&& f, Funcs&&... fs) { f();
exec(forward<Funcs>(fs)...); }
140 template<
int64 begin,
int64 end,
int64 step = 1,
class Func,
class... Args,
typename std::enable_if<begin == end, int>::type=0>
141 void for_(Func&& f, Args&&... args) {}
142 template<
int64 begin,
int64 end,
int64 step = 1,
class Func,
class... Args,
typename std::enable_if<begin != end, int>::type=0>
143 void for_(Func&& f, Args&&... args) { f(begin, forward<Args>(args)...); for_<begin+step, end, step>(forward<Func>(f), forward<Args>(args)...); }
156 #define mt_hasMember(MemberName) mt_hasMember2(MemberName, MemberName)
157 #define mt_hasMember2(MemberName, TestName) \
158 template<class Class, class MemberType> \
159 class mt_hasMember_##TestName \
161 template<class T, T> struct matchType; \
162 template<class T> static auto memberMatch(void*) -> decltype(declval<matchType<MemberType, &T::MemberName>>(), std::true_type()); \
163 template<class T> static std::false_type memberMatch(...); \
165 static const bool value = mt::isTrue<decltype(memberMatch<Class>(nullptr))>::value; \
166 typedef typename std::conditional<value, MemberType, mt::Void>::type type; \
181 #define mt_hasType(TypeName) mt_hasType2(TypeName, TypeName)
182 #define mt_hasType2(TypeName, TestName) \
183 template<class Class> \
184 class mt_hasType_##TestName \
186 template<class T> static auto test(void*) -> decltype(declval<typename T::TypeName>(), std::true_type()); \
187 template<class T> static std::false_type test(...); \
189 template<bool Res, class Enable = void> \
190 struct testType { typedef mt::Void type; }; \
192 struct testType<Res, typename std::enable_if<Res>::type> { typedef typename Class::TypeName type; }; \
194 static const bool value = mt::isTrue<decltype(test<Class>(nullptr))>::value; \
195 typedef typename testType<value>::type type; \
203 template<
class T>
struct isIterator :
Value<bool, mt_hasType_iterator_category<T>::value || isPtr<T>::value> {};
207 template<
class T>
using isIterator = priv::isIterator<typename removeRef<T>::type>;
236 template<
class R,
class... Args>
243 template<
class F>
Funcptr(F&& f) { operator=(forward<F>(f)); }
246 template<
class... Args_>
247 R
operator()(Args_&&... args)
const {
return (base->*func)(forward<Args_>(args)...); }
250 explicit operator bool()
const {
return base && func; }
257 template<
class... Args>
264 template<
class F>
Funcptr(F&& f) { operator=(forward<F>(f)); }
267 template<
class... Args_>
268 void operator()(Args_&&... args)
const { (base->*func)(forward<Args_>(args)...); }
271 explicit operator bool()
const {
return base && func; }
278 template<class F, class Sig = typename funcTraits<typename removeRef<F>::type>::Sig>
283 #define mt_global(Class, Func, Ctor) inline UNBRACKET(Class)& Func() { static UNBRACKET(Class) obj Ctor; return obj; }
297 template<
int64 val,
int64... vals>
struct min<val, vals...> :
Value<int64, (val < min<vals...>::value ? val : min<vals...>::value)> {};
298 template<int64 val> struct min<val> : Value<int64, val> {};
302 template<int64... vals> struct max;
303 template<int64 val, int64... vals> struct max<val, vals...> : Value<int64, (val > max<vals...>::value ? val : max<vals...>::value)> {};
304 template<
int64 val>
struct max<val> :
Value<int64, val> {};
316 template<
int64 a,
int64 b>
struct gcd :
gcd<b, a % b> {};
317 template<
int64 a>
struct gcd<a, 0> :
Value<int64, abs<a>::value> {};
318 template<
int64 b>
struct gcd<0, b> :
Value<int64, abs<b>::value> {};
323 template<u
int64 N>
struct byteCount :
Value<int, ((max<log2Floor<N>::value, 1>::value + 7) >> 3)> {};
325 template<u
int64 N>
struct byteType : identity<uint64> {};
326 template<>
struct byteType<4> : identity<uint32> {};
327 template<>
struct byteType<3> : identity<uint32> {};
328 template<>
struct byteType<2> : identity<uint16> {};
329 template<>
struct byteType<1> : identity<uint8> {};
333 template<u
int64 N>
struct uintByValue : priv::byteType<priv::byteCount<N>::value> {};
336 template<
int N>
struct uintBySize : priv::byteType<N> {};
344 template<
class T>
struct functorTraits {};
348 template<
class T>
struct funcTraits : priv::functorTraits<decltype(&T::operator())> {};
351 #define TRAITS(Ptr) \
352 template<class R, class... Args> \
353 struct funcTraits<R Ptr (Args...)> \
355 typedef R Sig(Args...); \
358 static const szt arity = sizeof...(Args); \
359 template<szt I> using param = typeAt<I, Args...>; \
362 #define M_TRAITS(Const) \
363 template<class R, class Base_, class... Args> \
364 struct funcTraits<R (Base_::*) (Args...) Const> \
366 typedef R (Base_::*Sig) (Args...) Const; \
367 typedef Base_ Base; \
369 static const szt arity = sizeof...(Args)+1; \
371 template<szt I, szt _=0> struct param_ { typedef typeAt<I-1, Args...> type; }; \
372 template<szt _> struct param_<0, _> { typedef Const Base* type; }; \
374 template<szt I> using param = typename param_<I>::type; \
379 template<class R, class Base_, class... Args> \
380 struct functorTraits<R (Base_::*) (Args...) Const> \
382 typedef R Sig(Args...); \
385 static const szt arity = sizeof...(Args); \
386 template<szt I> using param = mt::typeAt<I, Args...>; \
Get maximum of all arguments.
Definition: Meta.h:302
bool operator==(const Funcptr &rhs) const
Definition: Meta.h:248
FuncptrBase * base
Definition: Meta.h:273
Version of std::is_base_of that removes reference qualifiers before testing.
Definition: Meta.h:69
FuncptrBase * base
Definition: Meta.h:252
Funcptr()
Definition: Meta.h:241
Funcptr & operator=(F &&f)
Definition: Meta.h:244
Funcptr(nullptr_t)
Definition: Meta.h:242
Inherit to declare that class is not copyable.
Definition: Meta.h:286
Funcptr(F &&f)
Definition: Meta.h:264
Func func
Definition: Meta.h:253
Check if T is a specialization of Template.
Definition: Meta.h:73
Funcptr(nullptr_t)
Definition: Meta.h:263
Variant of std::conditional for integers, stores result in value
Definition: Meta.h:65
static const bool value
Definition: Meta.h:87
tag(int)
Definition: Meta.h:39
bool operator!=(const Funcptr &rhs) const
Definition: Meta.h:249
Special void type, use where void is intended but implicit members are required (default ctor...
Definition: Meta.h:37
void operator()(Args_ &&...args) const
Definition: Meta.h:268
Funcptr & operator=(F &&f)
Definition: Meta.h:265
Get function type traits.
Definition: Meta.h:227
R operator()(Args_ &&...args) const
Definition: Meta.h:247
bool operator==(const Funcptr &rhs) const
Definition: Meta.h:269
Always returns true. Can be used to force a clause to be type dependent.
Definition: Meta.h:31
Func func
Definition: Meta.h:274
Funcptr()
Definition: Meta.h:262
Calc greatest common divisor of a and b.
Definition: Meta.h:316
Use to differentiate an overloaded function by type. Accepts dummy parameter default value: func(tag<...
Definition: Meta.h:39
size_t szt
Size type, shorthand for size_t.
Definition: Core.h:90
T type
Definition: Meta.h:25
Variant of True for integers.
Definition: Meta.h:33
Funcptr & operator=(nullptr_t)
Definition: Meta.h:245
NoCopy & operator=(const NoCopy &)=delete
long long int64
Definition: Core.h:21
Funcptr & operator=(nullptr_t)
Definition: Meta.h:266
Calc log base 2 of unsigned integer, rounded down to nearest integer. Returns -1 if x is zero...
Definition: Meta.h:312
bool operator==(const String &lhs, const String &rhs)
Definition: String.h:139
bool operator!=(const Funcptr &rhs) const
Definition: Meta.h:270
Returns type T unchanged.
Definition: Meta.h:25
Check if functor is callable with arguments.
Definition: Meta.h:82
Inherit to enable non-virtual functor calling.
Definition: Meta.h:231
Get minimum of all arguments.
Definition: Meta.h:296
Global Honeycomb namespace.
Funcptr(F &&f)
Definition: Meta.h:243