std::from_range, std::from_range_t

Header: <ranges>

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.

# Declarations

struct from_range_t { explicit from_range_t() = default; };

(since C++23)

inline constexpr std::from_range_t from_range {};

(since C++23)

# Notes

Feature-test macro Value Std Feature __cpp_lib_containers_ranges 202202L (C++23) Tagged constructors to construct from container compatible range

# Example

#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
}

# See also