Boost logo

Boost :

From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2022-01-01 13:47:58


On 1/1/22 13:42, Ivan Matek via Boost wrote:
> I don't know much about library development, but with variadic templates
> does not seem so hard, although every library development is much harder
> than regular user code.
>
> Sure boost::array probably wants to support ancient compilers, but variadic
> version could exist only for "modern"(I do not consider >10y old standards
> modern) C++.
>
> I found this std:: proposal
> http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2013/n3794.html#Ch05
> from 9 y ago,
> also author seemed to have some working impl on github
> https://github.com/CTMacUser/ArrayMD/tree/master/include/boost/container
>
> But I guess none of it ever progressed.
>
> Does anybody knows more about this?
> It is not trivial since there are probably a ton of edge cases, typdefs,
> semantics(what should size return?, I would say array of dims) to deal
> with, but I think it would be a nice extension since I find nested
> std::array hideous (with current syntax), e.g.:
>
> std::array<std::array<int,3>, 4> arr;
>
> I would like to have this
> boost::array<int,4,3> arr;
>
> P.S. I know I can use Eigen or some other library, but I think if not std
> then at least boost should support simple way to have multidim arrays.

To my knowledge, this cannot be supported in a generic manner as a
variadic sequence cannot be expanded into a sequence of array
dimensions. Therefore the support would require a set of template
specializations up to a predefined limit, a-la Boost.MPL and other C++03
libraries.

The next thing is the result of operator[], which can no longer be a
simple reference. The reference would have to retain information of the
lower level dimensions in order to apply the index correctly. Then there
are iterators and related APIs (front(), back(), size()) which no longer
make sense, unless applied to the last dimension. Either that API has to
be removed or redefined with new semantics.

The bottom line is that such a multi-dimensional array would be a much
more complicated component that is drastically different from the
one-dimensional array. At the same time, array<> is supposed to be a
thin and lightweight replacement for the language built-in arrays. IMO,
it is not a worthy tradeoff.

BTW, you still have the multidimensional language built-in arrays. Why
can't you use those?


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