From a7d1db2f9fd3c669768d52a2cf6a89598b96b28a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kevin=20H=C3=B6llring?= <kevin.hoellring@fau.de> Date: Mon, 25 Nov 2019 01:51:53 +0100 Subject: [PATCH] Add lambda wrapper from exercise 3 --- include/lambda_wrapper.h | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 include/lambda_wrapper.h diff --git a/include/lambda_wrapper.h b/include/lambda_wrapper.h new file mode 100644 index 0000000..9c0eda0 --- /dev/null +++ b/include/lambda_wrapper.h @@ -0,0 +1,38 @@ +#ifndef __LAMBDA_WRAPPER_H__ +#define __LAMBDA_WRAPPER_H__ + +#include <cassert> +#include <vector> + +#include <cmath> +#include <cstdint> +#include <iostream> +#include "function.h" +#include <functional> + +namespace numerics { + + template <typename argtype, typename valtype> + class LambdaWrapper : public Function<argtype, valtype> { + public: + LambdaWrapper(std::function<valtype(argtype)> func, size_t indim, size_t outdim) : input_dim(indim), output_dim(outdim), f(func) {} + + virtual valtype operator()(argtype arg) const override { + return f(arg); + }; + + virtual size_t input_dimension() const override { + return input_dim; + } + + virtual size_t output_dimension() const override { + return output_dim; + } + protected: + size_t input_dim, output_dim; + std::function < valtype(argtype)> f; + }; + +}; // namespace numerics + +#endif -- GitLab