Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ > Notation of "A...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 3 Topic 45814 of 45898
Post > Topic >>

Notation of "A Proposal to Add an Rvalue Reference to the C++

by aitorf666@[EMAIL PROTECTED] May 8, 2008 at 12:53 PM

Hi,
I have been reading the improvement that will be made to C++0x, and
one of this is  "A Proposal to Add an Rvalue Reference to the C++
Language" , which will add a double &,  for example:

int someFunction(int && a){ ...

the reason is to allow to change temporaries passed to functions. Due
to:

void f(int& a);
void ff(const int& a);
=2E..
int x =3D 5;
f(x); //ok
ff(x); //ok
f(2); // error, not to make mistakes
ff(2); //ok

to can pass changeable temporaries, it has been proposed the syntax
int&&, which I thought is naughty.
void g(int&& a){ a =3D 0; }
g(2); //ok

Would not be better the following syntax? -> instead of int&&   ,
mutable int&

The mutable word means "not const", and is used for const member
functions to allow changing values.

I think it has much more logic to:

void f(int& a);
void ff(const int& a){ //perform some task without the possibility of
changing a}
void g(mutable int& a){ a =3D 0; //for example }

int x =3D 5;
f(x); //ok
ff(x);//ok
g(x); // better to be an error to avoid silly mistakes
f(2); //error
ff(2); // not an error, but we can=B4t change the value which is we
really want
g(2); //ok,  we can do it.

My proposal is to change '&&' for 'mutable &'




 3 Posts in Topic:
Notation of "A Proposal to Add an Rvalue Reference to the C++
aitorf666@[EMAIL PROTECTE  2008-05-08 12:53:43 
Re: Notation of "A Proposal to Add an Rvalue Reference to the C
"Victor Bazarov"  2008-05-08 16:44:18 
Re: Notation of "A Proposal to Add an Rvalue Reference to the C
Jerry Coffin <jcoffin@  2008-05-10 10:54:06 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed May 14 19:18:41 CDT 2008.