Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/named req/ContiguousIterator"

From cppreference.com
< cpp‎ | named req
(Notes: note fancy pointers and std::contiguous_iterator)
m (+C++17 in title)
 
(4 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{cpp/named req/title|ContiguousIterator}}
+
{{cpp/named req/title|ContiguousIterator|notes={{mark since c++17}}}}
 
{{cpp/named req/navbar}}
 
{{cpp/named req/navbar}}
  
A {{named req|ContiguousIterator}} is a {{named req|RandomAccessIterator}} whose logically adjacent elements are also physically adjacent in memory.
+
A {{named req|ContiguousIterator}} is a {{named req|Iterator}} whose logically adjacent elements are also physically adjacent in memory.
  
 
A pointer to an element of an array satisfies all requirements of {{named req/core|ContiguousIterator}}.
 
A pointer to an element of an array satisfies all requirements of {{named req/core|ContiguousIterator}}.
  
 
===Requirements===
 
===Requirements===
The type {{tt|It}} satisfies {{named req/core|ContiguousIterator}} if
+
The type {{c|It}} satisfies {{named req/core|ContiguousIterator}} if
 
+
* The type {{c|It}} satisfies {{named req|Iterator}}
* The type {{tt|It}} satisfies {{named req|RandomAccessIterator}}
+
  
 
And, for every
 
And, for every
* {{tt|a}}, a dereferenceable iterator of type {{tt|It}}
+
* {{c|a}}, a dereferenceable iterator of type {{c|It}}
* {{tt|n}}, an integral value
+
* {{c|n}}, an integral value
  
 
such that  
 
such that  
Line 24: Line 23:
  
 
===Standard library===
 
===Standard library===
 
 
The following standard library types are {{named req|ContiguousIterator}}s.
 
The following standard library types are {{named req|ContiguousIterator}}s.
  
Line 30: Line 28:
 
* {{ltt|cpp/string/basic_string_view|basic_string_view::iterator}}.
 
* {{ltt|cpp/string/basic_string_view|basic_string_view::iterator}}.
 
* {{ltt|cpp/string/basic_string|basic_string::iterator}}.
 
* {{ltt|cpp/string/basic_string|basic_string::iterator}}.
* {{ltt|cpp/container/vector|vector::iterator}} for {{lc|value_type}} other than {{lc|bool}}.
+
* {{ltt|cpp/container/vector|vector::iterator}} for {{tt|value_type}} other than {{c|bool}}.
* The return type of {{ltt|cpp/numeric/valarray/begin2|begin{{dsc small|(valarray)}}}} and {{ltt|cpp/numeric/valarray/end2|end{{dsc small|(valarray)}}}}
+
* The return type of {{ltt|cpp/numeric/valarray/begin2|begin{{dsc small|(valarray)}}}} and {{ltt|cpp/numeric/valarray/end2|end{{dsc small|(valarray)}}}}.
  
 
===Notes===
 
===Notes===
Line 37: Line 35:
  
 
{{rrev|since=c++20|
 
{{rrev|since=c++20|
{{named req/core|ContiguousIterator}} is partially replaced with the {{lconcept|contiguous_iterator}} concept: iterator types in the standard library that are required to satisfy {{named req/core|ContiguousIterator}} in C++17 are also required to model {{tt|contiguous_iterator}} in C++20.
+
{{named req/core|ContiguousIterator}} is replaced with the {{lconcept|contiguous_iterator}} concept: iterator types in the standard library that are required to satisfy {{named req/core|ContiguousIterator}} in C++17 are required to model {{tt|contiguous_iterator}} in C++20.
 
}}
 
}}
  
 
===See also===
 
===See also===
 
{{dsc begin}}
 
{{dsc begin}}
{{dsc inc | cpp/iterator/dsc ContiguousIterator}}
+
{{dsc inc | cpp/iterator/dsc contiguous_iterator}}
 +
{{see_also_iterator_library}}
 
{{dsc end}}
 
{{dsc end}}
* [[cpp/iterator|Iterator library]]
 
  
 
{{langlinks|de|es|fr|it|ja|pt|ru|zh}}
 
{{langlinks|de|es|fr|it|ja|pt|ru|zh}}

Latest revision as of 12:02, 8 November 2022

 
 
C++ named requirements
 

A LegacyContiguousIterator is a LegacyIterator whose logically adjacent elements are also physically adjacent in memory.

A pointer to an element of an array satisfies all requirements of LegacyContiguousIterator.

Contents

[edit] Requirements

The type It satisfies LegacyContiguousIterator if

And, for every

  • a, a dereferenceable iterator of type It
  • n, an integral value

such that

  • a + n is a valid and dereferenceable iterator value

then

[edit] Standard library

The following standard library types are LegacyContiguousIterators.

[edit] Notes

Fancy pointer to object types are also required to satisfy LegacyContiguousIterator.

LegacyContiguousIterator is replaced with the contiguous_iterator concept: iterator types in the standard library that are required to satisfy LegacyContiguousIterator in C++17 are required to model contiguous_iterator in C++20.

(since C++20)

[edit] See also

specifies that a random_access_iterator is a contiguous iterator, referring to elements that are contiguous in memory
(concept) [edit]
Iterator library provides definitions for iterators, iterator traits, adaptors, and utility functions