Suppose I have a class
template <typename T>
struct Foo {
T data;
};
where I want to enforce the fact that T
is a known templated type. For instance, suppose that I want T
to be a std::vector
of something. Now one way to handle this problem would be to redefine the class so that the template parameter is also the template parameter of the data function:
template <typename S>
struct Foo {
std::vector<S> data;
};
I do not want to do that. In this specific case, it feels more natural to require the user to construct a foo
object like this:
Foo<T<S>> f;
which, in the case where we want T
to be a vector
, looks like
Foo<std::vector<S>> f;
Is there anyway to keep the first form of the class, which requiring that T
be of a specific class? Perhaps a static_assert
?