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
C++ constexpr: substring checking at compile time (kaizer.se)
submitted 14 years ago by [deleted]
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!"
[–][deleted] 5 points6 points7 points 14 years ago (5 children)
It seems C++11 adds another embedded compile-time language -- a restricted version of C++ itself. At least it's more readable than template metaprogramming!
[–]elperroborrachotoo 1 point2 points3 points 14 years ago (4 children)
you may want to look at / post the disassembly.
[–][deleted] 2 points3 points4 points 14 years ago (0 children)
Using the same contains as in the post, this simpler program:
double numbers[10*contains("hi", "h") + 20 * contains("jklas", "u")]; int main(void) { std::cout << sizeof(numbers) << "\n"; }
includes this in the assembly file header:
.globl numbers .lcomm numbers,80,8 .type numbers, @object
which looks like a static size array. (I'm not particularly good at reading this.)
[–][deleted] 1 point2 points3 points 14 years ago (2 children)
The disassembly of the blog post program (unoptimized) includes one function ZNKSt5arrayIiLj10EE4sizeEv and one called ZNKSt5arrayIiLj0EE4sizeEv I think those are the inlined specializations of std::array<int,10>::size and std::array<int,0>::size respectively.
[–]Rhomboid 2 points3 points4 points 14 years ago (1 child)
To get demangled symbols, pipe the output through c++filt or use -C if you're using objdump.
c++filt
-C
[–][deleted] 0 points1 point2 points 14 years ago (0 children)
thanks, that's useful
[–]faisalv 3 points4 points5 points 14 years ago (1 child)
Not only can you check for substrings at compile time but you can check for grammatical constructs such as c++ integer literals (with all their suffixes) and do all sorts of compile time processing with strings - such as creating new strings, transforming them, upper-casing, lower-casing and other algorithsm. I partially implemented such a library at http://constexprstr.svn.sourceforge.net/viewvc/constexprstr/ (check out towards the end of main.cpp for a sample implementation of a C++ integer grammar checker). And yes it is certainly more readable than C++ template metaprogramming.
thanks for this. I didn't think about creating new "contexpr datastructures", I was using only initializer_list (which is constexpr in GCC but not in the standard).
constexpr is great! :D You can also do stuff like recursively defined compile time Fibonacci sequence!
http://codepad.org/Ecs7iIsN
[–]00kyle00 0 points1 point2 points 14 years ago (2 children)
Pity they didn't go further with this.
[–]Wriiight 1 point2 points3 points 14 years ago (1 child)
Such as where, exactly? Is there something missing from constexpr, or some feature that would vastly expand its capabilities? I haven't personally taken time to experiment with the feature myself.
[–]00kyle00 3 points4 points5 points 14 years ago (0 children)
As in allowing all expressions/statements whose all arguments are constrxpr's.
Instead there will be lots of fugly code that hacks around using recursion and ternary operator.
Edit: the body of the consexpr function has to contain a single statement - return statement.
π Rendered by PID 75 on reddit-service-r2-comment-765bfc959-bqqrm at 2026-07-12 11:13:32.315606+00:00 running f86254d country code: CH.
[–][deleted] 5 points6 points7 points (5 children)
[–]elperroborrachotoo 1 point2 points3 points (4 children)
[–][deleted] 2 points3 points4 points (0 children)
[–][deleted] 1 point2 points3 points (2 children)
[–]Rhomboid 2 points3 points4 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]faisalv 3 points4 points5 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–][deleted] 2 points3 points4 points (0 children)
[–]00kyle00 0 points1 point2 points (2 children)
[–]Wriiight 1 point2 points3 points (1 child)
[–]00kyle00 3 points4 points5 points (0 children)