Declaring global const objects in the header file

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{}; 
+8
c ++ global-variables c ++ 14 range-v3
source share

No one has answered this question yet.

See related questions:

2840
Using global variables in a function
1643
Why can templates be implemented only in the header file?
1483
Why should I use the pointer and not the object itself?
1239
What is the difference between const int *, const int * const and int const *?
904
How to use extern to exchange variables between source files?
838
How to convert std :: string to const char * or char *?
674
Is the value of 'const' the last in a class function declaration?
556
How to declare global variables in Android?
435
What does const mean at the end of a function declaration?
366
Pretty Printed Containers STL STL

All Articles