In the Eric Niebler range-v3 library, it provides many headers, each of which has its own global function object. They are all declared the same. It provides a static_const class static_const :
template<typename T> struct static_const { static constexpr T value {}; }; template<typename T> constexpr T static_const<T>::value;
And then every function object of type F declared as:
namespace { constexpr auto&& f = static_const<F>::value; }
What are the benefits of injecting an object through the static_const template and into an unnamed namespace, rather than just writing:
static constexpr F f{};
c ++ global-variables c ++ 14 range-v3
Barry
source share