【发布时间】:2021-05-13 10:26:21
【问题描述】:
我正在尝试使我的程序多平台,最初是为 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 下工作。我是否在这里遗漏了一些要点,或者它并没有真正得到完全支持?
【问题讨论】:
-
你是否在项目的Property页面中将C++语言标准设置为
std:c++latest? -
@D-RAJ 是的,在 Godbolt 的实时示例中你可以看到它已经设置好了。我刚刚研究了 msvc 的标准标头,显然它只是没有定义(与 gcc 标头相反)。也许有人知道任何解决方法?
标签: c++ visual-c++ c++20 spaceship-operator