The following meta-function computes if a given type is a random access iterator:
template <class I>
struct is_random_access
: boost::is_convertible
< typename boost::iterator_traversal<I>::type
, boost::random_access_traversal_tag
>
{};
Now of course, this doesn't work if I
is not an iterator at all, as there is no boost::iterator_traversal<I>
is defined.
Two independent questions:
- How to make
is_random_access
return false (rather than fail to compile) whenI
is not an iterator? - Is this a good way to detect if an iterator is random access traverseable?
Aucun commentaire:
Enregistrer un commentaire