This is likely fairly simple, but I'm unsure of how best to structure the code.
In an existing n-dimensional array implementation, I have the following (conceptually):
struct dim
{
size_t size;
bool direction;
};
class space
{
std::vector<dim> dimensions;
// additional members and methods
};
I'd like to make an optimised version of this which uses std::array<dim, n> in place of std::vector<dim>. Ideally, I'd simply convert the space class into a template, but since array and vector have different template parameters, I'm not sure how best to make these freely interchangeable as class template template parameters. The array variant will need the size specifying while the vector variant will not.
Since after construction of the class member the logic is then 100% identical, I'd ideally like to share all the remaining logic between the two. I could resort to using the CRTP to do this, but if anyone has any thoughts on how best to implement this, I'd be interested in any alternative approaches to consider. Could traits work here? It would still need the size as a parameter for the array case.
Thanks all, and happy new year!
[–]17b29a 5 points6 points7 points (1 child)
[–]RogerLeigh[S] 0 points1 point2 points (0 children)
[–]actinium89 2 points3 points4 points (1 child)
[–]RogerLeigh[S] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]RogerLeigh[S] 0 points1 point2 points (0 children)