C++ Logo


Advanced search

[std-proposals] Self-move-assignment and iterator preservation

From: Emile Cormier <emile.cormier.jr_at_[hidden]>
Date: Sun, 15 Jan 2023 17:51:50 -0400
I'm writing a custom container that I wish to make as standards-compliant
as practical. I was considering whether to make it so that my container's
move-assign operator does not invalidate iterators. I stumbled upon LWG
Issue 2321 (https://cplusplus.github.io/LWG/issue2321) which proposes that
containers preserve iterators after move-assign whenever possible.

I am in favor of LWG 2321, but it does not cover the self-move-assignment
use case. LWG 2849 (https://cplusplus.github.io/LWG/issue2839) proposes
that "such an [self-move] assignment places the object in a valid but
unspecified state unless otherwise specified."

LWG 2321 and LWG 2849 are currently in contradiction, I believe.

For my custom container, I'm opting for self-move-assignment to be a no-op
so that it can satisfy both LWG 2321 and LWG 2849. My container uses
std::map under the hood, so I can't count on it preserving its state after
a self-move-assign.

I'm not interested in learning the bureaucracy involved in writing my own
standard library defect report, so I'm raising the contradiction here for
discussion and follow-up. I've also BCCed the authors of the two LWG issues
I cited.

Due its very high volume, I opted not to receive notifications from this
mailing lists, so please CC me in your replies.

Emile Cormier

Received on 2023-01-15 21:52:02