c++ - Type-specific static declaration in a template function -
i've written following snippet:
// fix mingw 4.9.2 bug - std::log2 missing there template <typename t> t log2 (t value) { static const t l2 = std::log(t(2)); return std::log(value) / l2; } obviously, l2 should unique each t type because is of type t. work way per c++ standard?
note once instantiated
log2<double> and
log2<float> are 2 different functions. both own static variable. after template instantiation, same situation if had 2 functions:
double log2(double) { static double x; /*...*/ } and
float log2(float) { static float x; /*...*/ } this nicely explained here in example around 6:00.
Comments
Post a Comment