GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
std::iterator_traits(3) C++ Standard Libary std::iterator_traits(3)

std::iterator_traits - std::iterator_traits


Defined in header <iterator>
template< std::input_iterator I >


requires /* see below */
struct iterator_traits<std::counted_iterator<I>> :
std::iterator_traits<I> { (since C++20)
using pointer = std::conditional_t<std::contiguous_iterator<I>,
std::add_pointer_t<std::iter_reference_t<I>>,
void>;


};


Inherits the properties from customized (generated from either a standard partial
specialization or a program-defined specialization) std::iterator_traits<I>, with
the member type pointer adjusted, where I models input_iterator.


Notably, the iterator_concept (if present) and iterator_category are inherited from
std::iterator_traits<I>.


The condition in the requires-clause is true if and only if std::iterator_traits<I>
is not generated from the primary template.


Before P2259R1, this specialization is used even if std::iterator_traits<I> is
generated from the primary template. As a result, when testing
std::counted_iterator<I> against an iterator concept (e.g. forward_iterator), the
determination of /*ITER_CONCEPT*/ does not take I::iterator_concept into account,
and thus std::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 of std::iterator_traits for
pointer types, std::counted_iterator, and std::common_iterator.

// Run this code


#include <iterator>
#include <type_traits>
#include <list>
#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>());
}


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 constraint added
pointer is unconditionally defined as void


iterator_traits provides uniform interface to the properties of an iterator
(class template)

2022.07.31 http://cppreference.com

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.