Concat two `const char` string literals

A little bit of constexpr, sprinkled with some TMP and a topping of indices gives me this: #include <array> template<unsigned… Is> struct seq{}; template<unsigned N, unsigned… Is> struct gen_seq : gen_seq<N-1, N-1, Is…>{}; template<unsigned… Is> struct gen_seq<0, Is…> : seq<Is…>{}; template<unsigned N1, unsigned… I1, unsigned N2, unsigned… I2> constexpr std::array<char const, N1+N2-1> concat(char const (&a1)[N1], … Read more

How should I write a Windows path in a Python string literal?

you can use always: ‘C:/mydir’ this works both in linux and windows. Other posibility is ‘C:\\mydir’ if you have problems with some names you can also try raw string literals: r’C:\mydir’ however best practice is to use the os.path module functions that always select the correct configuration for your OS: os.path.join(mydir, myfile) From python 3.4 … Read more

If char*s are read only, why can I overwrite them?

The presented code snippet does not change the string literals themselves. It only changes the values stored in the pointer fruit. You can imagine these lines char* fruit = “banana”; fruit = “apple”; the following way char unnamed_static_array_banana[] = { ‘b’, ‘a’, ‘n’, ‘a’, ‘n’, ‘a’, ‘\0’ }; char *fruit = &unnamed_static_array_banana[0]; char unnamed_static_array_apple[] = … Read more

String literals not allowed as non type template parameters

Your compiler ultimately operates on things called translation units, informally called source files. Within these translation units, you identify different entities: objects, functions, etc. The linkers job is to connect these units together, and part of that process is merging identities. Identifiers have linkage†: internal linkage means that the entity named in that translation unit … Read more