
Aleksey Gurtovoy <agurtovoy@meta-comm.com> writes:
Writing an algorithm for _bidirectional_ iterators and making sure that it gets selected for random-access ones as well is somewhat more tricky:
template< typename Iterator > struct algorithm : if_c< iterator_category<Iterator>::type::value >= bidirectional_iterator_tag::value , bidirectional_algorithm<Iterator> , forward_algorithm<Iterator> > { };
but try to write this up assuming that _there is_ an implicit conversion between 'random_access_iterator_tag' and 'bidirectional_iterator_tag', and you'll see that you'll end up with something at least as complex as the above.
If there was a _form_ relationship among MPL iterator tags just like the _inheritance_ relationship among the STL ones, it would be easier to do this with partial specialization. E.g., typedef tag<> forward_iterator_tag; typedef tag<tag<> > bidirectional_iterator_tag; typedef tag<tag<tag<> > > random_access_iterator_tag; Unfortunately, I don't know how to make this look right. A specialization on: template <class T, class Category> struct algorithm< T , tag<tag<Category> > // Bidirectional
{ ... }; doesn't really communicate well. Maybe some built-in SFINAE facilities would help? template <class Iterator, class Enable = void> struct algorithm; template<class Iterator> struct algorithm<Iterator, typename bidirectional_iterator_tag::enable_if<Iterator>::type> { ... }; -- Dave Abrahams Boost Consulting www.boost-consulting.com