
20 Aug
2014
20 Aug
'14
1:24 p.m.
On 20/08/14 14:33, Peter Dimov wrote:
Mathias Gaunard wrote:
AFAIK an iterator T doesn't have to provide an iterator_category typedef, only std::iterator_traits<T> does.
That's true. However, pre-C++14, iterator_traits<It>::iterator_category causes a hard error (not SFINAE) when It is not an iterator. In C++14, the default iterator_traits<It> is empty when It doesn't have the nested types. So
is_iterator<It, tag> :- is_convertible<X::iterator_category, tag> where X is iterator_traits<It> in C++14, It otherwise
is the best we can do.
Alternatively, Boost could provide a boost::iterator_traits that always behaves like C++14's (and would even be an alias to std::iterator_traits in C++14) This would be more clean to me that the code posted above.