Wednesday, February 16, 2011

How to check if a parameter of an inline function is known at compile time?

Programmer Question

Hello,



I have a performance critical inline function. It generates some data, based on a parameter. I want the compiler to optimize the data generation for all invocations, where the parameter is known at compile-time. The problem is that I can't force the compiler to put the optimized data out of the stack to a static constant, since marking the data static would break the case when parameter is not a compile-time constant. Having constant data on the stack hurts performance. Is there a way to deduce (maybe using templates/boost::enable_if), that the parameter is a compile-time constant and choose appropriate implementation of the data generation?



Disclaimer



This question is not the same as How to use different overload of an inline function, depending on a compile time parameter?. This is more generic problem.



Find the answer here

No comments:

Post a Comment

LinkWithin

Related Posts with Thumbnails