Cansisti
Cansisti

Reputation: 153

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?

Upvotes: 2

Views: 332

Answers (1)

ChrisMM
ChrisMM

Reputation: 10096

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)

Upvotes: 6

Related Questions