Skip to content

Commit

Permalink
ranges: from_rangeタグ (#1069)
Browse files Browse the repository at this point in the history
  • Loading branch information
yohhoy committed Oct 19, 2023
1 parent 0ee0833 commit 6e62fb1
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 2 deletions.
4 changes: 2 additions & 2 deletions reference/format/range_formatter/format.md
Expand Up @@ -22,8 +22,8 @@ typename FormatContext::iterator
## 効果
- [`parse()`](parse.md)メンバ関数で解析した書式文字列の指定に基づいて、`r`の値を文字列に変換し、以下を[`ctx.out()`](/reference/format/basic_format_context/out.md)に出力する:
- Range書式として[`s` (文字列として出力)](/reference/format/format.md#range-format-options)が指定された場合、[`basic_string`](/reference/string/basic_string.md)`<charT>(`[`from_range`](/reference/ranges/from_range_t.md.nolink)`, r)`を出力する
- そうでなく、Range書式として[`?s` (デバッグ文字列として出力)](/reference/format/format.md#range-format-options)が指定された場合、[`basic_string`](/reference/string/basic_string.md)`<charT>(`[`from_range`](/reference/ranges/from_range_t.md.nolink)`, r)`に引用符を付け、エスケープシーケンスをエスケープして出力する
- Range書式として[`s` (文字列として出力)](/reference/format/format.md#range-format-options)が指定された場合、[`basic_string`](/reference/string/basic_string.md)`<charT>(`[`from_range`](/reference/ranges/from_range_t.md)`, r)`を出力する
- そうでなく、Range書式として[`?s` (デバッグ文字列として出力)](/reference/format/format.md#range-format-options)が指定された場合、[`basic_string`](/reference/string/basic_string.md)`<charT>(`[`from_range`](/reference/ranges/from_range_t.md)`, r)`に引用符を付け、エスケープシーケンスをエスケープして出力する
- そうでなければ、
- 開きカッコを出力する
- Range `r`の各要素`e`について、
Expand Down
3 changes: 3 additions & 0 deletions reference/ranges.md
Expand Up @@ -404,6 +404,9 @@ range | adaptor(args...)
| 名前 | 説明 | 対応バージョン |
|----------------------|----------------------------------------------------------------|----------------|
| [`to`](ranges/to.md.nolink) | パイプライン記法でRangeからコンテナを構築する (class template) | C++23 |
| [`from_range_t`](ranges/from_range_t.md) | Rangeからコンテナへの変換を示すタグ型 (class) | C++23 |
| [`from_range`](ranges/from_range_t.md) | Rangeからコンテナへの変換を示すタグ値 (variable) | C++23 |
## 実装例
- [libstdc++](https://github.com/gcc-mirror/gcc/blob/master/libstdc%2B%2B-v3/include/std/ranges)
Expand Down
63 changes: 63 additions & 0 deletions reference/ranges/from_range_t.md
@@ -0,0 +1,63 @@
# from_range_t
* utility[meta header]
* std[meta namespace]
* class[meta id-type]
* cpp23[meta cpp]

```cpp
namespace std {
struct from_range_t { explicit from_range_t() = default; };

inline constexpr from_range_t from_range{};
}
```
## 概要
`from_range_t`クラスは、オーバーロードのための空クラスである。
標準ライブラリのコンテナ初期化において、Rangeからコンテナを構築するオーバーロードを定義するためにある。
## 例
```cpp example
#include <iostream>
#include <ranges>
#include <list>
#include <vector>
int main()
{
std::vector vec{1, 2, 3};
std::list lst{std::from_range, vec};
for (int n: lst) {
std::cout << n << std::endl;
}
}
```
* std::from_range[color ff0000]

### 出力
```
1
2
3
```


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

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


## 関連項目
- [`container-compatible-range`](/reference/exposition-only/container-compatible-range.md)コンセプト


## 参照
- [P1206R7 Conversions from ranges to containers](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p1206r7.pdf)

0 comments on commit 6e62fb1

Please sign in to comment.