How can I fill in the ???
template<class...Itrs> struct itr_category { typedef /* ??? */ type; };
so that type is the most specialized of iterator_traits<Itrs>::iterator_category... which supports all the Itrs' operations, else failure (like enable_if<false>::type) if there is no single such category?
Most specialized means the most descended type (iterator_category) in the following inheritance:
struct input_iterator_tag { };
struct output_iterator_tag { };
struct forward_iterator_tag : public input_iterator_tag,
public output_iterator_tag { };
struct bidirectional_iterator_tag : public forward_iterator_tag { };
struct random_access_iterator_tag : public bidirectional_iterator_tag { };
So, for example, something like itr_category<InputIterator,OutputIterator,...> would fail.
NB: this is a different hierarchy than defined in std::iterator_traits (see 24.3 or http://en.cppreference.com/w/cpp/iterator/iterator_tags): hereforward_iterator_tag derives from both input_iterator_tag and output_iterator_tag, rather than just the former. This corresponds to the inheritance described in, e.g., the SGI documentation (see http://www.sgi.com/tech/stl/Iterators.html). Feel free to comment on this discrepancy if it is relevant (this is part of a zip iterator implementation, by the way).
First, you'll need a
foldfunction for types, something like this:Then, define a combining function:
And, basically, that's it: