std::sort problem on solaris (libCstd)

1.6k views Asked by At

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.

2

There are 2 answers

1
Erik On BEST ANSWER

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

0
AProgrammer On
#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