C++ Logo

std-proposals

Advanced search

Make lifetime a part of the object model

From: Omer Rosler <omer.rosler_at_[hidden]>
Date: Tue, 30 Jul 2019 00:43:39 +0300
Hi,

I want your feedback about the merit of what I want to propose.
If the feedback will be positive, I will split these into separate papers
regarding every point below.

Will the committee be open to such a change?

The TL;DR is as follows:

   - Bake an ownership model into the language as an opt-in mechanism
   using the (placeholder) keyword `*unique*`
      - This allows us *language level RAII*
      - This model adds *zero-runtime overhead* (no extra pointers are
      needed anywhere)
*. *
      - This turns many *dangling* references/pointer bugs into *compile
      errors*
      - Add `*restrict*` keyword to handle objects we don't own (it is
   mostly backward compatible with C)
   - Make copy/move elision mandatory in more cases (*guaranteed NRVO* and
   Ultimate Copy Elision) by withhold conversion of owner objects into viewer
   objects.
   - Make copy/move elision allowed in more cases.
   - Turn `unique` into a full blown *cv-qualifer* which allows the
   following features:


   1. *Destructive moves* (move constructors taking a `unique T&&`).
   2. *Lazy evaluation* by overloading operations on `unique`
   3. *Smart references* by providing a conversion operator on a `unique`
   this pointer into a different type which is not `unique` (this requires
   several changes to overload resolution as well).


   - *Integrate *these new keywords *implicitly *in certain places that
   need to be discussed (just like the integration of move semantics into
   existing C++ 03 code).

Attached a very rough draft of the functionality proposed:
https://github.com/OmerRosler/uvalues/tree/v0.1.0

Thank you,
Omer Rosler

Received on 2019-07-29 16:45:49