C++已经有了引用操作符&,为什么C++11还要引入std::ref?
有什么情况是&符号不能处理的,必须要std::ref才能清楚的表达语义呢? 除了在std::bind里面用到之外?
可是std::bind完全可以用lambda来取代啊
[解决办法]
比如 std::for_each 第三个参数要接受引用时,就必须用 std::ref.
[解决办法]
例如:
template< typename T >
struct Example
{
typedef typename T::ref MyReference;
..............
};
template <class T> class reference_wrapper;
//Class that emulates a reference to an element of type T, but which can be copied (it is both copy-constructible and copy-assignable).