CppCoreGuidelines icon indicating copy to clipboard operation
CppCoreGuidelines copied to clipboard

General Question about Suggestions for C++

Open CodePagesNet opened this issue 2 years ago • 2 comments

Hi,

I occasionally have suggestions for C++. I don't necessarily seek to be an official ISO CPP member etc. However, sometimes I have ideas and suggestions for C++ that I would like to at least email to someone on the committee or who has contact with the committee (conceptually like a C++ congressional representative :-) ).

I don't know where to provide these suggestions, so would someone be willing to allow me to email them a suggestion occasionally or point me in the right direction? (I will be very careful to pre-filter my suggestions and only send an email if I truly think that I have a worthwhile contribution. I am busy and I know others are busy.)

My current idea is a ctor-like re-init/re-use language feature that supports re-use of objects without any memory operations (new/delete). An analogy that I use is the reset() function of unique_ptr. However, my suggestion goes beyond that such that this re-use capability is a ctor-like once-and-done action that is not available as a normal function - just as the ctor is not available as a normal function once the instance has been created.

Sincerely and Thank You, Greg McPherran

CodePagesNet avatar Aug 14 '22 03:08 CodePagesNet

See https://isocpp.org/std/forums

But IMHO that idea won't go anywhere.

jwakely avatar Aug 14 '22 06:08 jwakely

I did request the feature on the iso proposals list. Thank you.

In summary, the three requested/proposed features are:

  • Ctor-like re-init once-and-done special functions that are not available as normal functions after init just as the ctor is not available as a normal function on an object. The re-init allows use of instance memory for new instance without any memory free and re-allocation.

  • const after first init This related feature would be very helpful for objects that are conceptually intended to be global constants, but one would like the chance to initialize them once (and only once) at runtime (typically in early startup time). So, they are automatically const after they are initialized the first time.

  • Object pool for class instances. E.g., class pool SomeClass {... A compiler option with pool capacity to pool all objects is also an idea.

Potential syntax for re-init ctor: some_object_instance::(..., ctor_args, ...) The args and overloads would be the same as for the ctor.

CodePagesNet avatar Aug 14 '22 21:08 CodePagesNet