Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/iterator/projected"

From cppreference.com
< cpp‎ | iterator
m
m (fmt)
Line 23: Line 23:
 
@2@ This specialization of {{lc|std::incrementable_traits}} makes {{c|std::projected<I, Proj>}} a {{lconcept|weakly_incrementable}} type when {{tt|I}} is also a {{tt|weakly_incrementable}} type.
 
@2@ This specialization of {{lc|std::incrementable_traits}} makes {{c|std::projected<I, Proj>}} a {{lconcept|weakly_incrementable}} type when {{tt|I}} is also a {{tt|weakly_incrementable}} type.
  
{{tt|projected}} is only used to constrain algorithms that accept callable objects and projections, and hence its {{tt|operator*()}} is not defined.
+
{{tt|projected}} is only used to constrain algorithms that accept callable objects and projections, and hence its {{c|operator*()}} is not defined.
  
 
===Template parameters===
 
===Template parameters===

Revision as of 16:09, 3 October 2021

 
 
Iterator library
Iterator concepts
Iterator primitives
Algorithm concepts and utilities
Indirect callable concepts
Common algorithm requirements
(C++20)
(C++20)
(C++20)
Utilities
projected
(C++20)
Iterator adaptors
Range access
(C++11)(C++14)
(C++14)(C++14)  
(C++11)(C++14)
(C++14)(C++14)  
(C++17)(C++20)
(C++17)
(C++17)
 
Defined in header <iterator>
template< std::indirectly_readable I,

          std::indirectly_regular_unary_invocable<I> Proj >
struct projected {
    using value_type = std::remove_cvref_t<std::indirect_result_t<Proj&, I>>;
    std::indirect_result_t<Proj&, I> operator*() const; // not defined

};
(1) (since C++20)
template< std::weakly_incrementable I, class Proj >

struct incrementable_traits<std::projected<I, Proj>> {
    using difference_type = std::iter_difference_t<I>;

};
(2) (since C++20)
1) Class template projected combines an indirectly_readable type I and a callable object type Proj into a new indirectly_readable type whose reference type is the result of applying Proj to the std::iter_reference_t<I>.
2) This specialization of std::incrementable_traits makes std::projected<I, Proj> a weakly_incrementable type when I is also a weakly_incrementable type.

projected is only used to constrain algorithms that accept callable objects and projections, and hence its operator*() is not defined.

Template parameters

I - an indirectly readable type
Proj - projection applied to a dereferenced I