Boost logo

Boost :

From: Eric Niebler (eric_at_[hidden])
Date: 2007-04-11 11:09:16


Maurizio Vitale wrote:
> Hi,
>
> I'm trying to get boost::proto to turn udt(v1,v2) into a parse
> tree. Up to now I haven't got past the compiler asking for an
> udt::operator()(int,int).
>
> I can probably define such an operator for my UDT and return a
> proto::expr tree, but I was hoping in proto providing overloads so
> that I don't have to do it for all my types.
>
> I've looked into expr.hpp and there seem to be something related to
> this, but I don't seem to be able to make use of it.
>
> What is the best way to achieve what I'm trying?

As you noticed, proto::expr<> has operator() overloads, and everything
in proto is an expr<>, including terminals, so you can do this:

struct udt_tag {};
proto::terminal<udt_tag>::type const udt = {{}};

And now udt(v1,v2) will build parse trees. If you want udt to have extra
member functions, you would use proto::extends<>, like this:

struct udt_ex
   : proto::extends<proto::terminal<udt_tag>::type, udt_ex>
{
   udt_ex() {}

   using
     proto::extends<proto::terminal<udt_tag>::type, udt_ex>
       ::operator=;

   void do_stuff() {...}
   ...
};

udt_ex const udt;

HTH,

-- 
Eric Niebler
Boost Consulting
www.boost-consulting.com

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk