小编CK1*_*CK1的帖子

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

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

c++ c++11

1
推荐指数
1
解决办法
1014
查看次数

标签 统计

c++ ×1

c++11 ×1