←back to thread

178 points todsacerdoti | 1 comments | | HN request time: 0.431s | 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. gpderetta ◴[] No.26347384[source]
That's because of the epic fail that are initializer lists that prevent aggregate initialization (which is otherwise awesome) to be used safely in generic contextes.