Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2003-12-22 11:24:21


"Andy Little" <andy_at_[hidden]> writes:

>
> OK Just to clarify. I am assuming the tree is representing the compilers
> internal database of instantiated templates.

The "instantiation stack" for a recursive sequence traversal.

> Though quite how MPL achieves this...hmm...I dont think I want to
> know :-)

It's quite simple, actually. It's just the same thing you'd do to
achieve that sort of flattening in a recursive function invocation.

> Now. ( I hope you dont mind me concentrating on my physical_quantities
> type.( pqs for short)

No

<snip>

> Here is the current 'abstract_pq' part of the type... similar idea to the
> one in your Powerpoint presentation:
> //Length,Time,Mass,Temperature,Current,Substance,Intensity
> template
> <
> int P_len ,
> int P_time=0,
> int P_mass=0,
> int P_temp=0,
> int P_current=0,
> int P_substance =0,
> int P_intensity=0
> >
> struct abstract_pq{
> static int const pwr_length = P_len;
> static int const pwr_time = P_time;
> static int const pwr_mass = P_mass;
> static int const pwr_temperature = P_temp;
> static int const pwr_current = P_current;
> static int const pwr_substance = P_substance;
> static int const pwr_intensity = P_intensity;
> };
>
> (There are also of course similar ops to plus<a,b>::type etc)
> I have Assumed(not tested... yet) that this will be about the fastest way to
> do this From a (general)compile-time point of view.
> ie faster than a mpl::vector_c. (I appreciate there are a lot of variables
> ,e.g compiler etc involved)
> but what is your view... solely on compile times.(There is some implication
> from the above that I am wrong and I would be very happy to be Wrong :-) )

You are unlikely to be able to improve on that using MPL, since you're
using a fixed set of units. You might have an improvement using enums
instead of static int const, though: I found on some compilers it
makes a big difference.

> I have also assumed (and now appreciate that I am wrong) that MPL was
> primarily about creating complex structures(types) at compile time.
> But you seem to be saying that it has other useful purposes.

Any kind of computation you want to do at compile-time, so long as
you don't need side-effects and state, can be done.

> If this is the case.. When is this MPL book coming out?

Sometime next year, I think.

-- 
Dave Abrahams
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