I'd like to initialize a boost::multi_array inline in some code. But I don't think the boost::multi_array supports initialization from an initializer list. Here's what I have so far:
// First create a primitive array, which can be directly initialized
uint8_t field_primitive[4][8] = {
{ 1,1,1,1,1,1,1,1 },
{ 1,2,1,2,1,2,1,2 },
{ 1,1,2,2,2,2,2,2 },
{ 1,2,2,2,2,2,2,2 }
};
// Create the boost::multi_array I actually want to use
boost::multi_array<uint8_t, 2> field(boost::extents[4][8]);
// Compact but yucky approach to copying the primitive array contents into the multi_array.
memcpy(field.data(), field_primitive, field.num_elements() * sizeof(uint8_t));
I like that I can compactly express the matrix contents using the curly brace intializer list. But I don't like the "memcpy" and I don't like the use of a throwaway primitive array. Is there a nicer way to populate my boost::multi_array from a readable inline set of values in the code?