From 74318f3bda273917a38a9b838a069d33c5121ba2 Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Sun, 12 Jan 2025 19:17:25 +0100 Subject: [PATCH] Apply-related code --- apply/Makefile | 5 +++++ apply/main.cc | 30 ++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 apply/Makefile create mode 100644 apply/main.cc diff --git a/apply/Makefile b/apply/Makefile new file mode 100644 index 0000000..60bee61 --- /dev/null +++ b/apply/Makefile @@ -0,0 +1,5 @@ +# Only define if needed: +# TARGET = main.elf +# SRCS = main.cc + +include ../config.mk diff --git a/apply/main.cc b/apply/main.cc new file mode 100644 index 0000000..62f64cf --- /dev/null +++ b/apply/main.cc @@ -0,0 +1,30 @@ +#include +#include + +// This code will kill your mood, steal your cat and invade russia + +template +auto apply(const F &f) -> decltype(f()) { + return f(); +} + +class Foo { + int val; + + public: + Foo() = default; + + Foo(const int &x) + : val(x) {} + + Foo operator()() const { return Foo(2 * val); } + + operator int() const { return val; } +}; + +int main() { + std::vector v = {1, 2, 3, 4, 5}; + std::vector b; + + std::transform(v.begin(), v.end(), std::back_inserter(b), apply); +}