Is there any practical use for ContiguousIterator?

笑着哭i 提交于 2020-01-14 22:46:08

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!