For the moment, I have a class, of the following form:
template <std::size_t N,
class T,
class Allocator = typename std::conditional<N, void, std::allocator<T>>::type>
class myclass {};
Which is a particular container with the following behaviour:
- if
N > 0
, then the container has a static size ofN
, and theAllocator
template parameter should bevoid
. - if
N == 0
, then the container is of dynamic size of, and theAllocator
parameter will be used.
But I am not satisfied with this design because it does not seem elegant. I would like a solution standard-like
or boost-ready
. Maybe such a problem has already been encountered for the design of one of the boost libary. If so what solution has been chosen?
Considering the fact that I want to keep a single version of myclass
, and not two version static_myclass
and dynamic_myclass
.
This might be a good use-case for CRTP. Have a base class which does all the important stuff, which asks its derived class for the actual objects:
Then, you have two versions of it. The dynamic one:
And the static one: