-
Notifications
You must be signed in to change notification settings - Fork 0
/
JL_ActionTree_ActionDynamic.h
59 lines (48 loc) · 1.46 KB
/
JL_ActionTree_ActionDynamic.h
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
// Copyright (C) 2021 Kobe Vrijsen <kobevrijsen@posteo.be>
//
// ActionTree - Tree based decision/action stucture helper. An alternative to branches.
//
// This file is free software and distributed under the terms of the European Union
// Public Lincense as published by the European Commision; either version 1.2 of the
// License, or, at your option, any later version.
#pragma once
#include "JL_ActionTree_Base.h"
#include "JL_ActionTree_Action.h"
namespace JL::action_tree
{
template <typename>
struct ActionDynamic {};
template <typename R, typename ... P>
struct ActionDynamic<R(P...)> : std::function<R(P...)>
{
explicit ActionDynamic () = default;
template<typename T>
explicit ActionDynamic (Action<T>);
TEMPLATE /* This& */ operator = (Action<T>);
};
};
namespace JL::action_tree
{
template<typename R, typename ...P>
template<typename T>
ActionDynamic<R(P...)>::ActionDynamic(Action<T> action)
{
operator=(std::move(action));
}
template <typename R, typename ... P>
template <typename T>
auto ActionDynamic<R(P...)>::operator = (Action<T> a)
{
if constexpr (std::is_same_v<R, decltype(a(std::declval<P>()...))>)
{
return std::function<R(P...)>::operator=(
[a = std::move(a)]
(P ... p) mutable->R
{
return a(p...);
}
);
}
else static_assert(false, "ActionDynamic::operator=(Action) Action does not return the correct type.");
}
}