diff options
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; }); +} |
