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/for_each | |
add: graphs et rushs
Diffstat (limited to 'graphs/cpp/for_each')
| -rw-r--r-- | graphs/cpp/for_each/for_each.hh | 6 | ||||
| -rw-r--r-- | graphs/cpp/for_each/for_each.hxx | 9 | ||||
| -rw-r--r-- | graphs/cpp/for_each/main.cc | 10 |
3 files changed, 25 insertions, 0 deletions
diff --git a/graphs/cpp/for_each/for_each.hh b/graphs/cpp/for_each/for_each.hh new file mode 100644 index 0000000..195c3c6 --- /dev/null +++ b/graphs/cpp/for_each/for_each.hh @@ -0,0 +1,6 @@ +#pragma once + +template <class IT, class F> +void my_foreach(IT begin, IT end, auto fun); + +#include "for_each.hxx"
\ No newline at end of file diff --git a/graphs/cpp/for_each/for_each.hxx b/graphs/cpp/for_each/for_each.hxx new file mode 100644 index 0000000..dcfa0fa --- /dev/null +++ b/graphs/cpp/for_each/for_each.hxx @@ -0,0 +1,9 @@ +#pragma once +#include "for_each.hh" + +template <class IT, class F> +void my_foreach(IT begin, IT end, F fun) +{ + for (; begin != end; ++begin) + fun(*begin); +}
\ No newline at end of file diff --git a/graphs/cpp/for_each/main.cc b/graphs/cpp/for_each/main.cc new file mode 100644 index 0000000..08da792 --- /dev/null +++ b/graphs/cpp/for_each/main.cc @@ -0,0 +1,10 @@ +#include <iostream> + +#include "for_each.hh" + +int main() +{ + auto v = { 'M', 'y', 'S', 'T', 'L', '\n' }; + + my_foreach(v.begin(), v.end(), [](auto c) { std::cout << c; }); +} |
