12 #ifndef HAMMER_TOOLS_LOKI
13 #define HAMMER_TOOLS_LOKI
21 template <
typename Test,
template <
typename...>
class Ref>
24 template <
template <
typename...>
class Ref,
typename... Args>
28 template <
typename... Ts>
30 static constexpr
size_t size{
sizeof... (Ts) };
37 template<
typename,
typename>
40 template<
typename T,
typename... Ts>
43 template<
typename T,
typename TOther,
typename... Ts>
44 struct IndexOf<T,
TypeList<TOther, Ts...>> : std::integral_constant<size_t, 1 + IndexOf<T, TypeList<Ts...>>::value> {};
48 template<
class Executor,
class BaseLhs,
class TypesLhs,
49 bool symmetric =
true,
class BaseRhs = BaseLhs,
50 class TypesRhs = TypesLhs,
typename ResultType =
void>
55 template <
bool swapArgs,
class SomeLhs,
class SomeRhs>
57 static ResultType
DoDispatch(SomeLhs& lhs, SomeRhs& rhs, Executor& exec) {
58 return exec(lhs, rhs);
61 template <
class SomeLhs,
class SomeRhs>
63 static ResultType
DoDispatch(SomeLhs& lhs, SomeRhs& rhs, Executor& exec) {
64 return exec(rhs, lhs);
70 template <
class SomeLhs>
72 return exec.error(lhs, rhs);
75 template <
class SomeLhs,
class Head,
class... Ts>
77 if (Head* p2 = dynamic_cast<Head*>(&rhs)) {
79 swapArgs = symmetric &&
86 return CallTraits::DoDispatch(lhs, *p2, exec);
92 return exec.error(lhs, rhs);
95 template <
class Head,
class... Ts>
97 if (Head* p1 = dynamic_cast<Head*>(&lhs)) {
98 return DispatchRhs(*p1, rhs, exec, TypesRhs());
104 static ResultType
Go(BaseLhs& lhs, BaseRhs& rhs, Executor& exec) {
105 return DispatchLhs(lhs, rhs, exec, TypesLhs());
110 template <
class Executor,
class BaseLhs,
class TypesLhs,
typename ResultType =
void>
114 template <
class SomeLhs>
123 return exec.error(lhs);
126 template <
class Head,
class... Ts>
128 if (Head* p1 = dynamic_cast<Head*>(&lhs)) {
131 return CallTraits::DoDispatch(*p1, exec);
137 static ResultType
Go(BaseLhs& lhs, Executor& exec) {
138 return Dispatch(lhs, exec, TypesLhs());
static ResultType DispatchRhs(SomeLhs &lhs, BaseRhs &rhs, Executor &exec, TypeList< Head, Ts...>)
static ResultType DoDispatch(SomeLhs &lhs, Executor &exec)
static ResultType DispatchRhs(SomeLhs &lhs, BaseRhs &rhs, Executor &exec, NullType)
static ResultType DispatchLhs(BaseLhs &lhs, BaseRhs &rhs, Executor &exec, TypeList< Head, Ts...>)
static ResultType Go(BaseLhs &lhs, Executor &exec)
static ResultType Dispatch(BaseLhs &lhs, Executor &exec, TypeList< Head, Ts...>)
static constexpr size_t size
static ResultType Go(BaseLhs &lhs, BaseRhs &rhs, Executor &exec)
static ResultType DoDispatch(SomeLhs &lhs, SomeRhs &rhs, Executor &exec)
static ResultType DispatchLhs(BaseLhs &lhs, BaseRhs &rhs, Executor &exec, NullType)
static ResultType Dispatch(BaseLhs &lhs, Executor &exec, NullType)
static ResultType DoDispatch(SomeLhs &lhs, SomeRhs &rhs, Executor &exec)