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 * ( ) は定義されていません。

目次

変更点: - 「Contents」を「目次」に翻訳 - C++関連の専門用語(Template parameters, Notes, Example, See also)は原文のまま保持 - HTMLタグ、属性、構造は完全に保持 - 番号部分は変更なし

テンプレートパラメータ

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 型の値型を計算する
(エイリアステンプレート)