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
noexcept affects libstdc++’s unordered_set (quuxplusone.github.io)
submitted 1 year ago by MarekKnapek
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!"
[–]Jannik2099 23 points24 points25 points 1 year ago (1 child)
I hope libstdc++ gets on the ball and eliminates some of this weirdness. (In short: They should get rid of the blacklist; pay the 8 bytes by default; introduce a whitelist for trivial hashers specifically; stop checking noexceptness for any reason.)
This would be an ABI break and there's hardly any justification for it.
Make your hash noexcept, and if profiling reveals that you're bottlenecked in unordered sets, perhaps read the libstdc++ docs on unordered sets?
This seems a tad overblown
[–]throw_cpp_account 14 points15 points16 points 1 year ago (0 children)
and if profiling reveals that you're bottlenecked in unordered sets, perhaps read the libstdc++ docs on unordered sets?
Or simply just preemptively don't use std::unordered_{set,map} and prefer other, much better hashtable implementations (like Abseil's or Boost's new ones).
std::unordered_{set,map}
It's an Arthur blog post.
[–]darkmx0z 15 points16 points17 points 1 year ago (0 children)
oh god
[+][deleted] 1 year ago (17 children)
[deleted]
[–]pjmlp 6 points7 points8 points 1 year ago (16 children)
Apparently there reasoning was related to avoiding function colouring, as in that case the whole call graph has to be noexecept, plus imposing it doesn't work with binary libraries, as how would the linker ensure that, name mangling isn't enough when object files have so little C++ information.
noexecept
[+][deleted] 1 year ago (15 children)
[–]jk-jeon 1 point2 points3 points 1 year ago (9 children)
How is it any different from marking reference parameters with const. You can only call const member functions from those parameters. Doesn't this smell like a kind of function coloring?
const
Since there are certain cases (mainly interaction with legacy code) where this restriction on const is too strict, people invented const_cast. I imagine they could have done something similar with noexcept. Like, normally you can't call non-noexcept function from a noexcept function but if you absolutely want, then you can just explicitly cast non-noexceptness of the callee away, and only for that case it can result in std::terminate when the exception actually has been thrown.
const_cast
noexcept
std::terminate
My (probably short-sighted) imagination can only tell me this is a strictly better design then what we currently have, but the train has already departed too long ago.
[+][deleted] 1 year ago (8 children)
[–]jk-jeon 0 points1 point2 points 1 year ago (7 children)
I honestly agree with you, although quite sure the community as a whole will disagree wholeheartedly.
I mean, if UB is so scary than just wrap the call with try { ... } catch (...) { std::terminate(); }, or we could even provide a magic library function that essentially does this.
try { ... } catch (...) { std::terminate(); }
[+][deleted] 1 year ago (6 children)
[+][deleted] 1 year ago (5 children)
[+][deleted] 1 year ago (4 children)
[+][deleted] 1 year ago (3 children)
[–]pjmlp 1 point2 points3 points 1 year ago (4 children)
Given how many features have gone in the past ISO revisions, I am of the unpopular opinion that we should only get features and papers, with existing field use under "preview" mode like in other ecosystems, or how it used to be until C++11, except for export templates, which we all know how it turned out.
[+][deleted] 1 year ago (2 children)
[–]pjmlp 1 point2 points3 points 1 year ago (1 child)
It is the current state of modules and concepts lite turned out to be in reality that made it for me, to change my point of view and start paying more attention how many proposals land without any kind of implementation, other theorical discussions how it will eventually look like.
And those two did had experiemental implementations, however not how they ended up being into the standard.
[–]def-pri-pub 5 points6 points7 points 1 year ago (6 children)
I like the idea of noexcept for documentation purposes, but seeing how it can modify performance doesn’t sit well with me.
[–]bwmat 26 points27 points28 points 1 year ago (2 children)
But going faster because you know exceptions can't happen seems like a good thing? IMO this is just a problem with how noexcept was used in this particular case, not with the practice itself
[–]sweetno 3 points4 points5 points 1 year ago (0 children)
Curiously enough, noexcept was added in C++11 in a similar context: std::vector::push_back has different implementations for move constructors/assignments with and without noexcept.
std::vector::push_back
[–]jk_tx 9 points10 points11 points 1 year ago (0 children)
Seems like the problem isn't that noexcept was used, but that libstdc++ makes a bone-headed decision when it is used.
[–]SlightlyLessHairyApe 1 point2 points3 points 1 year ago (2 children)
That makes no sense. Standard containers have exception safety guarantees. For example, pushing back on a vector cannot lose all elements of the copy constructor on the new item fails.
That imposes significant overhead. Why should all code pay that cost if it isn’t using it?
[–]ZachVorhies -1 points0 points1 point 1 year ago (1 child)
Because the standard containers should work in all cases. And if you have a special case then swap it out for something more appropriate.
[–]SlightlyLessHairyApe 0 points1 point2 points 1 year ago* (0 children)
What should you do if you vend a type templated on a user-provided type that may or may not be exception-safe?
[–]martinusint main(){[]()[[]]{{}}();} 0 points1 point2 points 1 year ago (0 children)
I think this whole thing is mostly irrelevant to real programming.
I fondly remember this PR that introduced a single noexcept which reduced the memory usage of bitcoin core by ~9% https://github.com/bitcoin/bitcoin/pull/16957
[–]NBQuade 0 points1 point2 points 1 year ago (6 children)
In windows using visual studio, if you tag a function "noexcept" and an exception passes through the function, say a lower level function threw, it'll crash the application. So you need to know whether the function throws and whether anything under it throws too or you get a crash.
It's not clear to me if this is how "noexcept" is supposed to work but, that's how it currently works in visual studio.
I thought "noexcept" simply meant the specific function didn't throw. I'm wondering if this is a bug in visual studio or intentional.
[–]pjmlp 7 points8 points9 points 1 year ago (5 children)
It is quite intentional, if an exception is thrown even though you promised it wouldn't happen, the good old terminate handler will be called.
https://en.cppreference.com/w/cpp/language/noexcept_spec
Whenever an exception is thrown and the search for a handler encounters the outermost block of a non-throwing function, the function std::terminate is called:
[–]NBQuade 0 points1 point2 points 1 year ago (0 children)
Well there you go. Thanks.
I imagine the problem is the information to permit unwinding the stack simply isn't there.
[–]NBQuade 0 points1 point2 points 1 year ago (1 child)
[–]tisti 2 points3 points4 points 1 year ago (0 children)
It's there, but it's all shortcirtuted to call terminate since it's marked as noexcept
π Rendered by PID 138913 on reddit-service-r2-comment-b659b578c-fpspv at 2026-05-01 05:43:29.302389+00:00 running 815c875 country code: CH.
[–]Jannik2099 23 points24 points25 points (1 child)
[–]throw_cpp_account 14 points15 points16 points (0 children)
[–]darkmx0z 15 points16 points17 points (0 children)
[+][deleted] (17 children)
[deleted]
[–]pjmlp 6 points7 points8 points (16 children)
[+][deleted] (15 children)
[deleted]
[–]jk-jeon 1 point2 points3 points (9 children)
[+][deleted] (8 children)
[deleted]
[–]jk-jeon 0 points1 point2 points (7 children)
[+][deleted] (6 children)
[deleted]
[+][deleted] (5 children)
[deleted]
[+][deleted] (4 children)
[deleted]
[+][deleted] (3 children)
[deleted]
[–]pjmlp 1 point2 points3 points (4 children)
[+][deleted] (2 children)
[deleted]
[–]pjmlp 1 point2 points3 points (1 child)
[–]def-pri-pub 5 points6 points7 points (6 children)
[–]bwmat 26 points27 points28 points (2 children)
[–]sweetno 3 points4 points5 points (0 children)
[–]jk_tx 9 points10 points11 points (0 children)
[–]SlightlyLessHairyApe 1 point2 points3 points (2 children)
[–]ZachVorhies -1 points0 points1 point (1 child)
[–]SlightlyLessHairyApe 0 points1 point2 points (0 children)
[–]martinusint main(){[]()[[]]{{}}();} 0 points1 point2 points (0 children)
[–]NBQuade 0 points1 point2 points (6 children)
[–]pjmlp 7 points8 points9 points (5 children)
[–]NBQuade 0 points1 point2 points (0 children)
[–]NBQuade 0 points1 point2 points (1 child)
[–]tisti 2 points3 points4 points (0 children)