The simplest code is the best asker:
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
vector<int> coll;
for_each(coll.begin(), coll.end(), [](vector<int>::value_type n) -> void {});
return 0;
}
Here, vector<int>::value_type n is tedious. I want to have an auto-like utility to deduce the right type of n automatically; just like the following:
for_each(coll.begin(), coll.end(), [](auto_type n) -> void {});
To be more greedy, I want auto_type to take an argument used to deduce the right type of n. The argument can be a (smart) pointer or reference to the container, or an iterator of the container.
Dear gurus, how to implement that?
You don’t have to declare the void return in that function. You could use decltype, like,
decltype(coll[0]).Edit: