I wrote this code in order to simplify the use of std::for_each when I need to go through an entire collection:
namespace ranges {
template<typename Range, typename Function>
Function for_each(Range &range, Function f) {
return std::for_each(std::begin(range), std::end(range), f);
}
}
So that I can use it like this:
ranges::for_each(a, foo);
This had worked for me and since I also have to sort entire collections, I thought it would be a good idea to implement the same process with std::sort, just like this:
namespace ranges {
template<typename Range, typename Function>
Function for_each(Range &range, Function f) {
return std::for_each(std::begin(range), std::end(range), f);
}
template<typename Range, typename Function>
Function sort(Range &range, Function f) {
return std::sort(std::begin(range), std::end(range), f);
}
}
When I add that code to my namespace, the compiler throws me the following error message:
error: void value not ignored as it ought to be
Is there a way to achieve what I want to do? I'm using the C++17 standard and g++.exe (Rev1, Built by MSYS2 project) 11.2.0 to compile.