std::from_range, std::from_range_t
From cppreference.com
| ヘッダ <ranges> で定義 |
||
| struct from_range_t { explicit from_range_t() = default; }; |
(C++23から) | |
| inline constexpr std::from_range_t from_range {}; |
(C++23から) | |
std::from_range は、コンテナのコンストラクタに渡すことができる曖昧解消タグであり、コンテナのメンバーが範囲構築されることを示します。
対応する型 std::from_range_t は、コンストラクタのパラメータリストで使用して、意図されたタグに一致させることができます。
目次 |
[編集] 標準ライブラリ
以下の標準ライブラリ型は、コンストラクタで std::from_range_t 型を使用しています。
コンテナライブラリ | |
| (C++23) |
範囲から vector を構築します。( std::vector<T,Allocator> の public メンバ関数)
|
| (C++26) |
範囲から inplace_vector を構築します。( std::inplace_vector<T,N> の public メンバ関数)
|
| (C++23) |
範囲から deque を構築します。( std::deque<T,Allocator> の public メンバ関数)
|
| (C++23) |
範囲から forward_list を構築します。( std::forward_list<T,Allocator> の public メンバ関数)
|
| (C++23) |
範囲から list を構築します。( std::list<T,Allocator> の public メンバ関数)
|
| (C++23) |
範囲から set を構築します。( std::set<Key,Compare,Allocator> の public メンバ関数)
|
| (C++23) |
範囲から map を構築します。( std::map<Key,T,Compare,Allocator> の public メンバ関数)
|
| (C++23) |
範囲から multiset を構築します。( std::multiset<Key,Compare,Allocator> の public メンバ関数)
|
| (C++23) |
範囲から multimap を構築します。( std::multimap<Key,T,Compare,Allocator> の public メンバ関数)
|
| (C++23) |
範囲から unordered_set を構築します。( std::unordered_set<Key,Hash,KeyEqual,Allocator> の public メンバ関数)
|
| (C++23) |
範囲から unordered_map を構築します。( std::unordered_map<Key,T,Hash,KeyEqual,Allocator> の public メンバ関数)
|
| (C++23) |
範囲から unordered_multiset を構築します。( std::unordered_multiset<Key,Hash,KeyEqual,Allocator> の public メンバ関数)
|
| (C++23) |
範囲から unordered_multimap を構築します。( std::unordered_multimap<Key,T,Hash,KeyEqual,Allocator> の public メンバ関数)
|
| (C++23) |
範囲から priority_queue を構築します。( std::priority_queue<T,Container,Compare> の public メンバ関数)
|
| (C++23) |
範囲から queue を構築します。( std::queue<T,Container> の public メンバ関数)
|
| (C++23) |
範囲から stack を構築します。( std::stack<T,Container> の public メンバ関数)
|
| (C++23) |
範囲から flat_set を構築します。( std::flat_set<Key,Compare,KeyContainer> の public メンバ関数)
|
| (C++23) |
範囲から flat_map を構築します。( std::flat_map<Key,T,Compare,KeyContainer,MappedContainer> の public メンバ関数)
|
| (C++23) |
範囲から flat_multiset を構築します。( std::flat_multiset<Key,Compare,KeyContainer> の public メンバ関数)
|
| (C++23) |
範囲から flat_multimap を構築します。( std::flat_multimap<Key,T,Compare,KeyContainer,MappedContainer> の public メンバ関数)
|
文字列ライブラリ | |
| (C++23) |
範囲から basic_string を構築します。( std::basic_string<CharT,Traits,Allocator> の public メンバ関数)
|
[編集] 注記
| 機能テストマクロ | 値 | 規格 | 機能 |
|---|---|---|---|
__cpp_lib_containers_ranges |
202202L |
(C++23) | コンストラクタにタグを付けて、コンテナ互換範囲から構築します。 |
[編集] 例
このコードを実行
#include <cassert> #include <string> int main() { #ifdef __cpp_lib_containers_ranges auto const range = {0x43, 43, 43}; std::string str{std::from_range, range}; // uses tagged constructor assert(str == "C++"); #endif }
[編集] 関連項目
| インプレース構築タグ (タグ) | |
| 範囲の要素がソートされていることを示す (一意性は不要) (タグ) | |
| (C++23) |
範囲の要素がソートされ、一意であることを示す (タグ) |
| (C++23) |
入力rangeから新しい非viewオブジェクトを構築する (関数テンプレート) |