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)>; // error (evaluated to false) until P2609R3: // this was because 'std::iter_value_t<Proj> &' is the same as 'IntWrapper&' // which is not convertible to 'IntWrapper' (implicitly deleted copy ctor) static_assert(std::indirectly_unary_invocable<decltype(print), Proj>); // if the compile-time check above evaluates to true, then this is 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> でした。 |
要求しなくなった |