I would like to create a function that prints to the command line with a set prefix that will never change at runtime, so I would like to set it at compile time. Something like:
print_sp(const char * msg)
{
printf("%s%s", prefix, msg);
}
Is there a way I can do this using constexpr in c++? If possible to do it in C++11 it would be even better.
I am trying to avoid having a singleton class with a SetPrefix method here.
1
One simple way to do it would be with the C preprocessor:
#define MYPREFIX "myprefix"
void print_sp(const char * msg)
{
printf(MYPREFIX "%s", msg);
}
3