Boost logo

Boost :

From: Joel de Guzman (joel_at_[hidden])
Date: 2003-10-11 18:46:54


Joel de Guzman <joel_at_[hidden]> wrote:
> Paul Mensonides <pmenso57_at_[hidden]> wrote:
>>> [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)
>
> Cool idea, Paul! I like it!

Of course, it's just "for fun" :-)

-- 
Joel de Guzman
http://www.boost-consulting.com
http://spirit.sf.net

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