admin管理员组文章数量:1124680
Consider the following class template.
template<template<typename U> typename T>
class Entity {
// Something
};
What is the proper syntax to specialize Entity
explicitly:
- by
U
, - by
T
(keeping it as a template)?
I cannot find out the proper syntax for this task. The cppreference page does not provide any examples on this issue.
Consider the following class template.
template<template<typename U> typename T>
class Entity {
// Something
};
What is the proper syntax to specialize Entity
explicitly:
- by
U
, - by
T
(keeping it as a template)?
I cannot find out the proper syntax for this task. The cppreference page does not provide any examples on this issue.
Share Improve this question edited 2 days ago Kaiyakha asked 2 days ago KaiyakhaKaiyakha 1,8131 gold badge11 silver badges28 bronze badges 8 | Show 3 more comments1 Answer
Reset to default 2Here 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
本文标签: cTemplate template partial specializationStack Overflow
版权声明:本文标题:c++ - Template template partial specialization - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736646540a1946119.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
U
there. – Jarod42 Commented 2 days agoT
only, and an argument for it would be something likestd::vector
(no args), whereasstd::vector<int>
won't be a proper argument since it's a type, not a template. – StoryTeller - Unslander Monica Commented 2 days agoT
parameter must be a concrete template, not just someT
template. – Kaiyakha Commented 2 days agoU
there? – Kaiyakha Commented 2 days ago