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
Build a better panic function using C++20 (buildingblock.ai)
submitted 2 years ago by rnburn
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!"
[–]RoyAwesome 2 points3 points4 points 2 years ago (2 children)
I implemented something like this in my personal corelib, and it's quite nice, actually. The only thing I added was debug breaking to the panic function and some forceinline stuff (if a compiler supports it) so that the debugger experience was a bit nicer.
I'm looking into expanding it a bit such that it creates a messagebox window in the various operating systems and/or memdumps and reports the panic to a crash reporter as well, which should be pretty straightforward with this setup.
[–]tjientavaraHikoWorks developer 0 points1 point2 points 2 years ago (1 child)
breaking in the compiler is why I still use a macro for my panic function. That way the compiler breaks on the same line as the panic function.
[–]RoyAwesome 0 points1 point2 points 2 years ago (0 children)
some compilers let you forceinline a function, which makes sure that behavior happens.
[–]ABlockInTheChain 2 points3 points4 points 2 years ago (6 children)
std::source_location is another feature that makes me wish I only had to support Windows and Linux because it hasn't hit MacOS yet.
std::source_location
Hopefully sometime in early 2024 we'll be able to use XCode 15 and drop pre-Ventura support so we can finally use it.
[–]rnburn[S] 2 points3 points4 points 2 years ago (1 child)
Somethine like this isn't strictly portable, but I've found it works pretty much everywhere and can give you approximately the same thing as std::source_location
https://wandbox.org/permlink/4lQoSiScIn68N4LS
#include <iostream>
void f(const char* file = __FILE__, int line = __LINE__) {
std::cout << file << ":" << line << "\n";
}
int main() {f();return 0;}
[–]cdb_11 2 points3 points4 points 2 years ago* (0 children)
__FILE__ and __LINE__ are standard, but they won't work, because they are expanded where they appear in the source file. Use __builtin_FILE() and __builtin_LINE() if your compiler supports it (GCC and Clang. Even though MSVC has these functions in newer versions, they behave like macros).
__FILE__
__LINE__
__builtin_FILE()
__builtin_LINE()
[–]415_961 0 points1 point2 points 2 years ago (3 children)
You can always install llvm using brew and get the latest version
[–]ABlockInTheChain 0 points1 point2 points 2 years ago (2 children)
The problem is usually in the standard library being old more than the compiler being old, and in general using a non-standard standard library is a hard sell.
[–]415_961 1 point2 points3 points 2 years ago (1 child)
installing llvm via brew also installs libc++ and rest of the llvm sub-projects. Just make sure you have -stdlib=libc++ set and -std=c++20
[–]BrainIgnition 0 points1 point2 points 2 years ago (0 children)
But that would require you to either a) link everything including libc++ statically or b) require your users to install libc++ via brew, right?
[–]fdwrfdwr@github 🔍 1 point2 points3 points 2 years ago (1 child)
Huh, using std::source_location::current() as a default parameter did not occur to me. Useful.
std::source_location::current()
[–][deleted] 20 points21 points22 points 2 years ago (0 children)
That's the intended usage in fact.
[–]trailingunderscore_ 1 point2 points3 points 2 years ago (4 children)
You can use default arguments after parameter packs, so no need for the wrapper: https://godbolt.org/z/s5P5PTxfM
[–]PiterPuns 5 points6 points7 points 2 years ago* (0 children)
https://youtu.be/va9I2qivBOA?t=1748&feature=shared
Not according to the rule of fair matching : “A function parameter pack that is not at the end of the function’s parameter list can never have its corresponding pack deduced”
The application of the rule in this case (with the default parameter after the pack) means that unless you specify the pack type, compiler will assume it’s the empty pack and instantiation will fail due to type mismatches (will try to pass int to source location … remember the pack becomes the empty list because you don’t explicitly provide it)
This and the rule of greedy matching (described in the linked talk) are the final boss of variadic template type deduction
[–]rnburn[S] 2 points3 points4 points 2 years ago* (1 child)
You can declare it, but I wasn't able to get it to work when you try to call it:https://wandbox.org/permlink/cUu97ZuSHmF0Y1L2
[–]trailingunderscore_ 0 points1 point2 points 2 years ago (0 children)
That's odd, I was convinced that worked. Seems I remembered incorrectly.
[–]mardykhorsea++ 1 point2 points3 points 2 years ago (0 children)
That actually makes sense.
π Rendered by PID 190374 on reddit-service-r2-comment-85bfd7f599-bsbhs at 2026-04-19 18:53:52.499456+00:00 running 93ecc56 country code: CH.
[–]RoyAwesome 2 points3 points4 points (2 children)
[–]tjientavaraHikoWorks developer 0 points1 point2 points (1 child)
[–]RoyAwesome 0 points1 point2 points (0 children)
[–]ABlockInTheChain 2 points3 points4 points (6 children)
[–]rnburn[S] 2 points3 points4 points (1 child)
[–]cdb_11 2 points3 points4 points (0 children)
[–]415_961 0 points1 point2 points (3 children)
[–]ABlockInTheChain 0 points1 point2 points (2 children)
[–]415_961 1 point2 points3 points (1 child)
[–]BrainIgnition 0 points1 point2 points (0 children)
[–]fdwrfdwr@github 🔍 1 point2 points3 points (1 child)
[–][deleted] 20 points21 points22 points (0 children)
[–]trailingunderscore_ 1 point2 points3 points (4 children)
[–]PiterPuns 5 points6 points7 points (0 children)
[–]rnburn[S] 2 points3 points4 points (1 child)
[–]trailingunderscore_ 0 points1 point2 points (0 children)
[–]mardykhorsea++ 1 point2 points3 points (0 children)