Inherits the properties from customized (generated from either a standard partial specialization or a program-defined specialization)std::iterator_traits<I>, with the member typepointer adjusted, whereI modelsinput_iterator.
Notably, theiterator_concept (if present) anditerator_category are inherited fromstd::iterator_traits<I>.
The condition in the requires-clause istrue if and only ifstd::iterator_traits<I> is not generated from the primary template.
BeforeP2259R1, this specialization is used even ifstd::iterator_traits<I> is generated from the primary template. As a result, when testingstd::counted_iterator<I> against an iterator concept (e.g.forward_iterator), the determination of/*ITER_CONCEPT*/ does not takeI::iterator_concept into account, and thusstd::counted_iterator<I> sometimes erroneously behaves as if it cannot model that concept. This incorrect behavior is implemented in libstdc++ prior to 10.4, and in MSVC STL prior to VS 2022 17.0 Preview 3.
The standard library provides partial specializations ofstd::iterator_traits for pointer types,std::counted_iterator, andstd::common_iterator.
[edit]Example
#include <iterator>#include <list>#include <type_traits>#include <vector> int main(){std::vector v{1,2,3,4};std::list l{1,2,3,4};std::counted_iterator iv{v.begin(),3};std::counted_iterator il{l.begin(),3}; static_assert(std::is_same<int*,std::iterator_traits<decltype(iv)>::pointer>()); static_assert(std::is_same<void,std::iterator_traits<decltype(il)>::pointer>());}[edit]Defect reports
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
| DR | Applied to | Behavior as published | Correct behavior |
|---|
| P2259R1 | C++20 | there's no requires-clause
pointer is unconditionally defined asvoid | constraint added |
[edit]See also
| provides uniform interface to the properties of an iterator (class template) |