What are some uses of template template parameters?

后端 未结 10 1012
无人共我
无人共我 2020-11-22 03:41

I\'ve seen some examples of C++ using template template parameters (that is templates which take templates as parameters) to do policy-based class design. What other uses do

10条回答
  •  别跟我提以往
    2020-11-22 04:09

    Here's another practical example from my CUDA Convolutional neural network library. I have the following class template:

    template  class Tensor
    

    which is actually implements n-dimensional matrices manipulation. There's also a child class template:

    template  class TensorGPU : public Tensor
    

    which implements the same functionality but in GPU. Both templates can work with all basic types, like float, double, int, etc And I also have a class template (simplified):

    template