c++ - MSVC 的标准库没有为 std::string、std::shared_ptr 等定义飞船操作符?

标签 c++ visual-c++ c++20 spaceship-operator

我正在努力使我的程序成为多平台的,最初是为 Linux 编写的。 MSVC(我使用的是 19.28)被告知从版本 19.20(https://en.cppreference.com/w/cpp/compiler_support/20)开始支持宇宙飞船运算符,但它似乎没有为 std::string 或 std::shared_ptr(可能对于许多其他众生)。

我真正想做的是:


// int x(1), y(2); // ok!
// std::string x("1"), y("2"); // nope
std::shared_ptr<int> x(new int), y(new int); // nope
auto r = x <=> y; // error C2676 for string and shared_ptr

实例: https://godbolt.org/z/Eo49hh

它在 GCC 10.2 下工作。我是否遗漏了一些要点,或者它没有得到真正的完全支持?

最佳答案

MSVC 支持 operator<=> ,但这并不意味着他们已经为所有图书馆实现。从您指向 cppreference 的链接,在 C++20 library features 部分下,它实际上表明 MSVC 没有 P1614R2 (将 <=> 添加到标准库)

它部分支持 P0768R1 (库支持运算符<=> <compare> )并完全支持 P1185R2 (运营商)

关于c++ - MSVC 的标准库没有为 std::string、std::shared_ptr 等定义飞船操作符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66124936/

相关文章:

c++ boost模板类型和非类型

c++ - 这个签名中的第二个参数是什么意思?

c++ - 如何在 Visual C++ 2013 中执行嵌套的 initializer_lists

visual-c++ - 构建使用强类型数据集的 C++/CLI 项目时警告 C4564

c++ - [[可能]] 和 [[不太可能]] 影响程序汇编的简单示例?

c++ - 如何在世界地图图像上突出显示特定国家/地区

C++ 错误 : invalid types 'int[int]' for array subscript

c++ - 为什么带有自定义删除器的 unique_ptr 不适用于 nullptr,而 shared_ptr 可以?

c++ - Visual Studio 中的 "Additional Module Dependencies"和 "Additional BMI Directories"设置

c++ - 如何在 constexpr 构造函数中初始化矩阵 ONCE?