In C++98, I typically use the following to declare a variable in an iterator's value type:
typename std::iterator_traits<Iterator>::value_type value;
In C++11 we have decltype and I had thought the easiest way to deduce the value type is:
decltype(*iterator) value;
Unfortunately for most iterators, the type of *iterator is value_type& and not value_type. Any ideas, without the type modification classes, how to massage the above into yielding the value_type (and not any reference)?
I don't think the question is unreasonable given that the following is fairly robust but ends up creating another variable.
auto x = *iterator;
decltype(x) value;
Also note that I really want the deduced type and not just an instance e.g. if I wanted to declare a std::vector of these values.