Boost C++ Libraries of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

Click here to view the latest version of this page.

Struct template local

boost::xpressive::local — local<> is a lazy wrapper for a reference to a value that is stored within the local itself. It is for use within xpressive semantic actions.


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

template<typename T> 
struct local {
  // construct/copy/destruct
  explicit local(T const &);

  // public member functions
  T & get();
  T const & get() const;


Below is an example of how to use local<> in semantic actions.

        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] Note

As the name "local" suggests, local<> objects and the regexes that refer to them should never leave the local scope. The value stored within the local object will be destroyed at the end of the local<>'s lifetime, and any regex objects still holding the local<> will be left with a dangling reference.

Template Parameters

  1. typename T

    The type of the local variable.

local public construct/copy/destruct

  1. local();
    Store a default-constructed value of type T.
  2. explicit local(T const & t);
    Store a default-constructed value of type T.



    The initial value.

local public member functions

  1. T & get();
    Fetch the wrapped value.
  2. T const & get() const;

    This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.