Re: Why std::vector requires noexcept move constructor?

Liste des GroupesRevenir à cl c++ 
Sujet : Re: Why std::vector requires noexcept move constructor?
De : eesnimi (at) *nospam* osa.pri.ee (Paavo Helde)
Groupes : comp.lang.c++
Date : 16. Jun 2025, 18:00:17
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <102pij2$1op2f$1@dont-email.me>
References : 1
User-Agent : Mozilla Thunderbird
On 15.06.2025 11:25, Marcel Mueller wrote:
I discovered shortly that a move constructor that is not declared as noexcept is ignored by std::vector. Instead the objects are moved by the copy constructor.
A move constructor is a way to squeeze out max performance from the code. Noexcept also helps in this regard and is usually trivial to add to move operations.

 Why?
The copy constructor is even more likely not declared as noexcept.
 
Depending on the operation, it might be needed to restore the original state of existing data if an exception appears middle-way. With move this might become cumbersome or even impossible if there appears another exception during restore. Declaring the move operations noexcept gets rid of such problems.
With copy constructors the original state is not touched at all so recovering from an exception is much simpler.

Date Sujet#  Auteur
15 Jun 25 * Why std::vector requires noexcept move constructor?5Marcel Mueller
16 Jun 25 +* Re: Why std::vector requires noexcept move constructor?3Paavo Helde
16 Jun 25 i`* Re: Why std::vector requires noexcept move constructor?2Marcel Mueller
17 Jun 25 i `- Re: Why std::vector requires noexcept move constructor?1Paavo Helde
1 Jul18:13 `- Re: Why std::vector requires noexcept move constructor?1Bonita Montero

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal