preprocessor library, unique token for each translational unit
Hello All, I'm trying to figure out if it is possible to use the preprocessor library to generate a unique token for a given translational unit suitable for use in a variable definition. __FILE__ doesn't work for obvious reasons. The motivation is use the template below to generate a unique function scope static "verbosity" for each translation unit. The extern is necessary to give the non-type template par external linkage but also requires a unique variable name. thanks for any help. -Sean #define INIT_VERBOSITY extern const char BOOST_PP_CAT(file,UNIQUE_TOKEN)[] filename = __FILE__; #define VERBOSITY VerbosityLookup<BOOST_PP_CAT(file,UNIQUE_TOKEN)>::get() template<const char* STR> class VerbosityLookup { static int get() { static int verbosity = initialize(STR); return verbosity; } }
-----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Sean Kelly
Hello All,
I'm trying to figure out if it is possible to use the preprocessor library to generate a unique token for a given translational unit suitable for use in a variable definition. __FILE__ doesn't work for obvious reasons.
Hi Sean. Unfortunately, there is no way to generate a unique symbol in different translation units. The best that you can do is something with __FILE__ (in the root file of the translation unit) at runtime. Regards, Paul Mensonides
participants (2)
-
Paul Mensonides
-
Sean Kelly