diff options
| author | Martial Simon <msimon_fr@hotmail.com> | 2025-09-15 01:08:27 +0200 |
|---|---|---|
| committer | Martial Simon <msimon_fr@hotmail.com> | 2025-09-15 01:08:27 +0200 |
| commit | c9b6b9a5ca082fe7c1b6f58d7713f785a9eb6a5c (patch) | |
| tree | 3e4f42f93c7ae89a364e4d51fff6e5cec4e55fa9 /graphs/cpp/forward_multiplication | |
add: graphs et rushs
Diffstat (limited to 'graphs/cpp/forward_multiplication')
3 files changed, 35 insertions, 0 deletions
diff --git a/graphs/cpp/forward_multiplication/forward_multiplication.cc b/graphs/cpp/forward_multiplication/forward_multiplication.cc new file mode 100644 index 0000000..72abc91 --- /dev/null +++ b/graphs/cpp/forward_multiplication/forward_multiplication.cc @@ -0,0 +1,7 @@ +#include "forward_multiplication.hh" +// +// Created by martial.simon on 2/26/25. +// +outer_lambda_type mult_by = [](int val) { + return [val](int mul) { return val * mul; }; +};
\ No newline at end of file diff --git a/graphs/cpp/forward_multiplication/forward_multiplication.hh b/graphs/cpp/forward_multiplication/forward_multiplication.hh new file mode 100644 index 0000000..9cca5e6 --- /dev/null +++ b/graphs/cpp/forward_multiplication/forward_multiplication.hh @@ -0,0 +1,7 @@ +#pragma once + +#include <functional> + +using inner_lambda_type = const std::function<int(int rhs)>; +using outer_lambda_type = const std::function<inner_lambda_type(int lhs)>; +extern outer_lambda_type mult_by; diff --git a/graphs/cpp/forward_multiplication/forward_multiplication_test.cc b/graphs/cpp/forward_multiplication/forward_multiplication_test.cc new file mode 100644 index 0000000..21be1a6 --- /dev/null +++ b/graphs/cpp/forward_multiplication/forward_multiplication_test.cc @@ -0,0 +1,21 @@ +#include <iostream> +#include <string> + +#include "forward_multiplication.hh" + +int main(int argc, char** argv) +{ + if (argc != 3) + { + std::cerr << "Usage: " << argv[0] << " 'number' 'number'" << std::endl; + return 1; + } + + auto lhs = std::stoi(argv[1]); + auto rhs = std::stoi(argv[2]); + + auto mult_by_lhs = mult_by(lhs); + + std::cout << mult_by(lhs)(rhs) << '\n'; + std::cout << mult_by_lhs(rhs) << std::endl; +} |
