|
@@ -115,8 +115,8 @@ std::vector<R> t2v(const std::tuple<ArgTypes...>& t){
|
|
|
|
|
|
namespace detail {
|
|
|
template <class F, class Tuple, std::size_t... I>
|
|
|
- constexpr decltype(auto) call_impl(F &&f, Tuple &&t, std::index_sequence<I...>){
|
|
|
- return f(std::get<I>(std::forward<Tuple>(t))...);
|
|
|
+ constexpr decltype(auto) call_impl(F *f, Tuple &&t, std::index_sequence<I...>){
|
|
|
+ return (*f)(std::get<I>(std::forward<Tuple>(t))...);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -124,9 +124,9 @@ namespace detail {
|
|
|
* Call a function f with the elements of the tuple t as arguments
|
|
|
*/
|
|
|
template <class F, class Tuple>
|
|
|
-constexpr decltype(auto) call(F &&f, Tuple &&t){
|
|
|
+constexpr decltype(auto) call(F *f, Tuple &&t){
|
|
|
return detail::call_impl(
|
|
|
- std::forward<F>(f), std::forward<Tuple>(t),
|
|
|
+ f, std::forward<Tuple>(t),
|
|
|
std::make_index_sequence<std::tuple_size<std::decay_t<Tuple>>::value>{});
|
|
|
}
|
|
|
|
|
@@ -194,7 +194,7 @@ class GenFunction {
|
|
|
}
|
|
|
|
|
|
template <typename T>
|
|
|
- static Function<T>& reg_func(const std::string& name, std::function<T> f, const std::string& impl){
|
|
|
+ static Function<T>* reg_func(const std::string& name, std::function<T> f, const std::string& impl){
|
|
|
in_reg_func = true;
|
|
|
Function<T>* func;
|
|
|
if (GenFunction::function_registry[name] != nullptr){
|
|
@@ -207,11 +207,11 @@ class GenFunction {
|
|
|
GenFunction::function_registry[name] = func;
|
|
|
}
|
|
|
in_reg_func = false;
|
|
|
- return *func;
|
|
|
+ return func;
|
|
|
}
|
|
|
|
|
|
template <typename T>
|
|
|
- static Function<T>& lookup_function(const std::string& name){
|
|
|
+ static Function<T>* lookup_function(const std::string& name){
|
|
|
if (GenFunction::function_registry[name] == nullptr){
|
|
|
CRITICAL("Function \"" << name << "\" not previously registered", -1);
|
|
|
} else {
|
|
@@ -219,7 +219,7 @@ class GenFunction {
|
|
|
if (func == nullptr){
|
|
|
CRITICAL("Function \"" << name << "\" request and register have mismatched types", -1);
|
|
|
}
|
|
|
- return *GenFunction::function_registry[name];
|
|
|
+ return func;
|
|
|
}
|
|
|
}
|
|
|
};
|
|
@@ -692,7 +692,7 @@ template <typename Ret, typename ArgType>
|
|
|
class Map<Ret(ArgType)> : public DerivedValue<std::vector<Ret>>{
|
|
|
private:
|
|
|
typedef Value<std::vector<ArgType>> arg_type;
|
|
|
- Function<Ret(ArgType)>& fn;
|
|
|
+ Function<Ret(ArgType)>* fn;
|
|
|
arg_type* arg;
|
|
|
|
|
|
void update_value(){
|
|
@@ -703,11 +703,11 @@ class Map<Ret(ArgType)> : public DerivedValue<std::vector<Ret>>{
|
|
|
}
|
|
|
|
|
|
public:
|
|
|
- static std::string fmt_name(Function<Ret(ArgType)>& fn, arg_type* arg){
|
|
|
- return "map("+fn.get_name()+":"+arg->get_name()+")";
|
|
|
+ static std::string fmt_name(Function<Ret(ArgType)>* fn, arg_type* arg){
|
|
|
+ return "map("+fn->get_name()+":"+arg->get_name()+")";
|
|
|
}
|
|
|
|
|
|
- Map(Function<Ret(ArgType)>& fn, arg_type* arg, const std::string& alias)
|
|
|
+ Map(Function<Ret(ArgType)>* fn, arg_type* arg, const std::string& alias)
|
|
|
:DerivedValue<std::vector<Ret>>(fmt_name(fn, arg), alias),
|
|
|
fn(fn), arg(arg){ }
|
|
|
|
|
@@ -728,7 +728,7 @@ template <typename Ret, typename... ArgTypes>
|
|
|
class TupMap<Ret(ArgTypes...)> : public DerivedValue<std::vector<Ret>>{
|
|
|
private:
|
|
|
typedef Value<std::vector<std::tuple<ArgTypes...>>> arg_type;
|
|
|
- Function<Ret(ArgTypes...)>& fn;
|
|
|
+ Function<Ret(ArgTypes...)>* fn;
|
|
|
arg_type* arg;
|
|
|
|
|
|
void update_value(){
|
|
@@ -739,11 +739,11 @@ class TupMap<Ret(ArgTypes...)> : public DerivedValue<std::vector<Ret>>{
|
|
|
}
|
|
|
|
|
|
public:
|
|
|
- static std::string fmt_name(Function<Ret(ArgTypes...)>& fn, arg_type* arg){
|
|
|
- return "tup_map("+fn.get_name()+":"+arg->get_name()+")";
|
|
|
+ static std::string fmt_name(Function<Ret(ArgTypes...)>* fn, arg_type* arg){
|
|
|
+ return "tup_map("+fn->get_name()+":"+arg->get_name()+")";
|
|
|
}
|
|
|
|
|
|
- TupMap(Function<Ret(ArgTypes...)>& fn, arg_type* arg, const std::string& alias)
|
|
|
+ TupMap(Function<Ret(ArgTypes...)>* fn, arg_type* arg, const std::string& alias)
|
|
|
:DerivedValue<std::vector<Ret>>(fmt_name(fn, arg), alias),
|
|
|
fn(fn), arg(arg){ }
|
|
|
|
|
@@ -883,14 +883,40 @@ class DeTupVector : public DerivedValue<std::vector<typename std::tuple_element<
|
|
|
};
|
|
|
|
|
|
template<typename> class Apply; // undefined
|
|
|
+/**
|
|
|
+ * Applies a function to a tuple of values and returns a value. This will
|
|
|
+ * typically be called with a Tuple object as an argument.
|
|
|
+ */
|
|
|
+template <typename Ret, typename ArgType>
|
|
|
+class Apply<Ret(ArgType)> : public DerivedValue<Ret>{
|
|
|
+ private:
|
|
|
+ Function<Ret(ArgType)>* fn;
|
|
|
+ Value<ArgType>* arg;
|
|
|
+
|
|
|
+ void update_value(){
|
|
|
+ this->value = (*fn)(arg->get_value());
|
|
|
+ }
|
|
|
+
|
|
|
+ public:
|
|
|
+ static std::string fmt_name(Function<Ret(ArgType)>* fn, Value<ArgType>* arg){
|
|
|
+ return "apply("+fn->get_name()+":"+arg->get_name()+")";
|
|
|
+ }
|
|
|
+
|
|
|
+ Apply(Function<Ret(ArgType)>* fn, Value<ArgType>* arg, const std::string& alias)
|
|
|
+ :DerivedValue<Ret>(fmt_name(fn,arg), alias),
|
|
|
+ fn(fn), arg(arg){ }
|
|
|
+
|
|
|
+};
|
|
|
+
|
|
|
+template<typename> class TupApply; // undefined
|
|
|
/**
|
|
|
* Applies a function to a tuple of values and returns a value. This will
|
|
|
* typically be called with a Tuple object as an argument.
|
|
|
*/
|
|
|
template <typename Ret, typename... ArgTypes>
|
|
|
-class Apply<Ret(ArgTypes...)> : public DerivedValue<Ret>{
|
|
|
+class TupApply<Ret(ArgTypes...)> : public DerivedValue<Ret>{
|
|
|
private:
|
|
|
- Function<Ret(ArgTypes...)>& fn;
|
|
|
+ Function<Ret(ArgTypes...)>* fn;
|
|
|
Value<std::tuple<ArgTypes...>>* arg;
|
|
|
|
|
|
void update_value(){
|
|
@@ -899,11 +925,11 @@ class Apply<Ret(ArgTypes...)> : public DerivedValue<Ret>{
|
|
|
}
|
|
|
|
|
|
public:
|
|
|
- static std::string fmt_name(Function<Ret(ArgTypes...)>& fn, Value<std::tuple<ArgTypes...>>* arg){
|
|
|
- return "apply("+fn.get_name()+":"+arg->get_name()+")";
|
|
|
+ static std::string fmt_name(Function<Ret(ArgTypes...)>* fn, Value<std::tuple<ArgTypes...>>* arg){
|
|
|
+ return "tup_apply("+fn->get_name()+":"+arg->get_name()+")";
|
|
|
}
|
|
|
|
|
|
- Apply(Function<Ret(ArgTypes...)>& fn, Value<std::tuple<ArgTypes...>>* arg, const std::string& alias)
|
|
|
+ TupApply(Function<Ret(ArgTypes...)>* fn, Value<std::tuple<ArgTypes...>>* arg, const std::string& alias)
|
|
|
:DerivedValue<Ret>(fmt_name(fn,arg), alias),
|
|
|
fn(fn), arg(arg){ }
|
|
|
|
|
@@ -915,7 +941,7 @@ class Apply<Ret(ArgTypes...)> : public DerivedValue<Ret>{
|
|
|
template<typename T>
|
|
|
class Count : public DerivedValue<int>{
|
|
|
private:
|
|
|
- Function<bool(T)>& selector;
|
|
|
+ Function<bool(T)>* selector;
|
|
|
Value<std::vector<T> >* v;
|
|
|
|
|
|
void update_value(){
|
|
@@ -927,11 +953,11 @@ class Count : public DerivedValue<int>{
|
|
|
}
|
|
|
|
|
|
public:
|
|
|
- static std::string fmt_name(Function<bool(T)>& selector, Value<std::vector<T>>* v){
|
|
|
- return "count("+selector.get_name()+":"+v->get_name()+")";
|
|
|
+ static std::string fmt_name(Function<bool(T)>* selector, Value<std::vector<T>>* v){
|
|
|
+ return "count("+selector->get_name()+":"+v->get_name()+")";
|
|
|
}
|
|
|
|
|
|
- Count(Function<bool(T)>& selector, Value<std::vector<T>>* v, const std::string alias)
|
|
|
+ Count(Function<bool(T)>* selector, Value<std::vector<T>>* v, const std::string alias)
|
|
|
:DerivedValue<int>(fmt_name(selector,v), alias),
|
|
|
selector(selector), v(v) { }
|
|
|
};
|
|
@@ -942,7 +968,7 @@ class Count : public DerivedValue<int>{
|
|
|
template<typename T>
|
|
|
class Filter : public DerivedValue<std::vector<T>>{
|
|
|
private:
|
|
|
- Function<bool(T)>& filter;
|
|
|
+ Function<bool(T)>* filter;
|
|
|
Value<std::vector<T> >* v;
|
|
|
|
|
|
void update_value(){
|
|
@@ -954,11 +980,11 @@ class Filter : public DerivedValue<std::vector<T>>{
|
|
|
}
|
|
|
|
|
|
public:
|
|
|
- static std::string fmt_name(Function<bool(T)>& filter, Value<std::vector<T>>* v){
|
|
|
- return "filter("+filter.get_name()+":"+v->get_name()+")";
|
|
|
+ static std::string fmt_name(Function<bool(T)>* filter, Value<std::vector<T>>* v){
|
|
|
+ return "filter("+filter->get_name()+":"+v->get_name()+")";
|
|
|
}
|
|
|
|
|
|
- Filter(Function<bool(T)>& filter, Value<std::vector<T>>* v, const std::string alias)
|
|
|
+ Filter(Function<bool(T)>* filter, Value<std::vector<T>>* v, const std::string alias)
|
|
|
:DerivedValue<std::vector<T>>(fmt_name(filter,v), alias),
|
|
|
filter(filter), v(v) { }
|
|
|
};
|
|
@@ -972,7 +998,7 @@ template<typename... ArgTypes>
|
|
|
class TupFilter : public DerivedValue<std::vector<std::tuple<ArgTypes...>>>{
|
|
|
private:
|
|
|
typedef std::vector<std::tuple<ArgTypes...>> value_type;
|
|
|
- Function<bool(ArgTypes...)>& filter;
|
|
|
+ Function<bool(ArgTypes...)>* filter;
|
|
|
Value<value_type>* arg;
|
|
|
|
|
|
void update_value(){
|
|
@@ -984,11 +1010,11 @@ class TupFilter : public DerivedValue<std::vector<std::tuple<ArgTypes...>>>{
|
|
|
}
|
|
|
|
|
|
public:
|
|
|
- static std::string fmt_name(Function<bool(ArgTypes...)>& filter, Value<value_type>* arg){
|
|
|
- return "tup_filter("+filter.get_name()+":"+arg->get_name()+")";
|
|
|
+ static std::string fmt_name(Function<bool(ArgTypes...)>* filter, Value<value_type>* arg){
|
|
|
+ return "tup_filter("+filter->get_name()+":"+arg->get_name()+")";
|
|
|
}
|
|
|
|
|
|
- TupFilter(Function<bool(ArgTypes...)>& filter, Value<value_type>* arg, const std::string alias)
|
|
|
+ TupFilter(Function<bool(ArgTypes...)>* filter, Value<value_type>* arg, const std::string alias)
|
|
|
:DerivedValue<value_type>(fmt_name(filter, arg), alias),
|
|
|
filter(filter), arg(arg) { }
|
|
|
};
|
|
@@ -1002,7 +1028,7 @@ class TupFilter : public DerivedValue<std::vector<std::tuple<ArgTypes...>>>{
|
|
|
template <typename T>
|
|
|
class Reduce : public DerivedValue<T>{
|
|
|
private:
|
|
|
- Function<T(std::vector<T>)>& reduce_fn;
|
|
|
+ Function<T(std::vector<T>)>* reduce_fn;
|
|
|
|
|
|
void update_value(){
|
|
|
this->value = reduce_fn(v->get_value());
|
|
@@ -1012,11 +1038,11 @@ class Reduce : public DerivedValue<T>{
|
|
|
Value<std::vector<T> >* v;
|
|
|
|
|
|
public:
|
|
|
- static std::string fmt_name(Function<T(std::vector<T>)>& reduce_fn, Value<std::vector<T>>* v){
|
|
|
- return "reduce("+reduce_fn.get_name()+":"+v->get_name()+")";
|
|
|
+ static std::string fmt_name(Function<T(std::vector<T>)>* reduce_fn, Value<std::vector<T>>* v){
|
|
|
+ return "reduce("+reduce_fn->get_name()+":"+v->get_name()+")";
|
|
|
}
|
|
|
|
|
|
- Reduce(Function<T(std::vector<T>)>& reduce_fn, Value<std::vector<T> >* v, const std::string alias)
|
|
|
+ Reduce(Function<T(std::vector<T>)>* reduce_fn, Value<std::vector<T> >* v, const std::string alias)
|
|
|
:DerivedValue<T>(fmt_name(reduce_fn, v), alias),
|
|
|
reduce_fn(reduce_fn), v(v) { }
|
|
|
};
|
|
@@ -1112,7 +1138,7 @@ class ElementOf : public Reduce<T>{
|
|
|
template <typename T>
|
|
|
class ReduceIndex : public DerivedValue<std::pair<T, int> >{
|
|
|
private:
|
|
|
- Function<std::pair<T,int>(std::vector<T>)>& reduce;
|
|
|
+ Function<std::pair<T,int>(std::vector<T>)>* reduce;
|
|
|
Value<std::vector<T> >* v;
|
|
|
|
|
|
void update_value(){
|
|
@@ -1120,8 +1146,8 @@ class ReduceIndex : public DerivedValue<std::pair<T, int> >{
|
|
|
}
|
|
|
|
|
|
public:
|
|
|
- ReduceIndex(Function<std::pair<T,int>(std::vector<T>)>& reduce, Value<std::vector<T> >* v, const std::string alias="")
|
|
|
- :DerivedValue<T>("reduceIndexWith("+reduce.get_name()+":"+v->get_name()+")", alias),
|
|
|
+ ReduceIndex(Function<std::pair<T,int>(std::vector<T>)>* reduce, Value<std::vector<T> >* v, const std::string alias="")
|
|
|
+ :DerivedValue<T>("reduceIndexWith("+reduce->get_name()+":"+v->get_name()+")", alias),
|
|
|
reduce(reduce), v(v) { }
|
|
|
};
|
|
|
|
|
@@ -1242,17 +1268,17 @@ class CartProduct : public DerivedValue<std::vector<std::tuple<FST,SND>>>{
|
|
|
template <typename T>
|
|
|
class BoundValue : public DerivedValue<T>{
|
|
|
protected:
|
|
|
- Function<T()>& f;
|
|
|
+ Function<T()>* f;
|
|
|
void update_value(){
|
|
|
- this->value = f();
|
|
|
+ this->value = (*f)();
|
|
|
}
|
|
|
|
|
|
public:
|
|
|
- static std::string fmt_name(Function<T()> f){
|
|
|
- return f.get_name()+"(<bound>)";
|
|
|
+ static std::string fmt_name(Function<T()>* f){
|
|
|
+ return f->get_name()+"(<bound>)";
|
|
|
}
|
|
|
|
|
|
- BoundValue(Function<T()>& f, const std::string alias="")
|
|
|
+ BoundValue(Function<T()>* f, const std::string alias="")
|
|
|
:DerivedValue<T>(fmt_name(f), alias),
|
|
|
f(f) { }
|
|
|
};
|