- std::shrink_to_fit(), which makes a non-binding request that a container reduce its capacity to match its size.
--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
---
You received this message because you are subscribed to the Google Groups "Chromium-dev" group.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/CAAHOzFBPmS6Drun0dg5sy1Vw7W35rLc%2BF-oO32FZsPO0rGh7_Q%40mail.gmail.com.
You received this message because you are subscribed to the Google Groups "cxx" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cxx+uns...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/710aeb1c-90ad-466c-9d9f-2cbb29966a7a%40chromium.org.
This understanding is not quite correct. std::vector commonly uses std::move_if_noexcept during its resize operation, which is a copy if the value (!is_nothrow_move_constructible && is_copy_constructible), and a move otherwise.
In particular this means the move constructor of both copyable and moveable should be marked noexcept, as otherwise vector will copy.
On Mon, Mar 9, 2020 at 8:58 AM Jan Wilken Dörrie <jdoe...@chromium.org> wrote:This understanding is not quite correct. std::vector commonly uses std::move_if_noexcept during its resize operation, which is a copy if the value (!is_nothrow_move_constructible && is_copy_constructible), and a move otherwise.I was asking about move-only types, where falling back to a copy isn't an option. Does this not mean that a move-only type can only be stuffed into a vector if it can be moved (via move assign or move construct) without an exception being thrown? Or does vector have some other path where it'll do the move and let exceptions fly?
In particular this means the move constructor of both copyable and moveable should be marked noexcept, as otherwise vector will copy.This is where the style guide makes things muddy: "You may use noexcept when it is useful for performance if it accurately reflects the intended semantics of your function". Where do we draw the line? Some (not me) might say "don't use noexcept unless you can demonstrate a performance hit by not using it."But wait! I just noticed that the style guide follows that with "You can assume that noexcept on move constructors has a meaningful performance benefit." I read that as "always put noexcept on move ctors as long as it's actually correct." Should we not be doing this? If no, why not?
Note that your final paragraph has circled around to the original cause of this thread: a mass rewrite to do this everywhere and a debate over wherever we should be doing it. Nico makes the case for "why not". My position is still that we should do this everywhere.PK
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CAKQnr0QY0KBgbn5%2BCZ8GQZYMeKD0MKPxGem8mH6cM47FPtSpsQ%40mail.gmail.com.
Due to the lack of exceptions in Chromium, I agree that there's no practical effect (I believe the compiler will do the right thing when exceptions are turned off), so this seems purely a matter of consistency. On that basis, it seems like a good practice to adopt, but it's not urgent or anything.
I threw together a Compiler Explorer link if anyone wants to play around with this: https://godbolt.org/z/IBvZTnAt least for my example, and with x86-64 clang-trunk, noexcept makes a difference with exceptions (as you'd expect), and makes no difference with -fno-exceptions (also as you'd expect, hopefully).I poked around a bit with the gcc vs. clang behavior, but wasn't able to trigger the compilation error; I'm assuming I didn't hit the right set of conditions to trigger it.