[proto] Matching terminals holding a function pointer

2011-02-07 Thread Bart Janssens
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::functionSFFieldVariables, 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::varargGrammarT 

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::functionSFFieldVariables, 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 mailing list
proto@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/proto


Re: [proto] Matching terminals holding a function pointer

2011-02-07 Thread Eric Niebler
On 2/8/2011 3:38 AM, Bart Janssens wrote:
 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). 
snip

Sure there's an easy way. You can use proto::if_ and type traits:

// untested
struct FunctionPointer
  : proto::and_
proto::terminal _ 
  , proto::if_ is_pointer proto::_value () 
  , proto::if_ is_function
remove_pointer proto::_value  () 

{};

HTH,

-- 
Eric Niebler
BoostPro Computing
http://www.boostpro.com
___
proto mailing list
proto@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/proto