Topic: lvalues and function calls
Author: anhaeupl@late.e-technik.uni-erlangen.de (Bernd Anhaeupl)
Date: 1996/06/03 Raw View
Can somebody please explain the reason for paragraph 12 in section 5.2.2 of
the April 95 working paper:
A function call is an lvalue if and only if the result type is a reference.
Please note, that functions returning class objects have to return something
very similar to a lvalue, you can call even non-constant member functions
on this type of 'rvalues', you can also easily convert them to an lvalue:
class foo{
....
foo & lvalue(){return *this;};
}
foo f(void);
Now
f().lvalue()
obviously converts the rvalue generated by f() to an lvalue.
So why not simply change the mentioned paragraph to
A function call is an lvalue if and only if the result is a
reference or a non-const class type.
( lvalue: foo f(); rvalue: const foo f();)
or, if you don't like that idea because it would also change overload
resolution and might therefore break existing code, introduce a new
meaning of the keyword 'mutable':
A function call is an lvalue if and only if the result is a
reference or a mutable class type.
(lvalue: mutable foo f(); rvalue: foo f();)
This would also solve the auto_ptr problem.
--
Bernd Anhaeupl Tel.: +49 9131 857787
LATE - Uni Erlangen
Cauerstr. 7 Email: anhaeupl@late.e-technik.uni-erlangen.de
91058 Erlangen
---
[ comp.std.c++ is moderated. To submit articles: Try just posting with your
newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]