From: Peder Holt (peder.holt_at_[hidden])
Date: 2004-08-31 03:58:14
I think i am closing in on the ultimate typeof implementation.
Given the maximum depth of an expression = N (BOOST_MPL_LIMIT_VECTOR_SIZE)
and the depth of the expression we are evaluating = m
My earlier implementation was of the order (N^2)
Arkadiys implementation (if I am correct) is of the order (m*N)
My new implementation is of the order (m) !!
Meaning it is linear. I only need to evaluate an expression once, and
if the expression is simple, very few templates need to be
There is only the compiler limit to the complexity of an expression.
Here is the define for BOOST_TYPEOF:
#define BOOST_TYPEOF(expr) \
I think this is about as simple as it can get without the real thing.
encode_start(expr) does not return the size of an item in the
expression. It returns the starting index of an iterator.
Every level in the expression instantiates a template class. Every
template class instantiates two friend functions. The first function:
encode_value() takes the current index as input argument, and returns
the encoded value of the current level.
The other function:
encode_index() incremets the current index count. (Up to a maximum of
BOOST_MAX_TYPEOF_COUNTER, defaulted to 1000)
This is the maximum number of levels that can be encoded in a single c++ file.
To access these values:
returns the value at iterator N.
returns the next available index
These are defined as BOOST_TYPEOF_VALUE(N)
I tested my 120 level deep type with very little overhead in compile time.
Since I rely heavily on the order of template instantiation, it may be
fragile to compiler errors (I am compiling this on VC 6.5)
I have had some problems with ETI screwing up the scheme when typeof
is used inside templates, but this is workaroundable by being more
relaxed on the indexing.
The source can be found at:
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk