is_constructible_v<std::string&&, std::string&&> 是什么意思?

myo*_*dpa 2 c++ constructor rvalue type-traits c++17

我能明白是什么is_constructible_v<std::string, std::string&&>。但什么is_constructible_v<std::string&&, std::string&&>意思呢?

is_constructible_v<std::string, std::string&&>和 和有什么区别is_constructible_v<std::string&&, std::string&&>

我认为这is_constructible_v<std::string&&, std::string&&>意味着从右值构造右值。但我不清楚是什么constructing rvalue意思。如果 T 是可构造的,那么它的构造函数总是可以用作右值。这就是构建右值的意义吗?

Ted*_*gmo 5

std::is_constructible_v<std::string&&, std::string&&>测试如果

std::string&& obj(std::declval<std::string&&>());
Run Code Online (Sandbox Code Playgroud)

是格式良好的(参见[meta.unary.prop] p9),确实如此。您可以像这样创建右值引用:

std::string&& obj(std::string{}); // string&& from string&&
Run Code Online (Sandbox Code Playgroud)