依赖名称的部分专业化
我正在构建用于算术操作的模板类型系统,我需要添加一些部分专业,以自动简化。
例如,我有一个struct min
:
struct unknown_t {};
template<typename f>
struct min {
using type = unknown_t;
};
代表-f
(未知直到已知f
)。
我需要表达- ( - f)= f
。我尝试了以下操作:
template<typename f>
struct min<typename min<f>::type> {
using type = f;
};
使用
类模板部分失败的部分专业化包含无法推导的模板参数;
我尝试添加某些type_traits,其他虚拟模板参数,但没有任何效用。
I'm building a template type system for arithmetic operations and I need to add some partial specializations for automatic simplification.
For example, I have a struct min
:
struct unknown_t {};
template<typename f>
struct min {
using type = unknown_t;
};
which represents -f
(unknown until f
is known).
I need to express that -(-f) = f
. I tried this :
template<typename f>
struct min<typename min<f>::type> {
using type = f;
};
which fails with
class template partial specialization contains a template parameter that cannot be deduced;
I tried to add some type_traits, additional dummy template parameters, but nothing worked.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它不能这样工作。考虑
min&lt; f&gt; ::类型
是unknown_t
对于任何f
(除非您专业化)。因此,您不能从min&lt; f&gt; :: type
从f
中推导f
考虑稍微更改设计,并且专门针对
min&lt; f&gt;
而不是<而不是<代码> min&lt; f&gt; ::类型:It cannot work like this. Consider that
min<f>::type
isunknown_t
for anyf
(unless you specialize it). Hence you cannot deducef
frommin<f>::type
Consider to change the design slightly and specialize for
min<f>
rather thanmin<f>::type
: