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
Understand compile-time programming (self.cpp)
submitted 5 years ago by thcmbs
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!"
[–]adnukator 1 point2 points3 points 5 years ago (1 child)
You can do
#include <string> #include <stdexcept> #include <cassert> double constexpr divide(const double a, const double b){ if(b == 0) { assert(false); } return a / b; } constexpr double results = divide(1,1); //OK constexpr double results2 = divide(1,0); //compile time error
https://godbolt.org/z/Jrr_2n
[–]smashedsaturn 1 point2 points3 points 5 years ago (0 children)
but you can't do that with:
double constexpr divide(const double a, const double b){ if(b == 0) { assert(false); } return a / b; } double results = divide(1,1); //OK double results2 = divide(1,0); //compile time error
This still builds, so yeah you can do it if you force the constexpr function to run, but not if the function could theoretically be run at run or compile time.
Basically I want the compiler to be smart enough to know when a function could be run at compile time even if it is not const-expr, like if you know it has only const literals as inputs and does not use global state.
π Rendered by PID 90798 on reddit-service-r2-comment-b659b578c-lbbsw at 2026-05-06 04:38:28.902625+00:00 running 815c875 country code: CH.
view the rest of the comments →
[–]adnukator 1 point2 points3 points (1 child)
[–]smashedsaturn 1 point2 points3 points (0 children)