Re: Constness for user-defined by-reference types
On 5 Jan., 20:18, Edward Rosten <edward.ros...@gmail.com> wrote:
On Jan 3, 10:15 pm, SG <s.gesem...@gmail.com> wrote:
[...] It seems you confuse
U const * // Type1
with
U * const // Type2
The OP is not confused about the semantics and has not misunderstood
the problem.
That's your opinion.
You can see that by the way that his example in the
original post and subsequent post is correct.
Correct in what way? Did you read the comment? He uses the name of the
proxy object interchangably for the proxy object and the object it
refers to. I wouldn't call that "correct". It's more of an indication
that the OP doesn't distinguish between two different objects even
though the top level constness only applies to one of them, the proxy.
The OP is instead _complaining_ about how the semantics work.
He is complaining about having to write two classes for two models of
two different but related concepts. He could try to solve this with a
parameterized class (aka class template, write one template, get two
models) or just check out how Boost's iterator libraries might help in
developing iterators with less boiler plate code. Anything that
involves misusing the top-level const is "just wrong" in my opinion.
[...]
If you write a function like this:
void bar(const refvector<int>& j)
{
refvector<int> nonconst_j(j);
nonconst_j[0] = 0xdeadbeef; //conceptually modify j.
}
That's what I'd call bad design -- possibly rooted in a distorted
perception of the concepts involved (something along the lines of not
getting the difference between pointer and pointee).
btw, your name looks familiar. I'm sure we discussed this already
which is why I don't really expect this discussion to go anywhere.
Obviously we both kept our views and it's probably going to stay that
way.
Then j is not conceptually const, as illustrated, despite the
similarity between the interface of vector and refvector and the
similarity between the function definitions. The complaint is that C++
has no mechanism for making the two examples have the same semantics.
I.e. it has no mechanism for making the top-level const stronger.
You blame C++. I blame you for a bad design. You want a spoon that
looks and feels exactly like a fork but you still want it to be a
spoon. I say, get over it and take a fork already. (I'm generally not
a fan of analogies but this one seems somewhat appropriate.)
Cheers,
SG
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]