Alexandria  2.25.0
SDC-CH common library for the Euclid project
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Function.icpp
Go to the documentation of this file.
1 
19 #ifdef PYSTON_GRAPH_FUNCTION_IMPL
20 
21 namespace Pyston {
22 
23 template <typename R, size_t N, typename... Evaluated>
24 struct FunctionEvalHelper {
25  template <typename Functor, typename ChildrenSet>
26  static R eval(const Context& context, const Arguments& args, const Functor& functor, const ChildrenSet& children,
27  Evaluated&&... evaluated) {
28  auto a = std::get<N - 1>(children)->eval(context, args);
29  return FunctionEvalHelper<R, N - 1, decltype(a), Evaluated...>::eval(
30  context, args, functor, children, std::forward<decltype(a)>(a), std::forward<Evaluated>(evaluated)...);
31  }
32 };
33 
34 template <typename R, typename... Evaluated>
35 struct FunctionEvalHelper<R, 0, Evaluated...> {
36  template <typename Functor, typename ChildrenSet>
37  static R eval(const Context& context, const Arguments&, const Functor& functor, const ChildrenSet&,
38  Evaluated&&... evaluated) {
39  return functor(context, std::forward<Evaluated>(evaluated)...);
40  }
41 };
42 
43 template <size_t N>
44 struct FunctionVisitHelper {
45  template <typename ChildrenSet>
46  static void visit(Visitor& visitor, const ChildrenSet& children) {
47  FunctionVisitHelper<N - 1>::visit(visitor, children);
48  std::get<N - 1>(children)->visit(visitor);
49  }
50 };
51 
52 template <>
53 struct FunctionVisitHelper<0> {
54  template <typename ChildrenSet>
55  static void visit(Visitor&, const ChildrenSet&) {}
56 };
57 
58 template <typename R, typename... Args>
59 R Function<R, Args...>::eval(const Context& context, const Arguments& args) const {
60  return FunctionEvalHelper<R, sizeof...(Args)>::eval(context, args, m_functor, m_children);
61 }
62 
63 template <typename R, typename... Args>
64 void Function<R, Args...>::visit(Visitor& visitor) const {
65  visitor.enter(this);
66  FunctionVisitHelper<sizeof...(Args)>::visit(visitor, m_children);
67  visitor.exit(this);
68 }
69 
70 } // end of namespace Pyston
71 
72 #endif
std::map< std::string, boost::any > Context
Definition: Node.h:99
std::vector< Value > Arguments
Definition: Node.h:94
R eval(const Context &context, const Arguments &args) const final
void visit(Visitor &visitor) const final
constexpr std::size_t N
T forward(T...args)