Boost logo

Boost :

From: Jonathan Turkanis (technews_at_[hidden])
Date: 2003-12-07 02:05:00


I skipped the thread about discovering array sizes until tonight, when I
discovered I need the size of an array type as a compile-time constant --
without partial specialization. Reading through the discussion, I didn't
find a proprosed implementation.

Is this simple implementation correct?

    template<typename T>
    struct array_size {
        static const T* t;
        BOOST_STATIC_CONSTANT(size_t, value = sizeof(T) / sizeof(*t[0]));
    };

For good measure, one could add
BOOST_STATIC_ASSERT(boost::is_array<T>::value).

Jonathan


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