Why use variadic arguments now when initializer lists are available?

前端 未结 2 1140
轻奢々
轻奢々 2020-12-07 23:04

I\'ve been wondering what are the advantages of variadic arguments over initializer lists. Both offer the same ability - to pass indefinite number of arguments to a function

2条回答
  •  一个人的身影
    2020-12-07 23:13

    Briefly, C-style variadic functions produce less code when compiled than C++-style variadic templates, so if you're concerned about binary size or instruction cache pressure, you should consider implementing your functionality with varargs instead of as a template.

    However, variadic templates are significantly safer and produce far more usable error messages, so you'll often want to wrap your out-of-line variadic function with an inline variadic template, and have users call the template.

提交回复
热议问题