问题
C++17 introduced ContiguousIterator, but there's no corresponding contiguous_iterator_tag.
Is there any practical use for ContiguousIterator
if it can't be checked/enforced via std::iterator_traits?
This question is different from contiguous iterator detection as it's not "why it doesn't have a tag", but "how it can be used if it doesn't have a tag".
回答1:
Named requirements in C++17 are first and foremost notation. They only correlate to detectable things in the language if they impose requirements which are detectable. And ContiguousIterator does not impose detectable requirements on types which implement them.
So the most practical thing ContiguousIterator allows you to do is write "you must pass a ContiguousIterator" in your documentation, with the understanding that the reader will track down the specific details of that term. But no, ContiguousIterator as defined in C++17 does not permit you to write anything which could statically detect the difference between ContiguousIterators and RandomAccessIterators that are not contiguous.
来源:https://stackoverflow.com/questions/52271797/is-there-any-practical-use-for-contiguousiterator