Kaiyakha
Kaiyakha

Reputation: 1913

Template template partial specialization

Consider the following class template.

template<template<typename U> typename T>
class Entity {
  // Something
};

What is the proper syntax to specialize Entity explicitly:

I cannot find out the proper syntax for this task. The cppreference page does not provide any examples on this issue.

Upvotes: 0

Views: 55

Answers (1)

Jarod42
Jarod42

Reputation: 217075

Here an example of specialization:

template <template<typename> typename C>
class Entity {
  // Something
};

template <typename>
struct A{};

template <>
class Entity<A>
{
// ...
};
// Usage is Entity<A> entity;

Demo

But you probably want something like:

template <typename T>
class Entity {
  // Something
};

template <typename>
struct A{};

template <typename T>
class Entity<A<T>>
{
    // ...
};

template <typename T, template <typename> class C>
class Entity<C<T>>
{
    // ...
};

// Usage is Entity<A<int>> entity;

Demo

Upvotes: 2

Related Questions