Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
118 views
in Technique[技术] by (71.8m points)

c++ - Circumventing template specialization

Suppose I am a user of a Certain Template Library (CTL) which defines a template, named, say, Hector

template <class T>
class Hector {...};

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> {....};

The purpose of the specialization is a more optimized implementation of Hector, but unfortunately because of this optimization many guarantees of Hector are violated.

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.

question from:https://stackoverflow.com/questions/6499007/circumventing-template-specialization

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...