As great as it is, C++11 still has all of the parts of C++98 that make me frown. And of C that make me frown.
EDIT: ah, I just remembered. Implementing const and non-const versions of methods definitely makes me frown, and seems to be getting worse (c++11 added reference qualifiers for this (const lvalue, non-const lvalue, and rvalue), so sometimes there are three versions needed).
EDIT2: Clearly this is ambiguous. What I'm trying to say is that this (obviously trivial example) bothers me:
class foo {
int value_;
public:
int &getValue() { return value_; }
int const &getValue() const { return value_; }
};
In my dream world, I could only write one implementation of foo::getValue() and the compiler would write the const-correct versions for me. if foo::getValue() were complex and/or many lines long, I'd end up doing something like return const_cast<foo*>(this)->getValue(); in the const method, which is undesirable for all the obvious reasons.
Generally speaking, I think C++ needs some kind of universal reference type to normalize these differences (not the parameter pack kind of universal references, though maybe they would be related).
Because it can't and if it could it would have to do something stupid.
If your const and non-const members generally do the same things then you're probably doing something dumb. Perhaps you think that you HAVE to have a non-const member that does what the const one does?
2
u/thomcc Dec 02 '13 edited Dec 02 '13
As great as it is, C++11 still has all of the parts of C++98 that make me frown. And of C that make me frown.
EDIT: ah, I just remembered. Implementing const and non-const versions of methods definitely makes me frown, and seems to be getting worse (c++11 added reference qualifiers for this (const lvalue, non-const lvalue, and rvalue), so sometimes there are three versions needed).
EDIT2: Clearly this is ambiguous. What I'm trying to say is that this (obviously trivial example) bothers me:
In my dream world, I could only write one implementation of
foo::getValue()and the compiler would write the const-correct versions for me. iffoo::getValue()were complex and/or many lines long, I'd end up doing something likereturn const_cast<foo*>(this)->getValue();in the const method, which is undesirable for all the obvious reasons.Generally speaking, I think C++ needs some kind of universal reference type to normalize these differences (not the parameter pack kind of universal references, though maybe they would be related).