Boost logo

Boost :

From: Paul Mensonides (pmenso57_at_[hidden])
Date: 2003-10-11 13:20:52


> [mailto:boost-bounces_at_[hidden]] On Behalf Of Brian McNamara

> typedef result_of< op_plus(int, double) >::type result;
>
> would truly work. (Names like op_plus are just used as tags
> which stand for the corresponding C++ operators.)

Just for fun:

You can use a template to handle all operators:

template<int> struct op { };

typedef result_of< op<'+'>(int, double) >::type result;

The longest operator in C++ is 4 characters %:%: (i.e. token-pasting to
the preprocessor). Otherwise, core language (non-keyword) operators max
out at three characters (e.g. >>=), so you should be able to fit all of
them in an integer literal that has at least 4 bytes.

Of course, this doesn't work that great for postfix operators because
there is no semantic difference, unless you fake it just like
overloading it:

op<'++'>(Type)
op<'++'>(Type, int)

Regards,
Paul Mensonides


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