Boost C++ 库

...世界上最受推崇和设计精良的 C++ 库项目之一。 Herb SutterAndrei Alexandrescu,《C++ 编码规范

结构体 _byref - Boost C++ 函数库
PrevUpHomeNext

结构体 _byref

boost::proto::_byref — 一个一元可调用对象,是 多态函数对象,它将其参数包装在 boost::reference_wrapper<> 中。

提要

// In header: <boost/proto/transform/arg.hpp>


struct _byref :  proto::callable {
  // member classes/structs/unions
  template<typename This, typename T> 
  struct result<This(T &)> {
    // types
    typedef boost::reference_wrapper< T > const type;
  };
  template<typename This, typename T> 
  struct result<This(T)> {
    // types
    typedef boost::reference_wrapper< T const  > const type;
  };

  // public member functions
  template<typename T> 
    boost::reference_wrapper< T > const operator()(T &) const;
  template<typename T> 
    boost::reference_wrapper< T const > const operator()(T const &) const;
};

描述

示例

proto::terminal<int>::type i = {42};
boost::reference_wrapper<proto::terminal<int>::type> j
  = proto::when<proto::_, proto::_byref(_)>()(i);
assert( boost::addressof(i) == boost::addressof(j.get()) );

_byref 公有成员函数

  1. template<typename T> 
      boost::reference_wrapper< T > const operator()(T & t) const;

    将参数 t 包装在 boost::reference_wrapper<>

    参数

    t

    要包装的对象

    返回

    boost::ref(t)

    抛出

    不会抛出异常。
  2. template<typename T> 
      boost::reference_wrapper< T const > const operator()(T const & t) const;

    这是一个重载的成员函数,为方便起见提供。它仅在接受的参数不同时与上述函数有所区别。


PrevUpHomeNext