C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Generalized "default" constructor

From: Gergely Nagy <gergely.nagy.alt_at_[hidden]>
Date: Tue, 14 Feb 2023 23:43:33 +0100
Hey, thanks, this was a little dumb overlook on my end :)

Ville Voutilainen <ville.voutilainen_at_[hidden]> ezt írta (időpont: 2023.
febr. 14., K, 23:19):

> On Wed, 15 Feb 2023 at 00:12, Gergely Nagy via Std-Proposals
> <std-proposals_at_[hidden]> wrote:
> >
> > Hey,
> >
> > Been wondering. To use emplace_back or emplace, or try_emplace, one
> needs a constructor obviously that can be called. Now if I have a trivial
> struct, like
> >
> > struct Trivial {
> > int x;
> > double y;
> > std::string z;
> > };
> >
> > I have to write my own constructor to be able to use *emplace*, even
> though it is kinda trivial, what I mean when I write:
> >
> > std::vector<Trivial> t;
> > t.emplace_back(1, 2.0, "blah");
>
> That code just works from C++20 onwards, since C++20 allows
> initializing aggregates with the parenthesized syntax,
> courtesy of Thomas Köppe and yours truly.
>

Received on 2023-02-14 22:43:46