←back to thread

178 points todsacerdoti | 1 comments | | HN request time: 0.216s | source
Show context
MauranKilom ◴[] No.26341332[source]
Random emplace_back hate: I really dislike how you can't use it for objects that you'd normally use aggregate initialization for.

See https://godbolt.org/z/6qW7q3

    struct SimpleData
    {
        int a;
        double b;
    };

    SimpleData someData = {1, 2.0}; // ok

    std::vector<SimpleData> data;

    // Why can I not do this?
    data.emplace_back(1, 2.0);
replies(3): >>26341692 #>>26344690 #>>26347384 #
1. vinkelhake ◴[] No.26344690[source]
You can as of C++20 - aggregate initialization has been extended to support T(x, y) syntax.

See https://godbolt.org/z/Tj5baM and https://en.cppreference.com/w/cpp/language/aggregate_initial... (case 5).