returning initializer list mechanism

后端 未结 2 617

What mechanism is involved, if when returning types, that are constructible from initializer lists, I don\'t specify the type I am returning, as in:

std::arr         


        
相关标签:
2条回答
  • 2021-01-01 22:57

    There are no performance penalties involved. The return value is constructed equivalent to

    std::array<int, 3> x = { 1, 2, 3 };
    

    There is not even a single copy or move of an std::array instance involved.

    0 讨论(0)
  • 2021-01-01 23:02

    The mechanism is just a constructor:

    struct X {};
    
    struct Y {
        Y(X);
    };
    
    Y f() {
        X x;
        return x;
    }
    
    0 讨论(0)
提交回复
热议问题