我想要移植一些代码,它们对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 …