1

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.

lytenyn
  • 819
  • 5
  • 21

2 Answers2

5

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

Erik
  • 88,732
  • 13
  • 198
  • 189
  • stupid me. Thanks a lot! I was so focused on 'It is certainly again this stupid STL implementation'... sorry about bothering everybody. – lytenyn Feb 28 '11 at 09:37
3
#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
AProgrammer
  • 51,233
  • 8
  • 91
  • 143