Boost logo

Boost :

From: Arkadiy Vertleyb (vertleyb_at_[hidden])
Date: 2006-01-14 22:37:40

"Andy Little" <andy_at_[hidden]> wrote

> I always understood typeof useage to be
> quite heavyweight, so I was quite worried about the large number of types
> automatically registered in last version of boost::mpl::math library.

Well, when the types are registered, the specializations are created by
preprocessor, and so, theoretically, it may consume some noticable time.
However, I don't believe it should be a problem...

When a type is actually being deduced, there are two parts that consume
compile time:

1) The type needs to be encoded and decoded. The time necessary for this
operation is linearly proportional to the complexity of the type (the size
of encoding vector). The factor is about 10 template instantiations per
node (or something like this -- I estimated this in the past, and things
changed since then).

2) The expression needs to be passed to the template function so that the
compiler deduce the type. This is done BOOST_TYPEOF_LIMIT_SIZE times per
BOOST_TYPEOF invocation.

Of these two, the first one is most significant. On my 1.5 GHz PC, with
BOOST_TYPEOF_LIMIT_SIZE=50, vc71 can compile 10 BOOST_TYPEOF's of
fundamental types in under one second. However, it may take about 2 sec to
compile BOOST_TYPEOF of one more complicated, e.g., Spirit expression of
about 45 nodes.

The inclusion of typeof.hpp takes 2 to 3 seconds. The time is spent
registering fundamental types, pointers, functions, etc.

> Bearing in mind that I have been getting a compiler out of keys error
> recently in even small tests, which as you will understand basically
renders my
> library a useless resource hog, I am now trying to be extremely careful to
> as little unnecessary clutter in headers as possible. That includes not
> to register unneccesary types with Typeof if at all possible.

You may want to consider the strategy we used with the STL types -- for each
STL header we defined a corresponding typeof header which included the STL
header and registered the types.

Then, depending on whether the typeof functionality is needed, the user can
do either:

#include <vector>


#include <boost/typeof/std/vector.hpp>


Boost list run by bdawes at, gregod at, cpdaniel at, john at