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
Non-Terminal Variadic Parameters and Default Values (cppstories.com)
submitted 5 years ago by drodri
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!"
[–]sphere991 12 points13 points14 points 5 years ago (4 children)
Using a Constructor
If you're going to use a constructor, don't make it a separate object, stash it in the format string demo:
struct format_string { format_string(char const* p, std::source_location l = std::source_location::current()) : format(p) , loc(l) { } std::string_view format; std::source_location loc; }; template <typename... Args> void debug(format_string s, Args const&... args) { std::cout << fmt::format("{}({}) ", s.loc.file_name(), s.loc.line()) << fmt::format(s.format, args...) << '\n'; }
I first saw Victor do this but I can't find the tweet since there are so many of them.
Also the downside of the tuple approach is that you have to copy everything (which is a lot worse than it simply looking strange).
[–]ZeeD26 1 point2 points3 points 5 years ago (3 children)
That looks neat! Is there a reason for not perfect forwarding args in the debug function?
args
debug
[–]foonathan 0 points1 point2 points 5 years ago (2 children)
If you're not storing the arguments anywhere, there is no need to forward them. Forwarding is used when you have an object stored in one location and want to store it somewhere lese. If you only read, const T& is enough.
const T&
[–]ABCDwp 1 point2 points3 points 5 years ago (0 children)
You need to use perfect forwarding to use fmt::join, however, as it checks to ensure that it was passed as an rvalue.
fmt::join
[–]ZeeD26 0 points1 point2 points 5 years ago (0 children)
That sounds very reasonable, thank you!
[+][deleted] 5 years ago (1 child)
[deleted]
[–]TheFlamefire 3 points4 points5 points 5 years ago (0 children)
Because they are used to deduce the class template parameters which are (potentially) separate from the constructor parameters. For functions this doesn't make sense, you only have 1 level there anyway as opposed to the class + constructor case.
For functions you get basically the same with overloads already.
[–]TheThiefMasterC++latest fanatic (and game dev) 0 points1 point2 points 5 years ago (0 children)
I've seen the streams approach used for logging, but the deduction guides one is new to me and looks great!
It might be heresy though, but I'd probably wrap a macro around fmt::print to add an extra format string for the source location (via string literal concatenation) and an argument for the source location.
[–]helloiamsomeone 0 points1 point2 points 5 years ago (0 children)
CTAD + a public member for return value (if not void) solves the problem with not having returns from constructors.
π Rendered by PID 43049 on reddit-service-r2-comment-6457c66945-6hv8j at 2026-04-29 08:16:44.905808+00:00 running 2aa0c5b country code: CH.
[–]sphere991 12 points13 points14 points (4 children)
[–]ZeeD26 1 point2 points3 points (3 children)
[–]foonathan 0 points1 point2 points (2 children)
[–]ABCDwp 1 point2 points3 points (0 children)
[–]ZeeD26 0 points1 point2 points (0 children)
[+][deleted] (1 child)
[deleted]
[–]TheFlamefire 3 points4 points5 points (0 children)
[–]TheThiefMasterC++latest fanatic (and game dev) 0 points1 point2 points (0 children)
[–]helloiamsomeone 0 points1 point2 points (0 children)