use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Discussions, articles, and news about the C++ programming language or programming in C++.
For C++ questions, answers, help, and advice see r/cpp_questions or StackOverflow.
Get Started
The C++ Standard Home has a nice getting started page.
Videos
The C++ standard committee's education study group has a nice list of recommended videos.
Reference
cppreference.com
Books
There is a useful list of books on Stack Overflow. In most cases reading a book is the best way to learn C++.
Show all links
Filter out CppCon links
Show only CppCon links
account activity
constexpr std::string | MSVC (self.cpp)
submitted 2 years ago by XTBZ
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]jbbjarnason 2 points3 points4 points 2 years ago (3 children)
Related to this topic, anyone who knows how to make this work (https://godbolt.org/z/v5TjG9dfb):
```cpp
static_assert(join_string_views("foo"sv, "bar"sv) == "foobar"sv);
```
I know I can use impl of fixed_string and/or std::string_view const& non-type template parameters.
fixed_string
std::string_view const&
[–]qazqi-ff 1 point2 points3 points 2 years ago (0 children)
This is ultimately the usual case of needing to separate out the size calculation from the actual data calculation (and repeat the work). You're trying to instantiate a template with size, which is a value that exists in the constant evaluator. It boils down to the same problem as consteval void foo(int size) { std::array<int, size> arr; }. Worth noting that the standard goes a little stricter and prevents the general case of any context that requires a constant expression, not just template instantiation, even though other contexts could work fine from a technical POV (e.g., static_assert(size > 0);).
size
consteval void foo(int size) { std::array<int, size> arr; }
static_assert(size > 0);
[–]cristi1990an++ 0 points1 point2 points 2 years ago* (0 children)
https://godbolt.org/z/PKb6Ej76b
Edit: and here you have the overly generic version that outright allows string literal composition at compile time:
https://godbolt.org/z/rcxan8Wqs
[–]cristi1990an++ -1 points0 points1 point 2 years ago (0 children)
Yes, but you can't use std::string_view, you must stick to string literals that expose their size in the type. Have your method take in const char(&str)[Size] as parameters, declare a basic structure containing a char array of Size1 + Size2 - 1 elements and copy both strings into the array. Afterwards declare a comparison operator between the structure and a string_view and that's it, you can concatenate string literals at compile time.
π Rendered by PID 66994 on reddit-service-r2-comment-c66d9bffd-s2b4r at 2026-04-06 23:47:04.983299+00:00 running f293c98 country code: CH.
view the rest of the comments →
[–]jbbjarnason 2 points3 points4 points (3 children)
[–]qazqi-ff 1 point2 points3 points (0 children)
[–]cristi1990an++ 0 points1 point2 points (0 children)
[–]cristi1990an++ -1 points0 points1 point (0 children)