mercredi 6 décembre 2017

Using std::make_array with C structs

I have been experimenting with std::make_array(), and overall very happy with the results. The code is a little cleaner and I don't have to specify the array size as a template parameter.

One unknown I've run into is how to use make_array with raw C structs. For example,

struct Point {
    int x, y;
};

constexpr auto triangle = std::make_array<point>({3, 3}, {5, 5}, {1, 5});

I can get this to work if I create a constexpr constructor for Point. This isn't always an option - some of my structs are defined in headers used by C code. Using std::array's constructor works fine. Is there any way to get this to work with std::make_array?

Aucun commentaire:

Enregistrer un commentaire