Linked Questions
38 questions linked to/from Conveniently Declaring Compile-Time Strings in C++
575 votes
34 answers
397k views
How to convert an enum to a string in modern C++
Contrary to all other similar questions, this question is about using the new C++ features. 2008 c Is there a simple way to convert C++ enum to string? 2008 c Easy way to use variables of enum types ...
1078 votes
6 answers
362k views
What are the rules about using an underscore in a C++ identifier?
It's common in C++ to name member variables with some kind of prefix to denote the fact that they're member variables, rather than local variables or parameters. If you've come from an MFC background, ...
293 votes
11 answers
119k views
"unpacking" a tuple to call a matching function pointer
I'm trying to store in a std::tuple a varying number of values, which will later be used as arguments for a call to a function pointer which matches the stored types. I've created a simplified ...
175 votes
13 answers
87k views
How do I expand a tuple into variadic template function's arguments?
Consider the case of a templated function with variadic template arguments: template<typename Tret, typename... T> Tret func(const T&... t); Now, I have a tuple t of values. How do I call ...
119 votes
12 answers
72k views
Compile time string hashing
I have read in few different places that using C++11's new string literals it might be possible to compute a string's hash at compile time. However, no one seems to be ready to come out and say that ...
79 votes
8 answers
165k views
C-Style Strings as template arguments? [duplicate]
Can C-Style strings be used as template arguments? I tried: template <char *str> struct X { const char *GetString() const { return str; } }; int main() { X<"String"...
41 votes
8 answers
19k views
C++: Can a macro expand "abc" into 'a', 'b', 'c'?
I've written a variadic template that accepts a variable number of char parameters, i.e. template <char... Chars> struct Foo; I was just wondering if there were any macro tricks that would ...
35 votes
3 answers
26k views
How to concatenate static strings at compile time?
I am trying to use templates to create an analogue of the type_info::name() function which emits the const-qualified name. E.g. typeid(bool const).name() is "bool" but I want to see "bool const". So ...
17 votes
5 answers
17k views
Concat two `const char` string literals
Is it possible to concat two string literals using a constexpr? Or put differently, can one eliminate macros in code like: #define nl(str) str "\n" int main() { std::cout << nl("usage: ...
12 votes
4 answers
28k views
static const member variable initialization
Looks like I can init a POD static const member, but not other types: struct C { static const int a = 42; // OK static const string b = "hi"; // compile error }; Why?
28 votes
1 answer
4k views
Will std::string end up being our compile-time string after all?
Many developers and library authors have been struggling with compile-time strings for quite a few years now - as the standard (library) string, std::string, requires dynamic memory allocation, and ...
18 votes
2 answers
10k views
Compile time string encryption using constexpr
I want to have a compile-time string encryption, such that I could write in my code: const auto encryptedInvalidLicense = ENCRYPT("Invalid license"); std::cout << encryptedInvalidLicense....
16 votes
1 answer
5k views
C++17 constexpr string parsing
Sorry that this will be a long post, but I feel like you need all of the code to see what's going on. So, I have been experimenting with an idea for compile time string to data structure parser. Think ...
4 votes
2 answers
4k views
Why use constexpr
Let's take a simple SFINAE templating example #include <iostream> template <typename T> struct has_typedef_foobar { // Types "yes" and "no" are guaranteed to have different sizes, ...
6 votes
4 answers
10k views
Concatenate compile-time strings in a template at compile time?
Currently I have: template <typename T> struct typename_struct<T*> { static char const* name() { return (std::string(typename_struct<T>::name()) + "*").c_str(); } ...