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

Discussion in 'C++' started by aitorf666@gmail.com, May 8, 2008.

  1. Guest

    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 &'
     
    , May 8, 2008
    #1
    1. Advertising

  2. Jerry Coffin Guest

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

    In article <9f60e411-a5b1-4571-9d3d-005432378cd4@
    56g2000hsm.googlegroups.com>, 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.
     
    Jerry Coffin, May 10, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andreas H?lscher

    hex notation

    Andreas H?lscher, Dec 10, 2003, in forum: VHDL
    Replies:
    2
    Views:
    23,070
    Egbert Molenkamp
    Dec 10, 2003
  2. =?ISO-8859-1?Q?Andreas_H=F6lscher?=

    hex notation

    =?ISO-8859-1?Q?Andreas_H=F6lscher?=, Dec 10, 2003, in forum: VHDL
    Replies:
    6
    Views:
    9,463
    Jim Lewis
    Dec 12, 2003
  3. Grey Squirrel

    Hungarian Notation Vs. Pascal Notation?

    Grey Squirrel, Mar 19, 2007, in forum: ASP .Net
    Replies:
    6
    Views:
    1,315
    Steve C. Orr [MCSD, MVP, CSM, ASP Insider]
    Mar 21, 2007
  4. Tameem
    Replies:
    454
    Views:
    12,017
  5. Robert Mark Bram

    Dot notation V Bracket notation

    Robert Mark Bram, Jul 4, 2003, in forum: Javascript
    Replies:
    3
    Views:
    471
    Robert Mark Bram
    Jul 5, 2003
Loading...

Share This Page