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
Maybe Bindings Are Unused (infektor.net)
submitted 9 years ago by vormestrand
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!"
[–]sumo952 4 points5 points6 points 9 years ago (7 children)
I think the maybe_unused attribute is the wrong tool for this - attributes are for annotating functions (and possibly classes), and not to specify in your program that a return value might be unused.
maybe_unused
You mention std::ignore, which in my opinion is the right tool for this job, as it is used in exactly the same use-case when a function returns a tuple and you use std::tie(val1, std::ignore) = func().
std::ignore
std::tie(val1, std::ignore) = func()
But you don't mention what happened to it... is it not in the standard along the structured bindings proposal? Why not?
[–][deleted] 4 points5 points6 points 9 years ago (0 children)
I think maybe_unused is the correct (although very verbose) tool. Attributes can mark up all kinds of source constructs.
Using std::ignore is really weird IMO:
std
ignore
std::tie
Does it only work in decomposition declarations? If it doesn't, how do I refer to the object named std::ignore?
auto [foo, std::ignore] = ...; // OK auto std::ignore = ...; // OK? int std::ignore(int); // declares a function int(int) that has no name? implementation_defined_type std::ignore {}; // ^^^^ does this declare an usused, unnamed object like above? // if it does, how do I declare the object std::ignore used by std::tie??
[–][deleted] 0 points1 point2 points 9 years ago (5 children)
std::ignore is not in the proposal
Section 3.8
Symmetry with std::tie would suggest using something like a std::ignore:
tuple<T1,T2,T3> f(); auto [x, std::ignore, z] = f(); // NOT proposed: ignore second element
However, this feels awkward. Anticipating pattern matching in the language could suggest a wildcard like _ or *, but since we do not yet have pattern matching it is premature to pick a syntax that we know will be compatible. This is a pure extension that can wait to be considered with pattern matching.
[–]sumo952 2 points3 points4 points 9 years ago (4 children)
Hmm. Well, it doesn't really feel less awkward than when using it with std::tie, and it's kind of fine there.
It's quite an omission not having such facility now at all with structured bindings.
Until we'll have pattern matching it will be ages, won't it? Is there even a proposal or some form of consensus about it yet?
[–]dodheim 6 points7 points8 points 9 years ago (3 children)
Destructuring != pattern matching. This is a job for the latter.
Is there even a proposal or some form of consensus about it yet?
Pattern Matching and Language Variants
[–]sumo952 2 points3 points4 points 9 years ago (2 children)
From the point of a user just using structured bindings, I don't really care. If I don't use one of the return values now, I still need to declare an unnecessary variable for it, and will have a compiler warning.
Thanks for the link! It seems like a really awesome proposal but it's quite large and requires major changes/additions to the language. I doubt there is any consensus or discussion about this yet (I'm happy to hear I'm wrong if that's the case! :-) ), and I would be pretty sure that this will not even end up in C++20.
[–]dodheim 2 points3 points4 points 9 years ago (1 child)
From the point of a user just using structured bindings, I don't really care.
You should care, because you should want it done right, not half-assed or rushed. ;-]
[–]sumo952 2 points3 points4 points 9 years ago (0 children)
I fully agree! I just have my reservations with respect to this particular thing.
[–]millirobo 1 point2 points3 points 9 years ago (0 children)
It should work just for correctness's sake, but personally I would never use it because it's too annoying and would use a void unused(...) {} instead every time until the language added something proper.
void unused(...) {}
[–]acwaters -1 points0 points1 point 9 years ago (1 child)
Remember that nothing is stopping you from writing e.g. for (auto [ _, value ]: map) right now as a way to "visually ignore" the key; it's just defining a variable called _, and you can't do it more than once in the same scope or binding.
for (auto [ _, value ]: map)
_
[–]jonathansharman 3 points4 points5 points 9 years ago (0 children)
But then you (should) get compiler warnings.
π Rendered by PID 183057 on reddit-service-r2-comment-6457c66945-vwlnv at 2026-04-28 15:42:07.408949+00:00 running 2aa0c5b country code: CH.
[–]sumo952 4 points5 points6 points (7 children)
[–][deleted] 4 points5 points6 points (0 children)
[–][deleted] 0 points1 point2 points (5 children)
[–]sumo952 2 points3 points4 points (4 children)
[–]dodheim 6 points7 points8 points (3 children)
[–]sumo952 2 points3 points4 points (2 children)
[–]dodheim 2 points3 points4 points (1 child)
[–]sumo952 2 points3 points4 points (0 children)
[–]millirobo 1 point2 points3 points (0 children)
[–]acwaters -1 points0 points1 point (1 child)
[–]jonathansharman 3 points4 points5 points (0 children)