简体   繁体   中英

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. 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).

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

It works under 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. 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 )

It has partial support for P0768R1 ( Library support for operator<=> <compare> ) and full support for P1185R2 ( the operator )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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