vendredi 24 février 2017

Initializing a static char based on template parameter

I want to do something like this :

template<typename T>
const char * toStr(T num)
{
    thread_local static char rc[someval*sizeof(T)] str = "0x000...\0"; // num of zeros depends on size of T
    // do something with str
    return str;
}

I'm guessing there's some template metaprogramming I'd have to do but I'm not sure where to start.

Edit:

I found a related question here: How to concatenate a const char* in compile time

But I don't want the dependency on boost.

Aucun commentaire:

Enregistrer un commentaire