let's have several container classes these:
template<typename t> class container { /* ... */ }; template<typename t, size_t> class array : public container<t> { /* fixed-sized container */ }; template<typename t> class vector : public container<t> { /* variable-sized container */ };
and have class accepts 1 of these template parameter:
template<typename t, template<typename> class u, size_t m> class polygon { u<t> vertices; // problem, if user passes array (it needs 2 parameters) u<t, m> vertices; // problem, if user wants use variable-sized container (it needs 1 parameter) };
my question is, can somehow (probably through tricky template parameter magic) make consuming class accept type of container (fixed or variable-sized, differing template signatures)?
the guarantees template signatures are, if fixed-sized container have 2 parameters <type, size>
, 1 if variable-sized container <type>
it's way less tricky think is. can template on container itself:
template <class container> class polygon { container vertices; };
this work meets container requirements, fixed sized or not.
the problem of choosing right template arguments container gets moved instantiation point parameters , types must known anyways.
Comments
Post a Comment