Simon Elliott
Simon Elliott

Reputation: 2117

c++ alternative to macro for compile-time string literal concatenation

I want to concatenate a number of string literals at compile time:

#include <iostream>

#define VAR0 "var0 text"
#define VAR1 "var1 text"
#define VAR2 "var2 text"

static const char* concat = "var0:" VAR0 " var1:" VAR1 " var2:" VAR2 ;

int main(int argc, char *argv[])
{
    std::cout << concat << std::endl;
    return(0);
}

This is all very well, but I'd rather use constant expressions instead of macros. Is there any simple way of doing this in C++ 03?

Upvotes: 0

Views: 1520

Answers (1)

Jan Hudec
Jan Hudec

Reputation: 76386

It's only possible to concatenate literals. There is no way to concatenate generic constant char array expressions in C++03. It is, however, possible to concatenate weird template abominations boost::mpl::string from Boost.MPL

Upvotes: 2

Related Questions