C++ Logo


Advanced search

Re: [std-proposals] Re-Init Example Use Case

From: Greg McPherran <GMcPherran_at_[hidden]>
Date: Mon, 15 Aug 2022 02:06:36 +0000
Text editor implemented as a vector of strings. Each string in vector is
a line of text.

vector implementation internally leverages re-init by cache'ing the
string objects for removed lines of text. When new lines of text are
created e.g. by emplacement, the vector can determine whether to
construct a new string or re-init an existing string object based on
availability of what is in the cache.

Currently, this would be handled by std::construct_at(...) using an
instance rvalue. This is fine for raw empty memory, but for existing
instances in the vector purposefully made available for re-use, the
"emplace using re-init feature syntax" is simpler and more concise, and
incorporates recognition of this pattern into the language. What is
std::xyz today may be a prototype for tomorrow's language syntax and I
propose that the re-init ctor is an example.

I also maintain that unique_ptr::reset() is a perfectly valid example of
usefulness of re-init concept.

Anyway, I've stated my case. And with regards to "tossing" ideas, as I
mentioned, if a language designer would like me to further collaborate,
I am willing and I already offer the some_object_instance::(ctor_args)
syntax suggestion.

Have Great Night All,
Greg McPherran

Received on 2022-08-15 02:06:40