Boost logo

Boost :

Subject: [boost] Boost house style?
From: Robert Jones (robertgbjones_at_[hidden])
Date: 2008-10-16 09:29:07

I've been looking at the implementation of Boost.multi_array, and in
particular the mechanics of generating the array extents objects.

The problem to be solved is to allow the extent of a multi-dimensional
array to be specified with this syntax


since this forms a nice nmemonic. The solution is a templated type

template <unsigned ndims> class extents_type {.....};

which contains a subscripting operator which returns its own
object with an extra subscript tacked-on

extents_type<ndims+1> operator[]( unsigned n ) {....}

OK. That's all fairly straight-forward. The interesting bit is the
required for the initial dimensionless object. The Boost implementation
goes through several intermediate objects which eventually resolve to
a boost::array<unsigned, ndims> in general, or a boost::array<unsigned, 1>
for the dimensionless case.

My questions about this are:

* why boost::array<unsigned, 1> rather than boost::array<unsigned, 0>?
an array of zero elements is an odd beast, but it seems to work, with
begin() equal
to end() as you'd expect.

* is it necessary to employ so many different objects to resolve the special
Is this an aspect of the Boost style guidlelines, or simply some C++ good
that I've missed?

The existing implementation of this is in boost/multi_array/range_list.hpp
if you're

Thanks, Rob.

Boost list run by bdawes at, gregod at, cpdaniel at, john at