Topic: Ref-qualifiers for assignment operators in the Standard Library?
Author: Niels Dekker - no return address <noreply@this.is.invalid>
Date: Fri, 13 Feb 2009 17:07:37 CST Raw View
> As far as I can see, none of the assignment operators provided by the
> Standard Library have a ref-qualifier, looking at the latest Draft,
> www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2800.pdf
>
> An ref-qualifier could be helpful to prevent people from accidentally
> assigning to an rvalue, as I understand from Bronek Kozicki and Daveed
> Vandevoorde, www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1821.htm
FYI, the paper on this subject, that I wrote together with Daniel
Kruegler, has just been published, as part of the 2009 pre-Summit mailing:
"Ref-qualifiers for assignment operators of the Standard Library"
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2819.html
Kind regards, 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: "Niels Dekker - no return address" <noreply@this.is.invalid>
Date: Tue, 16 Dec 2008 00:34:07 CST Raw View
As far as I can see, none of the assignment operators provided by the
Standard Library have a ref-qualifier, looking at the latest Draft,
www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2800.pdf
An ref-qualifier could be helpful to prevent people from accidentally
assigning to an rvalue, as I understand from Bronek Kozicki and Daveed
Vandevoorde, www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1821.htm
For example:
//////////////////////////////////////////////////
#include <cstdlib>
struct S {
S& operator=(S const&) &; // ref-qualifier
operator bool() const;
};
S func();
int main() {
S value;
if ( func() = value ) // Error! (Typical typo.)
return EXIT_FAILURE;
return EXIT_SUCCESS;
}
//////////////////////////////////////////////////
Are those ref-qualifiers still to be added to the assignment operators
within the Library?
Kind regards,
--
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: daniel.kruegler@googlemail.com
Date: Tue, 16 Dec 2008 14:55:06 CST Raw View
On Dec 16, 7:34 am, "Niels Dekker - no return address"
<nore...@this.is.invalid> wrote:
> As far as I can see, none of the assignment operators provided by the
> Standard Library have a ref-qualifier, looking at the latest Draft,www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2800.pdf
>
> An ref-qualifier could be helpful to prevent people from accidentally
> assigning to an rvalue, as I understand from Bronek Kozicki and Daveed
> Vandevoorde,www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1821.htm
>
> For example:
>
> //////////////////////////////////////////////////
> #include <cstdlib>
>
> struct S {
> S& operator=(S const&) &; // ref-qualifier
> operator bool() const;
> };
>
> S func();
>
> int main() {
> S value;
> if ( func() = value ) // Error! (Typical typo.)
> return EXIT_FAILURE;
>
> return EXIT_SUCCESS;
> }
> //////////////////////////////////////////////////
>
> Are those ref-qualifiers still to be added to the assignment operators
> within the Library?
One important use-case for ref-qualifications for basically
all member functions seem to be all atomic types in the
recent library draft. As of
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2514.html
the section "Ambiguity and Insecurity" ends with the sentence:
"In summary, atomic objects are only lvalues, never rvalues."
Just my 2 Euro cents,
Daniel
--
[ 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 ]