如何解开像boost :: unwrap_reference这样的std :: reference_wrapper

CK1*_*CK1 1 c++ c++11

我想要移植一些代码,它们对C++ 11使用了boost :: unwrap_reference.代码调用很多成员函数,比如

template< typename T, typename Y>
void initialize( T _t, Y y)
{

    typename boost::unwrap_reference< T >::type & t = _t;

    t.doSomethingNastyWithY( y );
}   

// The function is called like this
struct DoSomething
{
     template<typename Y>
     void doSomethingNastyWithY(Y y)
     {
         // do stuff
     }
};

struct Object {};

DoSomething s;
Object obj;

int main()
{
    initialize( s, obj ); // Take a copy of DoSomething
    initialize( boost::ref(s), obj ); // Uses DoSomething as reference
}
Run Code Online (Sandbox Code Playgroud)

我在STL中找不到与boost :: unwrap_reference等效的东西,还有其他直接的方法吗?

编辑:我澄清了一些例子

Yli*_*sar 5

有点像:

template< typename T >
struct UnwrapReference;

template< typename T >
struct UnwrapReference { typedef T type; }

template< >
struct UnwrapReference< std::reference_wrapper< T > > { typedef T type; }
Run Code Online (Sandbox Code Playgroud)

虽然未经测试,但这是你可能能够做到这一点的要点.