![](/img/trans.png)
[英]binary '<' : no operator found for map<std::string, shared_ptr<Foo>>
[英]MSVC's standard library does not define spaceship operator for std::string, std::shared_ptr, and so?
我正在嘗試使我的程序多平台,最初是為 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 下工作。 我在這里遺漏了一些觀點,還是沒有完全支持?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.