Solaris 上的 std::sort 问题 (libCstd)

发布于 2024-10-19 09:51:10 字数 1061 浏览 14 评论 0原文

我在 Solaris 上使用 Sun Studio 编译器时遇到问题,这很可能是由于使用了奇怪的 STL 实现 (libCstd),请参阅 http://developers.sun.com/solaris/articles/cmp_stlport_libCstd.html。考虑一下:

std::vector<C*> v;
// .. populate the vector
std::sort(v.begin(), v.end());

其中 C 是某个类。这会产生以下编译器错误消息:

"/opt/sunstudio12.1/prod/include/CC/Cstd/./algorithm", line 725: Error: The operand "*first" cannot be assigned to.
"/opt/sunstudio12.1/prod/include/CC/Cstd/./algorithm.cc", line 985:     Where: While instantiating "std::__linear_insert<C*const*, C*>(C*const*, C*const*, C**)".
"/opt/sunstudio12.1/prod/include/CC/Cstd/./algorithm.cc", line 985:     Where: Instantiated from std::__insertion_sort<C*const*>(C*const*, C*const*).
"/opt/sunstudio12.1/prod/include/CC/Cstd/./algorithm", line 811:     Where: Instantiated from non-template code.

有人知道如何规避该问题吗?当然,实际上我想将 std::sort 与自定义比较函子一起使用,但即使这个简单的版本也不起作用。

I have a problem on Solaris using the Sun Studio compiler, which is most likely due to the strange STL implementation (libCstd) used, see http://developers.sun.com/solaris/articles/cmp_stlport_libCstd.html. Consider this:

std::vector<C*> v;
// .. populate the vector
std::sort(v.begin(), v.end());

where C is some class. This produces the following compiler error message:

"/opt/sunstudio12.1/prod/include/CC/Cstd/./algorithm", line 725: Error: The operand "*first" cannot be assigned to.
"/opt/sunstudio12.1/prod/include/CC/Cstd/./algorithm.cc", line 985:     Where: While instantiating "std::__linear_insert<C*const*, C*>(C*const*, C*const*, C**)".
"/opt/sunstudio12.1/prod/include/CC/Cstd/./algorithm.cc", line 985:     Where: Instantiated from std::__insertion_sort<C*const*>(C*const*, C*const*).
"/opt/sunstudio12.1/prod/include/CC/Cstd/./algorithm", line 811:     Where: Instantiated from non-template code.

Does anybody know how to circumvent the problem? Of course, actually I want to use std::sort with a custom comparison functor, but even this simple version does not work.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

忘羡 2024-10-26 09:51:10

看起来你的实际向量是 const 。它是在 const 成员函数中访问的成员变量吗?它是 const 函数参数吗?

Looks like your actual vector is const. Is it a member variable accessed in a const member function? Is it a const function argument?

对你再特殊 2024-10-26 09:51:10
#include <algorithm>
#include <vector>

struct C {};

int main()
{
    std::vector<C*> v;
    std::sort(v.begin(), v.end());
}

编译时没有错误并

CC: Sun C++ 5.9 SunOS_sparc Patch 124863-19 2009/12/02

调用为

CC lytenyn.cpp
#include <algorithm>
#include <vector>

struct C {};

int main()
{
    std::vector<C*> v;
    std::sort(v.begin(), v.end());
}

compiles without error with

CC: Sun C++ 5.9 SunOS_sparc Patch 124863-19 2009/12/02

invoked as

CC lytenyn.cpp
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文