Boost logo

Boost Users :

From: Sean Kelly (sean.kelly_at_[hidden])
Date: 2005-01-05 14:08:56

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.


#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;

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at