Boost logo

Boost :

From: Valentin Bonnard (Bonnard.V_at_[hidden])
Date: 2000-01-29 16:03:19


Dave Abrahams wrote:

> on 1/29/00 3:15 PM, Valentin Bonnard at Bonnard.V_at_[hidden] wrote:
>
> >> Basically, the idea is to overload all the typical operators
> >> (+, -, <, ==) for functor objects, and use Nico's composition
> >> library as the nodes in the expression tree. It's really not
> >> all that hard to do...
> >
> > How it is possible at all w/o typeof, which no compiler (not even
> > gcc) supports ?
> >
> > (and even then (w/ typeof) it would be ugly)
>
> I did some thinking, and I think you could do it with traits. Preparing
> types for use in operations isn't pretty, but the resulting usage would be
> ;)

template <typename T>
T value ();

typeof (value<T> () + value<U> ())

can of course be rewritten

template <>
struct plus_trait<T, U>
{
  typedef whatever result_type;
};

typename plus_trait<T, U>::result_type

but if the user is required to define too much traits, then
he will simply define a named function to do the work
directly instead of using all the compose library.

(In complex cases, the named function will be clearer than
a bunch of combinators.)

-- 
Valentin Bonnard

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