Boost logo

Proto :

Subject: [proto] Matching terminals holding a function pointer
From: Bart Janssens (bart.janssens_at_[hidden])
Date: 2011-02-07 15:38:54


Hi,

I may be overlooking the obvious here, but I can't seem to find an
easy way to match terminals containing a pointer to a function (of
arbitrary type). The basic use case is this:
I have some grammars that contain specific rules for terminals used as
a function in certain cases, something along the lines of:

boost::proto::when
<
  boost::proto::function<SFFieldVariables, MappedCoordinate>,
  MyPrimitiveTransform(...)
>

However, further along in the sequence of grammars, I want to provide
a fall-back for "normal" functions, which are evaluated using the
default grammar. This makes defining standard functions such as sin,
cos, ... very easy. Right now, I am matching those like this:

boost::proto::function< boost::proto::_, boost::proto::vararg<GrammarT> >

where GrammarT corresponds to whatever grammar is currently in use
(it's a template parameter for my "default operations" fall-back).

The problem with this is, is that it also matches
boost::proto::function<SFFieldVariables, GrammarT>, which is incorrect
for anything except if GrammarT happens to be a MappedCoordinate. So
what I'd like to do, is limit my fall-back grammar to only match
functions with child 0 being a function pointer terminal, such as

static boost::proto::terminal< double(*)(double) >::type const _sin = {&sin};

And this for any possible function signature. Is there an (easy) way to do this?

Cheers,

-- 
Bart

Proto list run by eric at boostpro.com