0

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?

Simon Elliott
  • 2,087
  • 4
  • 30
  • 39
  • possible duplicate of [C++ template string concatenation](http://stackoverflow.com/questions/4693819/c-template-string-concatenation) – SomeWittyUsername Feb 06 '13 at 10:46
  • @icepack: Thanks for the link. Unfortunately the possible duplicate is tagged as C++11. It starts from the premise of variadic templates. I'm looking for a C++03 solution. – Simon Elliott Feb 06 '13 at 11:02

1 Answers1

2

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

Jan Hudec
  • 73,652
  • 13
  • 125
  • 172