0

I would like to define a struct Primitives that contains containers that hold non struct-templated types as I tried to bellow. The structs Sphere, Plane and Triangle are all defined before this struct as well as the enum Device. I would like for the container of these types to be templated by the user of the struct without specifying the types they hold as the struct should do that. An arbitrary container type might looks like (in my case since I'm abstracting CUDA host/device memory):

template <typename T, Device D>
struct my_container {
    /*...*/
};

And the Primitives class I would like to define looks like:

template <typename Container, Device D>
struct Primitives {
    Container<Sphere, D>   spheres;
    Container<Plane, D>    planes;
    Container<Triangle, D> triangles;
}; // Primitives

When I compile it with nvcc on windows which uses cl.exe, I get the error message:

error: template parameter "Container" may not have a template argument list

I understand why I get this message but I don't know if there is a way to achieve what I want to do.

cigien
  • 57,834
  • 11
  • 73
  • 112
Henry Le Berre
  • 910
  • 9
  • 18
  • 2
    What you're looking for is a "template template parameter" - a template parameter that is a placeholder not for a concrete type, but for a template type! That's what your `Container` template parameter is: a placeholder for a _template type_. See this page https://en.cppreference.com/w/cpp/language/template_parameters (and there are other pages as well) describing how you do this. – davidbak Oct 28 '20 at 23:50
  • thanks! Could you give an example of how I could make it work? – Henry Le Berre Oct 28 '20 at 23:52
  • Yes it does! I found it quite hard to search for it. – Henry Le Berre Oct 28 '20 at 23:53
  • 1
    As usual, you kind of have to know the answer - or at least what it is _called_ - before you can find it! – davidbak Oct 28 '20 at 23:53

0 Answers0