tl;dr: It actually does exist.
As @Barry and @StoryTeller indicate, this constructor actually exists - albeit through the use of templates; you're just failing to notice the "fine print" on the cppreference page you linked to:
template < class T >
explicit constexpr basic_string(
const T& t,
const Allocator& alloc = Allocator()
);
this will construct an std::string
from a std::string_view
. Why? Because what it:
Implicitly converts t
to a string view sv
as if by std::basic_string_view<CharT, Traits> sv = t;
, then initializes the string with the contents of sv
, as if by std::basic_string(sv.data(), sv.size(), alloc)
.
For the specific case of T = std::string_view
:
template <>
explicit constexpr basic_string<std::string_view>(
const std::string_view& t,
const Allocator& alloc = Allocator()
);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…