确定模板参数的相等性? [英] Determine equality of template parameters?
本文介绍了确定模板参数的相等性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
让我们说我有一个功能模板如下:
模板< class T,U类>
foo {
...
}
但是,如果T == U,我想要有不同的行为。
如何检查?
如果我添加以下专业化,它是否会按预期工作?
模板< class T,T类> < br $>
foo {
...
}
谢谢,
Joseph
Let''s say I have a function template as follows:
template<class T, class U>
foo {
...
}
However, I''d like to have different behavior if T == U.
How can I check that?
Will it work as desired if I add the following specialization?
template<class T, class T>
foo {
...
}
Thanks,
Joseph
推荐答案
Joseph Turian写道:
Joseph Turian wrote:
让我们说我有一个功能模板如下:
模板< T级,U级>
foo {
...
}
我假设这个是一个类模板。
但是,如果T == U,我想要有不同的行为。
我该怎么检查?
会不会如果我添加以下专业化,可以按照需要工作吗?
模板< class T,class T& gt;
foo {
...
}
模板< class T>
class foo< T, T>
{
// ...
};
谢谢,
Joseph
Let''s say I have a function template as follows:
template<class T, class U>
foo {
...
}
I''m assuming this is a class template.
However, I''d like to have different behavior if T == U.
How can I check that?
Will it work as desired if I add the following specialization?
template<class T, class T>
foo {
...
}
template<class T>
class foo<T,T>
{
// ...
};
Thanks,
Joseph
red floyd写道:
red floyd wrote:
假设我有一个函数模板如下:
Let''s say I have a function template as follows:
我假设这是一个类模板。
I''m assuming this is a class template.
不,功能模板。
无论如何,谢谢。
Joseph
No, function template.
Thanks anyway.
Joseph
BTW,我的原创问题仍然存在:
如果两个
类型相同,有没有人知道如何进行模板专业化?
这就是我要做的事情:
如果这两种类型不相等,我会在做之前从T转换为U
与U items。
如果两种类型相同,我想保存转换ead。
谢谢
Joseph
BTW, my original question still stands:
Does anyone know how to do template specialization in case the two
types are equal?
Here''s what I''m trying to do:
If the two types are unequal, I convert from T to U before doing stuff
with the U items.
If the two types are equal, I want to save the conversion overhead.
Thanks
Joseph
这篇关于确定模板参数的相等性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文