4

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".

Dev Null
  • 4,731
  • 1
  • 30
  • 46
  • @swordfish 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". – Dev Null Sep 11 '18 at 08:42
  • @swordfish I have re-read it (and in fact I referenced it in my original question). Could you please point out how the accepted answer addresses "how contiguous iterator can be used in practice"? – Dev Null Sep 11 '18 at 08:51
  • @Swordfish Comments are not answers. This is a valid question, IMHO (and one I'm curious about the answer to). – jonspaceharper Sep 11 '18 at 14:02
  • 3
    @JonHarper: That comment doesn't even answer this question. It talks about a proposal for C++20 concepts and ranges, which has nothing to do with this C++17 feature. Indeed, that proposal doesn't even propose a way to detect contiguous *iterators*, only contiguous *ranges*. – Nicol Bolas Sep 11 '18 at 14:07

1 Answers1

5

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.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
  • This is because C++17 does not have concepts, but ContiguousIterator establishes the constraints that a concept *would have* (and I presume C++20 does have)? – jonspaceharper Sep 11 '18 at 14:12
  • 1
    @JonHarper: "*This is because C++17 does not have concepts*" Nonsense. You can detect a RandomAccessIterator with SFINAE tricks, even without checking the `random_access_iterator_tag`. It doesn't work because C++17's ContiguousIterator doesn't define *anything* that is statically detectable. The Range integration proposal explicitly adds a `contiguous_iterator_tag`, which now allows them to be detectable. – Nicol Bolas Sep 11 '18 at 14:19