
On 12/06/07 18:40, Larry Evans wrote: [snip]
Then, the rank of array_fix_size would be Shape::size. You could calculate of strides using some mpl metafunction on Shape:
typedef some-mpl-function < Shape >::type strides ;
and then allocate storage as:
Value values [ mpl::at_c<strides,Strides::size>::value ] ;
Then operator[] could be defined as:
Value& operator[](boost::array<unsigned,Shape::size>const& indices) { return values[some_offset_function_<strides>(indices)]; }
where some_offset_function simply performs a dot product of the compile time vector, strides, with the runtime vector, indices. Andreas,
There actually some code to illustrate this in the fold_seq_test.zip file at: http://www.boost-consulting.com/vault/index.php?&directory=Template%20Metaprogramming It's in the test_array_index_offset function. The fold_seq.hpp file includes several other files on my local disk and I could upload those if you're interested, but I think the test_array_index_offset code illustrates the general idea. Hm... No actually it differs from what's suggested in my previous post. Instead of that, there would be something like: typedef unsigned index_type ; struct inner_product_static_dynamic_ftor { explicit inner_product_static_dynamic_ftor ( index_type const* indices ) : cur_index_ptr(indices) , offset(0) {} index_type const* cur_index_ptr ; index_type offset ; template<class PartialProductElement> void operator()(PartialProductElement)const { offset+=PartialProductElement::value*(*cur_index_ptr); ++cur_index_ptr; } }; template < class Strides
index_type offset_at_indices ( array<index_type,mpl::size<Strides>::value>const& a ) { index_type const*indices=a.data(); inner_product_static_dynamic_ftor ip(indices); typedef mpl::pop_back<Strides>::type strides;//rm total array size. mpl::for_each<strides>(ip); return ip.offset; } *WARNING*: not compiled.