C++ Logo

std-proposals

Advanced search

Re: [std-proposals] c++ proposal

From: Rune Lund Olesen <rune.olesen_at_[hidden]>
Date: Wed, 1 Jul 2026 11:01:58 +0200
Afaik, you can create this behavior yourself with most types of factories
for the init part.
If you concerned with users not using the factory, one way around that is
with the "private token pattern".

eg. :

template<class T, class... Args>
T create_widget( Args&&... args ) {
  T obj(private_token, std::forward<Args>(args)...);
  obj.init();
  return obj;
}

The language is flexible enough to accommodate this already and design-wise
it is feels more like this is already starting to be a mess when this two
phase construction/destruction comes up as a need....

It is hard enough teach these things already and this will just make it
more complicated i reckon and also to reason about code in general. Keep it
simple.

Have a lovely day

On Wed, Jul 1, 2026 at 10:22 AM Sebastian Wittmeier via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> Then why not call the respective f() functions from the constructors?
>
>
> -----Ursprüngliche Nachricht-----
> *Von:* Rainer Deyke via Std-Proposals <std-proposals_at_[hidden]>
> *Gesendet:* Mi 01.07.2026 08:26
> *Betreff:* Re: [std-proposals] c++ proposal
> *An:* std-proposals_at_[hidden];
> *CC:* Rainer Deyke <rainerd_at_[hidden]>;
>
>
> On 7/1/26 08:12, Sebastian Wittmeier via Std-Proposals wrote:
> > Making f() virtual is a bit confusing:
> >
> >
> > During construction only the base member function is called. So it could
> be non-virtual as well?
>
> Making f() virtual is the whole point of the example. When called from
> base::base, base::init calls base::f. When called from
> derived1::dervived1, base::init calls derived1::f. When called from
> derived2::dervived2, base::init calls derived2::f.
>
>
> --
> Rainer Deyke - rainerd_at_[hidden]
>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>

Received on 2026-07-01 09:02:15