开发者

How to check which specialized template is compiled in

I have a te开发者_如何学Pythonmplated function, which is also specialized with built-in types (int, float). Is there a way to display which functions are being used and which are being pruned out by the compiler, at compile-time?? Perhaps using #pragma??

template<typename T>
int func(T val)
{
 ...
}

template<>
int func<float>(float val)
{
 ...
}

// etc


Your best option is to just leave all of the functions undefined, and see what errors the compiler throws at you when it tries to instantiate the template functions. If you need to do this multiple times, perhaps setting up a #ifdef around that code would allow for a "dump out the used functions" build. From there it would be a simple shell script or something to pull out the types of the functions instantiated from the compiler's error log.

Alternatively, you could possibly add a compile error based on the template parameter:

template<typename T>
int func(T val)
{
    T::this_version_is_being_included;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜