#include <string>
template<class T> struct passer
{
using type = T;
};
template<class T> using pass_t = typename passer<T>::type;
template <typename Inner>
class Outer {
private:
Inner inner;
public:
template<class T>
auto foo(T&& arg)
-> pass_t<decltype(this->inner.foo(std::forward<T>(arg)))>
{
return inner.foo(std::forward<T>(arg));
}
};
struct Bar
{
void foo(std::string const& thing);
};
struct Baz
{
int foo(int thing) { return thing * 2; };
};
int main()
{
auto o = Outer<Bar>();
o.foo(std::string("hi"));
o.foo("hi");
int i = 1;
auto o2 = Outer<Baz>();
auto x = o2.foo(2);
}
此处链接:
https://godbolt.org/g/UvsrbP