C++ Logo

std-proposals

Advanced search

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

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Wed, 15 Feb 2023 00:35:14 +0000
On Tue, Feb 14, 2023 at 10:12 PM Gergely Nagy via Std-Proposals
<std-proposals_at_[hidden]> wrote:
>
> std::vector<Trivial> t;
> t.emplace_back(1, 2.0, "blah");


I always used to use compound literals for this purpose:

     t.emplace_back( (Trivial){1,2.0,"blah"} );

Strictly speaking I think these compound literals are only a feature
of C, but every C++ compiler supports them.

Ville posted "C++20 allows initializing aggregates with the
parenthesized syntax", so does that mean we pretty much have compound
literals in C++ except that we use the following syntax?

    Trivial(1,2.0,"blah")

Received on 2023-02-15 00:35:25