简体   繁体   English

MSVC 的标准库没有为 std::string、std::shared_ptr 等定义 spaceship 运算符?

[英]MSVC's standard library does not define spaceship operator for std::string, std::shared_ptr, and so?

I'm trying to make my program multi-platform, originally written for Linux.我正在尝试使我的程序多平台,最初是为 Linux 编写的。 MSVC (I'm using 19.28) is told to have spaceship operator support from version 19.20 ( https://en.cppreference.com/w/cpp/compiler_support/20 ), but it seems like it does not define this operator for std::string, or std::shared_ptr (probably for many other beings). MSVC(我使用的是 19.28)被告知从 19.20 版( https://en.cppreference.com/w/cpp/compiler_support/20 )开始支持宇宙飞船操作员,但它似乎没有为 std 定义此操作员::string 或 std::shared_ptr (可能适用于许多其他生物)。

What I'm exactly trying to do is:我真正想做的是:


// 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

Live example: https://godbolt.org/z/Eo49hh现场示例: https://godbolt.org/z/Eo49hh

It works under GCC 10.2.它在 GCC 10.2 下工作。 Am I missing some point in here, or it's not really completely supported?我在这里遗漏了一些观点,还是没有完全支持?

MSVC supports the operator<=> , but that doesn't mean they've implemented for all libraries. MSVC 支持operator<=> ,但这并不意味着它们已经为所有库实现。 From your link to cppreference, under the C++20 library features section, it actually shows that MSVC does not have P1614R2 ( Adding <=> to the standard library )从您到 cppreference 的链接,在C++20 库功能部分下,它实际上表明 MSVC 没有P1614R2将 <=> 添加到标准库

It has partial support for P0768R1 ( Library support for operator<=> <compare> ) and full support for P1185R2 ( the operator )它部分支持P0768R1库支持 operator<=> <compare> )和完全支持P1185R2operator

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM