Boost logo

Boost Users :

Subject: Re: [Boost-users] Boost.Variant broke in 1.54?
From: Krzysztof Czainski (1czajnik_at_[hidden])
Date: 2013-08-05 07:47:17


2013/8/4 Edward Diener <eldiener_at_[hidden]>

> On 8/4/2013 8:57 AM, gast128 wrote:
> Returning a 'const X' is meaningless. Just return 'X' instead.

Just to clarify, Edward, I think you're wrong. Consider:

struct X { void go() {} };

X source_a();
X const source_b();

int main()
{
  source_a().go(); // ok
  source_b().go(); // error

> The same goes for passing something as 'const X'.

I assume you mean a function *taking* something as 'const X'. Consider:

void g( X x );
void g( X const x );

The two declarations of g() are equivalent (!), so you could say this
'const' is meaningless ;-). The 'const' here matters in the implementation
of function g.

void f( X x, X const y )
{
  x.go(); // ok
  y.go(); // error

> When you pass or return by value you get a copy of the object being passed
> so it means nothing to say that the object is 'const'.

Considering what I've written above, I disagree that 'const' means nothing
here. When function source_b() returns by const value, it *means* the
returned temporary is const. When function f() takes by const value, it
*means* the implementation of f() doesn't modify the copy it gets. For the
caller of f(), this 'const' is meaningless indeed ;-)

Regards,
Kris



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net