Boost C++ 库

...世界上备受推崇、精心设计的C++库项目之一。 Herb SutterAndrei Alexandrescu, C++ 编码规范

结构体模板 local - Boost C++ 函数库
PrevUpHomeNext

结构体模板 local

boost::xpressive::local — local<> 是一个针对存储在 local 内部的值的引用的惰性包装器。它用于 xpressive 语义动作中。

提要

// In header: <boost/xpressive/xpressive_fwd.hpp>

template<typename T> 
struct local : public proto::terminal::type {

  // public member functions
  local();
  explicit local(T const &);
  T & get();
  T const & get() const;
};

描述

以下是如何在语义动作中使用 local<> 的示例。

using namespace boost::xpressive;
local<int> i(0);
std::string str("1!2!3?");
// count the exciting digits, but not the
// questionable ones.
sregex rex = +( _d [ ++i ] >> '!' );
regex_search(str, rex);
assert( i.get() == 2 );

[Note] 注意

正如“local”这个名称所暗示的那样,local<> 对象以及引用它们的正则表达式永远不应离开局部作用域。存储在 local 对象中的值将在 local<> 的生命周期结束时被销毁,并且任何仍然持有 local<> 的正则表达式对象都将留下悬空引用。

模板参数

  1. typename T

    局部变量的类型。

local 公共成员函数

  1. local();
    存储类型为 T 的默认构造值。
  2. explicit local(T const & t);
    存储类型为 T 的默认构造值。

    参数

    t

    初始值。

  3. T & get();
    获取包装的值。
  4. T const & get() const;
    这是一个重载的成员函数,为方便起见提供。它仅在接受的参数不同时与上述函数有所区别。

PrevUpHomeNext