std::from_range, std::from_range_t
From cppreference.com
C++
Feature test macros (C++20)
Concepts library (C++20)
Metaprogramming library (C++11)
Ranges library (C++20)
Filesystem library (C++17)
Concurrency support library (C++11)
Execution control library (C++26)
Ranges library
constructs the
(public member function of
constructs the
(public member function of
constructs the
(public member function of
constructs the
(public member function of
constructs the
(public member function of
constructs the
(public member function of
constructs the
(public member function of
constructs the
(public member function of
constructs the
(public member function of
constructs the
(public member function of
constructs the
(public member function of
constructs the
(public member function of
constructs the
(public member function of
constructs the
(public member function of
constructs the
(public member function of
constructs the
(public member function of
constructs the
(public member function of
constructs the
(public member function of
constructs the
(public member function of
constructs the
(public member function of
constructs the
(public member function of
constructs the
(public member function of
(C++23)(C++23)
(C++23)(C++23)
(C++23)(C++23)
(C++26)(C++26)
(C++23)(C++23)
(C++23)(C++23)
(C++23)(C++23)
(C++23)(C++23)
(C++23)(C++23)
(C++23)
(C++23)(C++23)
(C++23)
(C++23)(C++23)
(C++23)(C++23)
(C++23)(C++23)
(C++23)(C++23)
(C++23)(C++23)
(C++23)
Defined in header
<ranges>
struct from_range_t { explicit from_range_t() = default; };
(since C++23)
inline constexpr std::from_range_t from_range {};
(since C++23)
std::from_range is a disambiguation tag that can be passed to the constructors of the suitable containers to indicate that the contained member is range constructed.
The corresponding type std::from_range_t can be used in the constructor's parameter list to match the intended tag.
[edit] Standard library
The following standard library types use std::from_range_t type in their constructors:
Containers library
(C++23)
vector from a range (public member function of
std::vector<T,Allocator>)
(C++26)
inplace_vector from a range (public member function of
std::inplace_vector<T,N>)
(C++26)
hive from a range (public member function of
Template:cpp/container/hive/title )
(C++23)
deque from a range (public member function of
std::deque<T,Allocator>)
(C++23)
forward_list from a range (public member function of
std::forward_list<T,Allocator>)
(C++23)
list from a range (public member function of
std::list<T,Allocator>)
(C++23)
set from a range (public member function of
std::set<Key,Compare,Allocator>)
(C++23)
map from a range (public member function of
std::map<Key,T,Compare,Allocator>)
(C++23)
multiset from a range (public member function of
std::multiset<Key,Compare,Allocator>)
(C++23)
multimap from a range (public member function of
std::multimap<Key,T,Compare,Allocator>)
(C++23)
unordered_set from a range (public member function of
std::unordered_set<Key,Hash,KeyEqual,Allocator>)
(C++23)
unordered_map from a range (public member function of
std::unordered_map<Key,T,Hash,KeyEqual,Allocator>)
(C++23)
unordered_multiset from a range (public member function of
std::unordered_multiset<Key,Hash,KeyEqual,Allocator>)
(C++23)
unordered_multimap from a range (public member function of
std::unordered_multimap<Key,T,Hash,KeyEqual,Allocator>)
(C++23)
priority_queue from a range (public member function of
std::priority_queue<T,Container,Compare>)
(C++23)
queue from a range (public member function of
std::queue<T,Container>)
(C++23)
stack from a range (public member function of
std::stack<T,Container>)
(C++23)
flat_set from a range (public member function of
std::flat_set<Key,Compare,KeyContainer>)
(C++23)
flat_map from a range (public member function of
std::flat_map<Key,T,Compare,KeyContainer,MappedContainer>)
(C++23)
flat_multiset from a range (public member function of
std::flat_multiset<Key,Compare,KeyContainer>)
(C++23)
flat_multimap from a range (public member function of
std::flat_multimap<Key,T,Compare,KeyContainer,MappedContainer>)
Strings library
(C++23)
basic_string from a range (public member function of
std::basic_string<CharT,Traits,Allocator>)
[edit] Notes
| Feature-test macro | Value | Std | Feature |
|---|---|---|---|
__cpp_lib_containers_ranges |
202202L |
(C++23) | Tagged constructors to construct from container compatible range |
[edit] Example
Run this code
#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 }