Boost C++ Libraries

...one 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.
PrevUpHomeNext

Struct template function

boost::xpressive::function — A unary metafunction that turns an ordinary function object type into the type of a deferred function object for use in xpressive semantic actions.

Synopsis

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

template<typename PolymorphicFunctionObject> 
struct function {
  // types
  typedef proto::terminal< PolymorphicFunctionObject >::type type;
};

Description

Use xpressive::function<> to turn an ordinary polymorphic function object type into a type that can be used to declare an object for use in xpressive semantic actions.

For example, the global object xpressive::push_back can be used to create deferred actions that have the effect of pushing a value into a container. It is defined with xpressive::function<> as follows:

xpressive::function<xpressive::op::push_back>::type const push_back = {};

where op::push_back is an ordinary function object that pushes its second argument into its first. Thus defined, xpressive::push_back can be used in semantic actions as follows:

namespace xp = boost::xpressive;
using xp::_;
std::list<int> result;
std::string str("1 23 456 7890");
xp::sregex rx = (+_d)[ xp::push_back(xp::ref(result), xp::as<int>(_) ]
    >> *(' ' >> (+_d)[ xp::push_back(xp::ref(result), xp::as<int>(_) ) ]);


PrevUpHomeNext