Lesen Sie den aktuellen Monatsindex in der Kompilierungszeit
Ich versuche den Monat von @ umzurechn__DATE__
im FormatMmm
, um in der Kompilierungszeit zu nummerieren. Ich brauche es für gcc und MS VC 2012.
mein Versuch:
template <char C0, char C1, char C2>
struct month{};
template<> struct month < 'J', 'a', 'n'> { static const unsigned id = 1; };
template<> struct month < 'S', 'e', 'p'> { static const unsigned id = 9; };
static const char c0 = __DATE__[0];
static const char c1 = __DATE__[1];
static const char c2 = __DATE__[2];
static const unsigned currId = month<c0, c1, c2>::id; //this gives error
static const unsigned currId2 = month<'S', 'e', 'p'>::id; //this is fine
gibt in MS VC
error C2970: 'month' : template parameter 'C0' : 'c0' : an expression involving objects with internal linkage cannot be used as a non-type argument
aber auf ideone funktioniert gut
Gibt es eine Möglichkeit, diese Arbeit plattform- / compilerübergreifend zu gestalten?
bearbeite
Ich brauche eincompile-time constant
Also Antworten in ähnliche Frage hilft nicht wirklich. Ich muss zum Beispiel zwei Daten subtrahieren (aktuelles und ein Datum im Code) und einen Kompilierungsfehler angeben, wenn die Differenz zwischen diesen beiden groß genug ist.