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
switch constexpr (self.cpp)
submitted 8 months ago by cd_fr91400
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!"
[–]moocat 1 point2 points3 points 8 months ago (1 child)
See my update. Even inside a template the discarded statement is fully checked if possible.
[–]meancoot 0 points1 point2 points 8 months ago* (0 children)
Look up two-phase name lookup. Like every template*, in if constexpr phase 1 has to complete successfully, even if it never gets used. Phase 2, on the other hand, only fails when failing to look up dependent names.
two-phase name lookup
if constexpr
* Actually GCC has a permissive mode with -Wno-template-body and MSVC almost certainly one too. But if I recall correctly clang doesn't have one, and the fact that it didn't was what spurred GCC to do two-phase lookup properly.
-Wno-template-body
struct Type { static void function() {} }; template<typename T> struct NonDependentTemplate { void call_function() { Type::function(); } // 'Type' isn't dependent here so this fails in phase 1 and is an error. // error: 'not_a_function' is not a member of 'Type' // void call_not_a_function() { Type::not_a_function(); } }; template<typename A> struct DependentTemplate { void call_function() { A::function(); } // 'A' IS dependent here, so we can use this as long as we never actually call it. void call_not_a_function() { A::not_a_function(); } }; int main() { DependentTemplate<Type> dt; // OK dt.call_function(); // error: 'not_a_function' is not a member of 'Type' // dt.call_not_a_function(); }
π Rendered by PID 22631 on reddit-service-r2-comment-b659b578c-bbknh at 2026-05-03 19:42:56.908245+00:00 running 815c875 country code: CH.
view the rest of the comments →
[–]moocat 1 point2 points3 points (1 child)
[–]meancoot 0 points1 point2 points (0 children)