Suppose I have two struct
s:
struct X {};
struct Y { X x; }
I have functions:
void f(X&);
void f(X&&
template <typename T>
void g(T&& t) {
f(std::forward<T>(t).x);
}
I think this will work, although I'm not sure:
template<class T, class M>
struct mforward {
using type = M&&;
};
template<class T, class M>
struct mforward<T&, M> {
using type = M&;
};
template <typename T>
void g(T&& t) {
f(std::forward<typename mforward<T, decltype(t.x)>::type>(t.x));
}