std::from_range, std::from_range_t
來自 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> 的公共成員函式)
|
| (C++26) |
從範圍構造 inplace_vector( std::inplace_vector<T,N> 的公共成員函式)
|
| (C++23) |
從範圍構造 deque( std::deque<T,Allocator> 的公共成員函式)
|
| (C++23) |
從範圍構造 forward_list( std::forward_list<T,Allocator> 的公共成員函式)
|
| (C++23) |
從範圍構造 list( std::list<T,Allocator> 的公共成員函式)
|
| (C++23) |
從範圍構造 set( std::set<Key,Compare,Allocator> 的公共成員函式)
|
| (C++23) |
從範圍構造 map( std::map<Key,T,Compare,Allocator> 的公共成員函式)
|
| (C++23) |
從範圍構造 multiset( std::multiset<Key,Compare,Allocator> 的公共成員函式)
|
| (C++23) |
從範圍構造 multimap( std::multimap<Key,T,Compare,Allocator> 的公共成員函式)
|
| (C++23) |
從範圍構造 unordered_set( std::unordered_set<Key,Hash,KeyEqual,Allocator> 的公共成員函式)
|
| (C++23) |
從範圍構造 unordered_map( std::unordered_map<Key,T,Hash,KeyEqual,Allocator> 的公共成員函式)
|
| (C++23) |
從範圍構造 unordered_multiset( std::unordered_multiset<Key,Hash,KeyEqual,Allocator> 的公共成員函式)
|
| (C++23) |
從範圍構造 unordered_multimap( std::unordered_multimap<Key,T,Hash,KeyEqual,Allocator> 的公共成員函式)
|
| (C++23) |
從範圍構造 priority_queue( std::priority_queue<T,Container,Compare> 的公共成員函式)
|
| (C++23) |
從範圍構造 queue( std::queue<T,Container> 的公共成員函式)
|
| (C++23) |
從範圍構造 stack( std::stack<T,Container> 的公共成員函式)
|
| (C++23) |
從範圍構造 flat_set( std::flat_set<Key,Compare,KeyContainer> 的公共成員函式)
|
| (C++23) |
從範圍構造 flat_map( std::flat_map<Key,T,Compare,KeyContainer,MappedContainer> 的公共成員函式)
|
| (C++23) |
從範圍構造 flat_multiset( std::flat_multiset<Key,Compare,KeyContainer> 的公共成員函式)
|
| (C++23) |
從範圍構造 flat_multimap( std::flat_multimap<Key,T,Compare,KeyContainer,MappedContainer> 的公共成員函式)
|
字串庫 | |
| (C++23) |
從範圍構造 basic_string( std::basic_string<CharT,Traits,Allocator> 的公共成員函式)
|
[編輯] 注意
| 特性測試宏 | 值 | 標準 | 特性 |
|---|---|---|---|
__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 }
[編輯] 參閱
| 原地構造標籤 (tag) | |
| 表示範圍的元素已排序(不要求唯一性) (tag) | |
| (C++23) |
表示範圍的元素已排序且唯一 (tag) |
| (C++23) |
從輸入範圍構造新的非檢視物件 (函式模板) |