In Java, when using genericism, you can specify what types are allowed to be used by doing something like this:
public class A<T inherits B>
{
public A(T e);
}
If the semantics is wrong I'm sorry, I haven't written Java in quite a few years.
Is there a way to do so with templates in C++, and if so how? From what I have seen in my research so far, people seem to be doing it through the use of extra arguments, but that seems like a worse solution than using like a static_assert
.
Something like this I guess:
template<typename T : std::vector>
class A
{
A(T t) {}
};
In the example above T
inherits from std::vector
and as such allows for all potential classes that extend the capabilities of the STL vector class