Boost logo

Boost :

From: Neal Becker (ndbecker2_at_[hidden])
Date: 2006-09-21 16:33:47


Kevin Spinar wrote:

> On 9/21/06, Neal Becker <ndbecker2_at_[hidden]> wrote:
>> Maybe I'm missing something obvious. How do I get a compile-time
>> constant for the numDim from a multi_array?
>>
>> For example:
>>
>> template<typename matrix_t>
>> void F (matrix_t const& m) {
>> typedef typename matrix_t::value_type value_type;
>> const int dim = ???
>
> Maybe I'm missing something too, but I couldn't find member for that.
> Is there some reason you aren't doing:
>
> template<typename T, int Dims>
> void F(boost::multi_array<T, Dims>& m) {
> typedef T value_type;
> const int dim = Dims;
> }
>

Yes, that's one approach. Less generic, though.

> Alternatively, you could use this class:
>
> template<typename Matrix>
> struct get_dims {};
>
> // partial template specialization
> template<typename T, int Dims>
> struct get_dims<boost::multi_array<T, Dims> > {
> const int dims = Dims;
> };
>
> template<typename matrix_t>
> void F (matrix_t const& m) {
> typedef typename matrix_t::value_type value_type;
> const int dim = get_dims<matrix_t>::dims;
> // ...
>
> Which perhaps is a little more flexible.
>

Yes, that's what I was using.
I think multi_array should export numDimen to make life a little easier.


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