Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <type_traits>
- #include <iostream>
- template<typename T, typename Param>
- concept bool UnaryFunction = requires(const T& func) {
- func(std::declval<Param>());
- };
- template<typename IT, typename Func>
- requires UnaryFunction<Func, decltype(*std::declval<IT>())>
- Func for_each(IT first, IT last, Func func)
- {
- for(auto it = first; it != last; ++it) {
- func(*it);
- }
- return func;
- }
- int main() {
- auto numbers = { 1, 2, 3, 4, 5 };
- std::cout << "numbers:\n";
- // gcc 7.2 segfaulted for some reason at the next statement
- for_each(numbers.begin(), numbers.end(), [](auto n) {
- std::cout << n << '\n';
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement