Perfect forwarding a member of object

后端 未结 2 1979
甜味超标
甜味超标 2020-12-09 04:25

Suppose I have two structs:

struct X {};
struct Y { X x; }

I have functions:

void f(X&);
void f(X&&         


        
2条回答
  •  独厮守ぢ
    2020-12-09 05:16

    I think this will work, although I'm not sure:

    template
    struct mforward {
      using type = M&&; 
    };
    template
    struct mforward {
      using type = M&; 
    };
    
    template 
    void g(T&& t) {
      f(std::forward::type>(t.x));
    }
    

提交回复
热议问题