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 reference

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


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

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

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


Here is an example of how to use reference<> to create a lazy reference to an existing object so it can be read and written in an xpressive semantic action.

        using namespace boost::xpressive;
        std::map<std::string, int> result;
        reference<std::map<std::string, int> > result_ref(result);
        // Match a word and an integer, separated by =>,
        // and then stuff the result into a std::map<>
        sregex pair = ( (s1= +_w) >> "=>" >> (s2= +_d) )
            [ result_ref[s1] = as<int>(s2) ];

Template Parameters

  1. typename T

    The type of the referent.

reference public construct/copy/destruct

  1. explicit reference(T & t);
    Store a reference to t.



    Reference to object

reference public member functions

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