0

The compiler's implementation of the STL requires it.

Obviously... Forgive my ignorance, but is that standard? I can't find anything in cplusplus.com's reference docs that indicate it's standard. There is absolutely no reference to const, and the examples don't have it either. Thinking on it, I would consider that good practice though.

As a side note, if I compile using MinGW in Dev-C++ I get the same error you posted. In that implementation's stl_algo.h file, I can see some const arguments in the function head above the line the error points to. I think that's the same implementation Code::Blocks uses isn't it?

Edited by Fbody: n/a

0

Obviously... Forgive my ignorance, but is that standard? I can't find anything in cplusplus.com's reference docs that indicate it's standard. There is absolutely no reference to const, and the examples don't have it either.

After staring at the C++ draft standard (for some time), the most relevant part that I found, says;

Compare is used as a function object which returns true if the first argument is less than the second, and false otherwise. Compare comp is used throughout for algorithms assuming an ordering relation. It is assumed that comp will not apply any non-constant function through the dereferenced iterator.

So it appears to be suggested to have it done as in e.g. GCC.

As a side note, if I compile using MinGW in Dev-C++ I get the same error you posted. ...
I think that's the same implementation Code::Blocks uses isn't it?

Possibly yes, perhaps different version though.

0

Compare is used as a function object which returns true if the first argument is less than the second, and false otherwise. Compare comp is used throughout for algorithms assuming an ordering relation. It is assumed that comp will not apply any non-constant function through the dereferenced iterator.

Interesting... This would lead me to think that the function itself should be const rather than the arguments/parameters. But would that provide any benefit considering the functional difference between the 2 contexts...??? I think I'm going to experiment a little. Thanks.

EDIT:
I now see why. I forgot that a non-member function can not be declared const. As a result, const arguments are your only choice.

Edited by Fbody: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.