::std::initializer_list vs variadic templates

前端 未结 3 1817
傲寒
傲寒 2021-01-13 03:38

Does passing multiple arguments via ::std::initializer_list offer any advantages over the variadic function template method?

In code:

te         


        
3条回答
  •  佛祖请我去吃肉
    2021-01-13 04:25

    You can iterate over an std::initializer_list in a way that you cannot over a parameter pack (unless you have C++17 and you fold it first). So for example you can have for loops with the lists. With parameter packs, you only option to expand them is via recursive specialised definitions.

提交回复
热议问题