Namespaces
Variants

std:: projected

From cppreference.net
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)
헤더에 정의됨 <iterator>
(1)
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 ; // 정의되지 않음

} ;
(C++20부터)
(C++26까지)
template < std:: indirectly_readable I,

std:: indirectly_regular_unary_invocable < I > Proj >

using projected = /*projected-impl*/ < I, Proj > :: /*type*/ ;
(C++26부터)
template < std:: weakly_incrementable I, class Proj >

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

} ;
(2) (C++20부터)
(C++26까지)
헬퍼 템플릿
template < class I, class Proj >

struct /*projected-impl*/
{
struct /*type*/
{
using value_type = std:: remove_cvref_t
< std:: indirect_result_t < Proj & , I >> ;
using difference_type =
std:: iter_difference_t < I > ; // 조건부로 존재
std:: indirect_result_t < Proj & , I > operator * ( ) const ; // 정의되지 않음
} ;

} ;
(3) (C++26부터)
( 설명 전용* )
1) 클래스 (C++26까지) 별칭 (C++26부터) 템플릿 projected indirectly_readable 타입 I 와 호출 가능 객체 타입 Proj 를 새로운 indirectly_readable 타입으로 결합하며, 그 참조 타입은 Proj std:: iter_reference_t < I > 에 적용한 결과입니다.
2) std::incrementable_traits 의 이 특수화는 std :: projected < I, Proj > weakly_incrementable 타입이 되도록 만듭니다. 이는 I 가 또한 weakly_incrementable 타입일 때 적용됩니다.
3) 예상치 못한 argument-dependent lookup 을 방지하기 위해 사용되는 간접적인 계층.
설명 전용 중첩 클래스 /*type*/ 의 경우, 중첩 타입 difference_type I weakly_incrementable 를 모델로 할 때만 존재합니다.

projected 는 호출 가능 객체와 프로젝션을 허용하는 알고리즘들을 제약하는 데에만 사용되므로, operator * ( ) 는 정의되지 않습니다.

목차

템플릿 매개변수

I - 간접적으로 읽을 수 있는 타입
Proj - 역참조된 I 에 적용되는 프로젝션

참고 사항

간접 계층은 I Proj projected 의 연관 클래스가 되는 것을 방지합니다. I 또는 Proj 의 연관 클래스가 불완전한 클래스 타입일 때, 간접 계층은 해당 타입의 정의를 검사하려는 불필요한 시도를 회피하여 하드 에러가 발생하는 것을 방지합니다.

예제

#include <algorithm>
#include <cassert>
#include <functional>
#include <iterator>
template<class T>
struct Holder
{
    T t;
};
struct Incomplete;
using P = Holder<Incomplete>*;
static_assert(std::equality_comparable<P>); // OK
static_assert(std::indirectly_comparable<P*, P*, std::equal_to<>>); // C++26 이전에는 오류
static_assert(std::sortable<P*>); // C++26 이전에는 오류
int main()
{
    P a[10] = {}; // 10개의 널 포인터
    assert(std::count(a, a + 10, nullptr) == 10); // OK
    assert(std::ranges::count(a, a + 10, nullptr) == 10); // C++26 이전에는 오류
}

참고 항목

투영을 통해 indirectly_readable 타입의 값 타입을 계산함
(alias template)