std:: indirectly_unary_invocable, std:: indirectly_regular_unary_invocable
|
ヘッダーで定義
<iterator>
|
||
std::indirectly_unary_invocable
|
||
|
template
<
class
F,
class
I
>
concept indirectly_unary_invocable
=
|
(C++20以降) | |
std::indirectly_regular_unary_invocable
|
||
|
template
<
class
F,
class
I
>
concept indirectly_regular_unary_invocable
=
|
(C++20以降) | |
indirectly_unary_invocable
および
indirectly_regular_unary_invocable
コンセプトは、引数として(正則)単項呼び出し可能オブジェクトを呼び出すアルゴリズムの要件を規定します。これらのコンセプトと
std::invocable
の主な違いは、これらが
I
自体ではなく、
I
が参照する型に適用される点です。
注記
indirectly_unary_invocable
と
indirectly_regular_unary_invocable
の区別は純粋に意味論的なものです。
例
#include <algorithm> #include <iterator> #include <print> #include <ranges> struct IntWrapper { int i; explicit IntWrapper(int i) : i(i) {} IntWrapper(IntWrapper&&) = default; IntWrapper& operator=(IntWrapper&&) = default; }; int main() { auto ints = std::views::iota(1, 10); auto print = [] (IntWrapper w) { std::print("{} ", w.i); }; auto wrap = [] (int i) { return IntWrapper{i}; }; using Proj = std::projected<decltype(ints.begin()), decltype(wrap)>; // P2609R3 までエラー(false と評価されていた): // これは 'std::iter_value_t<Proj> &' が 'IntWrapper&' と同じであり、 // これは 'IntWrapper' に変換できないため(暗黙的に削除されたコピーコンストラクタ) static_assert(std::indirectly_unary_invocable<decltype(print), Proj>); // 上記のコンパイル時チェックが true と評価される場合、これは well-formed: std::ranges::for_each(ints, print, wrap); }
出力:
1 2 3 4 5 6 7 8 9
不具合報告
以下の動作変更の欠陥報告書は、以前に公開されたC++規格に対して遡及的に適用されました。
| DR | 適用対象 | 公開時の動作 | 正しい動作 |
|---|---|---|---|
| P2609R3 | C++20 |
一部の要件が
std::
iter_value_t
<
I
>
&
に基づいて定義されており、プロジェクションの誤った扱いにより F & との非互換性が生じていた |
/*indirect-value-t*/
<
I
>
に基づいて定義し、そのようなプロジェクションを正しく扱う |
| P2997R1 | C++20 |
対応するコンセプトが
F
&
に対して
invocable
および
regular_invocable
の要件をそれぞれ要求していた(
std::
iter_common_reference_t
<
I
>
と共に)
|
要求しない |