c++boost-multi-array

boost::multi_array_ref vs. boost::multi_array&


Is there a reason to prefere the usage of boost::multi_array_ref over boost::multi_array&? Why is the adapter class boost::multi_array_ref provided by boost at all?


Solution

  • Those would be two quite different things. boost::multi_array& is a reference which can be bound to already existing multi array, and you can use it for indirection to a 'true' multi array container.

    On the other hand, boost::multi_array_ref is an adaptor - it allows one to use it with any other block of continuous data as if it was a multi array (while in fact it is not). (I personally think this is not a great name, as it implies a reference to the container)

    See https://www.boost.org/doc/libs/1_73_0/libs/multi_array/doc/reference.html for more details.