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

This is the documentation for an old version of Boost. Click here to view this page for the latest version.

Struct template value

boost::xpressive::value — value<> is a lazy wrapper for a value that can be used in xpressive semantic actions.


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

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

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


Below is an example that shows where value<> is useful.

        sregex good_voodoo(boost::shared_ptr<int> pi)
            using namespace boost::xpressive;
            // Use val() to hold the shared_ptr by value:
            sregex rex = +( _d [ ++*val(pi) ] >> '!' );
            // OK, rex holds a reference count to the integer.
            return rex;

In the above code, xpressive::val() is a function that returns a value<> object. Had val() not been used here, the operation ++*pi would have been evaluated eagerly once, instead of lazily when the regex match happens.

Template Parameters

  1. typename T

    The type of the value to store.

value public construct/copy/destruct

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



    The initial value.

value public member functions

  1. T & get();

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

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