Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Notation of "A Proposal to Add an Rvalue Reference to the C++Language"

Reply
Thread Tools

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

 
 
aitorf666@gmail.com
Guest
Posts: n/a
 
      05-08-2008
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);
...
int x = 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 = 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 = 0; //for example }

int x = 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īt change the value which is we
really want
g(2); //ok, we can do it.

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



 
Reply With Quote
 
 
 
 
Jerry Coffin
Guest
Posts: n/a
 
      05-10-2008
In article <9f60e411-a5b1-4571-9d3d-005432378cd4@
56g2000hsm.googlegroups.com>, http://www.velocityreviews.com/forums/(E-Mail Removed) says...
> 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:


That's not the real reason for rvalue references. There are two primary
reasons for rvalue references: providing move semantics, and providing
forwarding semantics.

The ability to modify the original object with impunity is the
_mechanism_ behind the move semantics. Looking at this as 'mutable',
however is looking at how you do one thing with rvalue references,
rather than looking at what the rvalue reference itself really is.

This would also completely ignore the other major use of rvalue
references, which is forwarding. In this case, the ability to modify the
original item is entirely beside the point -- it's mostly about avoiding
providing lots of overloads of forwarding functions.

--
Later,
Jerry.

The universe is a figment of its own imagination.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to convert Infix notation to postfix notation Tameem C Programming 454 01-31-2014 06:01 PM
Giving an rvalue ref to a function taking an rvalue ref Juha Nieminen C++ 13 08-29-2012 09:25 PM
Hungarian Notation Vs. Pascal Notation? Grey Squirrel ASP .Net 6 03-21-2007 09:42 AM
Hot(rvalue) Referencing and move proposal terminator C++ 0 03-09-2007 08:49 PM
operators requiring lvalue/rvalue operands and resulting in rvalue/lvalue Kavya C Programming 9 10-28-2006 01:45 AM



Advertisments