Boost logo

Boost :

From: AlisdairM (alisdair.meredith_at_[hidden])
Date: 2003-12-07 10:21:55


"Thorsten Ottosen" <nesotto_at_[hidden]> wrote in
news:bqvbi5$d6n$1_at_[hidden]:

> your implementation looks ok (I have not testet it), but the problem
> is often that you want the size of a variable and not a
> type, eg,
>
> sizer( my_array_variable );
>
> which makes the code look a lot different.

I'm still can't work out the syntax for this.

To determine bounds of the array at compile time we can use the array as a
non-type template paramter:

const size_t size = array_size<myArray>::size;

However, I can't work out how to declare array_size as parameterized on
both N and T:

template< class T, size_t N >
struct array_size_holder
{

template< T[N] >
struct array_size
{
    enum result { size = N };
};

};

We can only call array_size if we know T and N in advance, which kind of
defeats the purpose <g> How can I deduce T/N without embedding array_size
into a wrapper template?

AlisdairM


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