I don't use C++11 yet, so I wrote the functions to_string(whatever)
by myself. They should only be compiled if they don't exist. If I switch to C++11, they should be skipped. I have something like this:
#ifndef to_string
string to_string(int a){
string ret;
stringstream b;
b << a;
b >> ret;
return ret;
}
string to_string(double a){
string ret;
stringstream b;
b << a;
b >> ret;
return ret;
}
#endif
This doesn't work apparently. Is something like this possible and if yes, how?
std::to_string
is C++11 thingto_string
, butstd::to_string
, which is very different. That means, you can't usestd::to_string
if your standard doesn't support it. Now think again - let's assume that you already use C++11. What now? If you use macro from accepted answer, will you for the rest of your life use it instead ofstd::to_string
? Very, very bad idea.#ifdef
only tests the presence of preprocessor definitions, not of regular functions likestd::to_string
. And this is all that#ifdef
can test, as preprocessor directives are executed by the ... preprocessor.