Boost logo

Boost :

Subject: [boost] [static] A useful static variable generator.
From: Dongfei Yin (yin.dongfei_at_[hidden])
Date: 2009-03-20 01:53:27

    Some time, the sequence of static variable initialization always
make something bad.
the piece of code below will useful about this problem.

class static_
    template <int N, class T>
    static T& var()
        static T instance;
        return instance;

    ~static_() {}

so, if a static variable of std::string is wanted, I will use:

static_::var<0, std::string>() = ":)";

the first template parameter is used for when many static variable of
same type is needed.
most important thing is all the variable will be initialized before use.

Just for fun.


Boost list run by bdawes at, gregod at, cpdaniel at, john at