std::common_iterator
From cppreference.com
C++
Feature test macros (C++20)
Concepts library (C++20)
Metaprogramming library (C++11)
Ranges library (C++20)
Filesystem library (C++17)
Concurrency support library (C++11)
Execution control library (C++26)
Iterator library
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)(C++20)(C++20)(C++23)(C++20)(C++20)
(deprecated in C++17)
(C++20)
(C++20)
(C++20)(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++14)
(C++11)
(C++11)
(C++20)(C++20)
(C++20)(C++20)
(C++20)
common_iterator
(C++20)
(C++20)
(C++23)
(C++23)
(C++23)
(C++23)
(C++23)
(C++11)(C++14)
(C++14)(C++14)
std::common_iterator
(C++20)
(C++20)
(C++20)
(C++20)
Defined in header
<iterator>
template< std::input_or_output_iterator I, std::sentinel_for <I> S >
(since C++20)
requires ( !std::same_as <I, S> && std::copyable <I> )
std::common_iterator
is an iterator I
/ sentinel S
adaptor that may represent a non-common range (where the types of I
and S
differ) as a common_range
, by containing either an iterator or a sentinel, and defining the appropriate equality comparison operators operator==.
std::common_iterator
can be used as a "bridge" between sequences represented by iterator/sentinel pair and legacy functions that expect common_range
-like sequences.
Contents
[edit] Data members
Member name
Definition
[edit] Member functions
[edit] Non-member functions
(C++20)
(function) [edit]
[edit] Helper classes
computes the associated difference type of the std::common_iterator type
(class template specialization) [edit]
(class template specialization) [edit]
provides uniform interface to the properties of the std::common_iterator type
(class template specialization) [edit]
(class template specialization) [edit]
[edit] Example
Run this code
#include <algorithm> #include <iostream> #include <iterator> #include <list> #include <string> template<class ForwardIter> void fire(ForwardIter first, ForwardIter last) { std::copy (first, last, std::ostream_iterator <std::string >{std::cout, " "}); } int main() { std::list <std::string > stars{"Pollux", "Arcturus", "Mira", "Aldebaran", "Sun"}; using IT = std::common_iterator< std::counted_iterator <std::list <std::string >::iterator>, std::default_sentinel_t >; fire(IT(std::counted_iterator (stars.begin(), stars.size() - 1)), IT(std::default_sentinel )); }
Output:
Pollux Arcturus Mira Aldebaran
[edit] References
- C++23 standard (ISO/IEC 14882:2024):
- 23.5.5 Common iterators [iterators.common]
- C++20 standard (ISO/IEC 14882:2020):
- 23.5.4 Common iterators [iterators.common]