C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Ref-qualifiers for assignment operators in the Standard Libr

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards
View previous topic :: View next topic  
Author Message
Niels Dekker - no return
Guest





PostPosted: Tue Dec 16, 2008 6:34 am    Post subject: Ref-qualifiers for assignment operators in the Standard Libr Reply with quote



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 ]
Back to top
Guest






PostPosted: Tue Dec 16, 2008 8:55 pm    Post subject: Re: Ref-qualifiers for assignment operators in the Standard Reply with quote



On Dec 16, 7:34 am, "Niels Dekker - no return address"
<nore...@this.is.invalid> wrote:
Quote:
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 ]
Back to top
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards All times are GMT
Page 1 of 1

 
 


Powered by phpBB © 2001, 2006 phpBB Group