What Is a Curly-Brace Enclosed List If Not an intializer_list?

前端 未结 4 1303
小蘑菇
小蘑菇 2020-12-01 17:54

I asked a question here: Lifetime Extension of a initializer_list return involving the non-functional code:

const auto foo = [](const auto& a, const auto         


        
4条回答
  •  执笔经年
    2020-12-01 18:37

    I just thought that any time you did a curly-braced list you were creating an intializer_list.

    That's not correct.

    If that's not what's happening, what is a list in curly-braces?

    struct Foo {int a; int b;};
    Foo f = {10, 20};
    

    The {10, 20} part is not an initializer_list. It's just a syntactic form to use a list of objects to create another object.

    int a[] = {10, 20, 30};
    

    Once again, it's a syntactic form to create an array.

    The name for the syntactic form is braced-init-list.

提交回复
热议问题