Skip to content

Commit

Permalink
functional/invoke_r: P2136R3対応(#1055)
Browse files Browse the repository at this point in the history
  • Loading branch information
yohhoy committed Jan 17, 2023
1 parent 5823043 commit 5a087a0
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lang/cpp23.md
Expand Up @@ -187,7 +187,7 @@ C++23とは、2023年中に改訂される予定の、C++バージョンの通


### 関数オブジェクト
- [`std::invoke()`](/reference/functional/invoke.md)の戻り値型を指定するバージョンである[`std::invoke_r()`](/reference/functional/onvoke_r.md.nolink)を追加
- [`std::invoke()`](/reference/functional/invoke.md)の戻り値型を指定するバージョンである[`std::invoke_r()`](/reference/functional/invoke_r.md)を追加
- ムーブのみ可能な[`std::function`](/reference/functional/function.md)クラスと等価な機能をもつ[`std::move_only_function`](/reference/functional/move_only_function.md.nolink)クラスを追加
- ユーザー定義のRangeアダプタがパイプライン演算子 `|` をサポートしやすくするために、末尾から引数を束縛する[`std::bind_back()`](/reference/functional/bind_back.md.nolink)関数を追加

Expand Down
5 changes: 3 additions & 2 deletions reference/concepts/Invoke.md
Expand Up @@ -6,8 +6,8 @@

C++における関数呼び出しという性質を抽象化しまとめた、仮想操作 *INVOKE* を定義する。

C++17からは、本仮想操作を実体化した[`invoke`](/reference/functional/invoke.md)関数テンプレートが提供される。

- C++17からは、仮想操作 *INVOKE* を実体化した[`std::invoke`](/reference/functional/invoke.md)関数テンプレートが提供される。
- C++23からは、仮想操作 *INVOKE<R>* を実体化した[`std::invoke_r`](/reference/functional/invoke_r.md)関数テンプレートが提供される。

## 用語定義
- *call-signature* とは、戻り値型に続けて丸括弧の中に0個以上の引数型を並べたものである。 *cf.* `int ( std::string, int )`
Expand Down Expand Up @@ -78,3 +78,4 @@ C++17からは、本仮想操作を実体化した[`invoke`](/reference/function
## 参照
- [P0777R1 Treating Unnecessary `decay`](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0777r1.pdf)
- C++20から`decay_t``remove_cvref_t`へ変更。
- [P2136R3 `invoke_r`](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p2136r3.html)
10 changes: 5 additions & 5 deletions reference/functional/invoke.md
Expand Up @@ -130,11 +130,11 @@ int main()


## 関連項目
- [invoke_result](/reference/type_traits/invoke_result.md)
- [is_invocable](/reference/type_traits/is_invocable.md)
- [is_invocable_r](/reference/type_traits/is_invocable_r.md)
- [is_nothrow_invocable](/reference/type_traits/is_nothrow_invocable.md)
- [is_nothrow_invocable_r](/reference/type_traits/is_nothrow_invocable_r.md)
- [`invoke_r`](invoke_r.md)
- [`invoke_result`](/reference/type_traits/invoke_result.md)
- [`is_invocable`](/reference/type_traits/is_invocable.md)
- [`is_nothrow_invocable`](/reference/type_traits/is_nothrow_invocable.md)


## 参照
- [C++1z INVOKEコンセプトに従った関数呼び出しをするinvoke()関数 - Faith and Brave - C++で遊ぼう](https://faithandbrave.hateblo.jp/entry/2016/09/07/173344)
Expand Down
67 changes: 67 additions & 0 deletions reference/functional/invoke_r.md
@@ -0,0 +1,67 @@
# invoke_r
* functional[meta header]
* function template[meta id-type]
* std[meta namespace]
* cpp23[meta cpp]

```cpp
namespace std {
template <class R, class F, class... Args>
constexpr R invoke_r(F&& f, Args&&... args)
noexcept(is_nothrow_invocable_r_v<R, F, Args...>);
}
```
* is_nothrow_invocable_r_v[link /reference/type_traits/is_nothrow_invocable_r.md]
## 概要
関数呼び出し可能なオブジェクト`f`とその引数`args...`の組み合わせで[*INVOKE*](/reference/concepts/Invoke.md)要件に従った関数呼び出しを行う。
`R`が(CV修飾された)`void`でなければ、戻り値は`R`型へ暗黙変換される。
## テンプレートパラメータ制約
[`is_­invocable_­r_­v`](/reference/type_traits/is_invocable_r.md)`<R, F, Args...>`が`true`
## 戻り値
[`INVOKE<R>`](/reference/concepts/Invoke.md)`(`[`std::forward`](/reference/utility/forward.md)`<F>(f),` [`std::forward`](/reference/utility/forward.md)`<Args>(args)...)`
## 例
```cpp example
#include <iostream>
#include <functional>
// ASCIIコード 0x43 == 'C'
int ch() { return 0x43; }
int main()
{
std::cout << std::invoke_r<char>(ch()) << std::endl;
}
```
* std::invoke_r[color ff0000]

### 出力例
```
C
```


## バージョン
### 言語
- C++23

### 処理系
- [Clang](/implementation.md#clang): ??
- [GCC](/implementation.md#gcc): ??
- [Visual C++](/implementation.md#visual_cpp): ??


## 関連項目
- [`invoke`](invoke.md)
- [`is_invocable_r`](/reference/type_traits/is_invocable_r.md)
- [`is_nothrow_invocable_r`](/reference/type_traits/is_nothrow_invocable_r.md)


## 参照
- [P2136R3 `invoke_r`](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p2136r3.html)

0 comments on commit 5a087a0

Please sign in to comment.