Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 693
Armen Tsirunyan Avatar asked Jun 27 '11 21:06

Armen Tsirunyan


2 Answers

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.

like image 124
Mark B Avatar answered Sep 19 '22 05:09

Mark B


You could wrap cool in a dummy type to prevent the template from specializing it.

like image 35
Mikola Avatar answered Sep 22 '22 05:09

Mikola