Topic: ref qualiter allowed for defaulted functions?
Author: SG <s.gesemann@gmail.com>
Date: Tue, 11 Aug 2009 14:30:25 CST Raw View
The grammar seems to allow the combination of a ref qualifier and the
=default; syntax for assignment operators.
According to 8.4/9 (N2914.pdf) "only special member functions may be
explicitly defaulted, and the implementation shall define them as if
they had implicit definitions."
Section 12.8/9 explains that an implicit assignment operator is either
of the form
X& X::operator=(const X&)
or
X& X::operator=(X&)
My question is now whether something like this:
class X {
public:
X& operator=(const X&) & = default;
};
(note the ref qualifier) is well-formed and if yes whether this
operator can be invoked on lvalues only (like the ref qualifier
indicates) or on both, lvalues and rvalues (like the implicit
definitions would support).
Maybe there should be added a comment on ref qualifiers. In my opinion
it is desirable to be able to use default assignment operators and at
the same time restrict them to lvalues
Cheers!
SG
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: "Niels Dekker - no reply address" <invalid@this.is.invalid>
Date: Wed, 12 Aug 2009 17:26:01 CST Raw View
SG wrote:
> The grammar seems to allow the combination of a ref qualifier and the
> =default; syntax for assignment operators.
>
> According to 8.4/9 (N2914.pdf) "only special member functions may be
> explicitly defaulted, and the implementation shall define them as if
> they had implicit definitions."
>
> Section 12.8/9 explains that an implicit assignment operator is either
> of the form
> X& X::operator=(const X&)
> or
> X& X::operator=(X&)
>
> My question is now whether something like this:
>
> class X {
> public:
> X& operator=(const X&) & = default;
> };
>
> (note the ref qualifier) is well-formed and if yes whether this
> operator can be invoked on lvalues only (like the ref qualifier
> indicates) or on both, lvalues and rvalues (like the implicit
> definitions would support).
>
> Maybe there should be added a comment on ref qualifiers. In my opinion
> it is desirable to be able to use default assignment operators and at
> the same time restrict them to lvalues
Sounds like CWG issue #906, by Daveed Vandevoorde: "Which special member
functions can be defaulted?"
www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#906 It was discussed
in Frankfurt, last month, and moved forward to status "Review". As you see,
the proposed resolution allows you to add a ref-qualifier to a defaulted
assignment operator. :-)
HTH, Niels
--
Niels Dekker
http://www.xs4all.nl/~nd/dekkerware
Scientific programmer at LKEB, Leiden University Medical Center
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Wed, 12 Aug 2009 17:26:19 CST Raw View
On Aug 11, 11:30 pm, SG <s.gesem...@gmail.com> wrote:
> The grammar seems to allow the combination of a ref qualifier and the
> =default; syntax for assignment operators.
> According to 8.4/9 (N2914.pdf) "only special member functions may be
> explicitly defaulted, and the implementation shall define them as if
> they had implicit definitions."
See core issue 906:
http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2009/n2936.html#906
The proposed resolution suggests that the ref qualifier is allowed,
and with your example,
the assignment can be invoked on lvalues only.
The issue is still in review, so nothing is set in stone.
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]