Use of rvalue reference members?

后端 未结 4 989
离开以前
离开以前 2021-01-30 06:52

I was wondering what use an rvalue reference member has

class A {
  // ...
  // Is this one useful?
  Foo &&f;
};

Does it have any bene

4条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-30 07:22

    class A {
      // ...
      // Is this one useful?
      Foo &&f; 
    };
    

    In this specific case, there is no reason to use an rvalue reference. It doesn't buy you anything you couldn't have done before.

    But you may want to define data members with parameterized types. std::tuple is going to support lvalue and rvalue reference data members, for example. This way it allows you to codify an expression's value category which might come in handy for "delayed perfect forwarding". The standard draft even includes a function template of the form

    template
    tuple pack_arguments(Args&&...args);
    

    But I'm honestly not sure about its usefulness.

提交回复
热议问题