38#ifndef LAMBDA_INSTRUCTION_H
39#define LAMBDA_INSTRUCTION_H
44#include "data/untypedSharedPtr.h"
45#include "instructions/instruction.h"
59 template <
typename First,
typename... Rest>
87 const std::function<double(
const First,
const Rest...)>
func;
94#ifndef CODE_GENERATION
110 virtual bool checkOperandTypes(
111 const std::vector<Data::UntypedSharedPtr>& arguments)
const override
118 const std::vector<std::reference_wrapper<const std::type_info>>
121 (!std::is_array<First>::value)
123 :
typeid(std::remove_all_extents_t<First>[]),
124 (!std::is_array<Rest>::value)
126 :
typeid(std::remove_all_extents_t<Rest>[])...};
128 for (
auto idx = 0; idx < arguments.size(); idx++) {
130 const std::type_info& argType = arguments.at(idx).getType();
131 if (argType != expectedTypes.at(idx).get()) {
141 const std::vector<Data::UntypedSharedPtr>& args)
const override
150 doExecution(args, std::index_sequence_for<Rest...>{});
170 template <
size_t... I>
171 double doExecution(
const std::vector<Data::UntypedSharedPtr>& args,
172 std::index_sequence<I...>)
const
175 getDataFromUntypedSharedPtr<First>(args, 0),
176 getDataFromUntypedSharedPtr<Rest>(args, I + 1)...);
193 template <
typename T,
194 typename MINUS_EXTENT =
typename std::remove_extent<T>::type,
195 typename RETURN_TYPE =
typename std::conditional<
196 !std::is_array<MINUS_EXTENT>::value,
197 typename std::remove_all_extents<T>::type*,
198 MINUS_EXTENT*>::type>
199 constexpr auto getDataFromUntypedSharedPtr(
200 const std::vector<Data::UntypedSharedPtr>& args,
size_t idx)
const
202 if constexpr (!std::is_array<T>::value) {
203 return *(args.at(idx).getSharedPointer<
const T>());
209 const std::remove_all_extents_t<T>[]>();
210 return (RETURN_TYPE)returnedPtr.get();
This abstract class is the base class for any instruction to be used in a Program.
Definition: instruction.h:59
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:211
virtual double execute(const std::vector< Data::UntypedSharedPtr > &args) const =0
Execute the Instruction for the given arguments.
Definition: instruction.cpp:81
std::string printTemplate
Definition: instruction.h:110
Template instruction for simplifying the creation of an Instruction from a c++ lambda function.
Definition: lambdaInstruction.h:61
const std::function< double(const First, const Rest...)> func
Function executed for this Instruction.
Definition: lambdaInstruction.h:80
LambdaInstruction()=delete
delete the default constructor.
virtual double execute(const std::vector< Data::UntypedSharedPtr > &args) const override
Inherited from Instruction.
Definition: lambdaInstruction.h:140
LambdaInstruction(std::function< double(First, Rest...)> function, const std::string &printTemplate="")
Constructor of the class LambdaInstruction to create a printable Instruction.
Definition: lambdaInstruction.h:75
Definition: addPrimitiveType.h:48