For constructors, how do I choose between variadic-templates vs std::initializer_list?

后端 未结 3 1187
南笙
南笙 2021-02-14 01:13

In the current state of c++11 (say gcc 4.7.2), how should I choose between using a variadic-template or a std::initializer_list when I need a constructor t

3条回答
  •  佛祖请我去吃肉
    2021-02-14 01:48

    With a variadic template, the number of arguments is known during compilation (and accessible via sizeof...). With a std::initializer_list, the number of arguments is known only at runtime. So part of the decision depends on when you need or want to know how many arguments you have.

提交回复
热议问题