Boost logo

Boost :

From: Andy Little (andy_at_[hidden])
Date: 2006-09-09 15:53:18


"Joel de Guzman" <joel_at_[hidden]> wrote in message
news:edu4v2$beb$1_at_sea.gmane.org...
> Andy Little wrote:

>> BTW. By using a tuple rather than an array, then you can use representing
>> zero
>> and one. IOW zero<T> one<T> .
>>
>> hence:
>>
>> template <typename TL, typename TR>
>> zero<typeof(TL() * TR() )>
>> operator *( Tl , zero<TR>)
>> {
>> return zero<typeof(TL() * TR() )>();
>> }
>> It should be relatively simple for the compiler to optimise such calcs away.
>> Very useful for matrix calcs.
>> (originally suggested by Geoffrey Irving).
>
> Indeed. Also, with Fusion, you have the option to use purely
> constant sequences such as mpl::vector_c together with plain
> sequences, or even user defined sequences and adapted/converted
> structs/classes.

Right. I started looking into this scheme for math ops. I opted for a zero and a
one, but then I figured that one + one should go to two etc.

In the end I opted for a static_value<StaticValue,RunTimeType>

StaticValue could then be any of mpl::int_ etc, though for mpl int_ division is
( can be) lossy so at that point the division should turn the result into the
RunTimeType. other possibilities for StaticValue are a compile time rational,
maybe with a long long value_type. At any point where the compile time value
will run out of steam then the type will be automatically converted to the
RunTimeType.

All in all... how to take a simple idea and make it very very complicated :-)

regards
Andy Little


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