Solaris 上的 std::sort 问题 (libCstd)
我在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看起来你的实际向量是 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?
编译时没有错误并
调用为
compiles without error with
invoked as