问题描述
假设我是某个模板库( CTL
)的用户,它定义了一个名为 Hector
Suppose I am a user of a Certain Template Library (CTL
) which defines a template, named, say, Hector
template <class T>
class Hector {...};
在它的文档中,它提供了许多保证 Hector
模板行为。
但是它还定义了某种类型的特殊化 Cool
And in its documentation it gives many guarantees about Hector
template behavior.But then it also defines a specialization for a certain type Cool
template <>
class Hector<Cool> {....};
专业化的目的是更优化的实现 Hector
,但不幸的是由于这种优化,违反了 Hector
的许多保证。
The purpose of the specialization is a more optimized implementation of Hector
, but unfortunately because of this optimization many guarantees of Hector
are violated.
目前我真的不需要优化,我宁愿保留 Hector
的所有保证。有没有什么办法,我可以,没有改变库代码( CTL
是一个非常受人尊敬的库,你知道),规避专业化?任何方式?也许写某种包装?什么?我只想让编译器以正常的,非优化的方式生成代码 Hector< Cool>
,所有的保证。
Currently I really don't need the optimization, I'd rather preserve all the guarantees of Hector
. Is there any way I could, without changing the library code (CTL
is a highly respectable library, you know), circumvent the specialization? Any way at all? Maybe write some sort of wrapper? Anything? I just want to the compiler to generate code for Hector<Cool>
in a normal, non-optimized way, with all the guarantees.
推荐答案
您能够使用相关模板 Reque
t有不希望的专业化?否则,我认为您需要为 Cool
创建一个包装,以便不使用特殊化。
Are you able to use the related template Reque
that doesn't have the undesired specialization? Otherwise I think you'd need to create a wrapper for Cool
so that the specialization isn't used.
这篇关于循环模板专业化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!