39#ifndef LAMBDA_INSTRUCTION_H
40#define LAMBDA_INSTRUCTION_H
45#include "data/untypedSharedPtr.h"
46#include "instructions/instruction.h"
60 template <
typename First,
typename... Rest>
88 const std::function<double(
const First,
const Rest...)>
func;
95#ifndef CODE_GENERATION
111 virtual bool checkOperandTypes(
112 const std::vector<Data::UntypedSharedPtr>& arguments)
const override
119 const std::vector<std::reference_wrapper<const std::type_info>>
122 (!std::is_array<First>::value)
124 :
typeid(std::remove_all_extents_t<First>[]),
125 (!std::is_array<Rest>::value)
127 :
typeid(std::remove_all_extents_t<Rest>[])...};
129 for (
auto idx = 0; idx < arguments.size(); idx++) {
131 const std::type_info& argType = arguments.at(idx).getType();
132 if (argType != expectedTypes.at(idx).get()) {
142 const std::vector<Data::UntypedSharedPtr>& args)
const override
151 doExecution(args, std::index_sequence_for<Rest...>{});
171 template <
size_t... I>
172 double doExecution(
const std::vector<Data::UntypedSharedPtr>& args,
173 std::index_sequence<I...>)
const
176 getDataFromUntypedSharedPtr<First>(args, 0),
177 getDataFromUntypedSharedPtr<Rest>(args, I + 1)...);
194 template <
typename T,
195 typename MINUS_EXTENT =
typename std::remove_extent<T>::type,
196 typename RETURN_TYPE =
typename std::conditional<
197 !std::is_array<MINUS_EXTENT>::value,
198 typename std::remove_all_extents<T>::type*,
199 MINUS_EXTENT*>::type>
200 constexpr auto getDataFromUntypedSharedPtr(
201 const std::vector<Data::UntypedSharedPtr>& args,
size_t idx)
const
203 if constexpr (!std::is_array<T>::value) {
204 return *(args.at(idx).getSharedPointer<
const T>());
210 const std::remove_all_extents_t<T>[]>();
211 return (RETURN_TYPE)returnedPtr.get();
This abstract class is the base class for any instruction to be used in a Program.
Definition instruction.h:61
std::vector< std::reference_wrapper< const std::type_info > > operandTypes
List of the types of the operands needed to execute the instruction.
Definition instruction.h:213
virtual double execute(const std::vector< Data::UntypedSharedPtr > &args) const =0
Execute the Instruction for the given arguments.
Definition instruction.cpp:82
std::string printTemplate
Definition instruction.h:112
Template instruction for simplifying the creation of an Instruction from a c++ lambda function.
Definition lambdaInstruction.h:62
const std::function< double(const First, const Rest...)> func
Function executed for this Instruction.
Definition lambdaInstruction.h:88
LambdaInstruction()=delete
delete the default constructor.
virtual double execute(const std::vector< Data::UntypedSharedPtr > &args) const override
Inherited from Instruction.
Definition lambdaInstruction.h:141
LambdaInstruction(std::function< double(First, Rest...)> function, const std::string &printTemplate="")
Constructor of the class LambdaInstruction to create a printable Instruction.
Definition lambdaInstruction.h:76
Definition addPrimitiveType.h:49