Quick Q: Is there a case where ellipsis(vararg) should be preffered over variadic templates?

Quick A: There are several special cases where you may want that, but in general no.

Recently on SO:

Is there a case where ellipsis(vararg) should be preffered over variadic templates?

  1. If you provide a C API with C++ implementation, then templates are not an option for the API. Varargs are.
  2. If you need to support a compiler that doesn't support C++11 or newer standard, then variadic templates are not available. Varargs are.
  3. If you need a compilation firewall. I.e. you need to hide the implementation of the function from the header, then variadic template is not an option. Varargs are.
  4. On memory constrained systems (embedded), the different functions generated by the template may introduce too much bloat. That said, such systems are typically also real time, in which case varargs might also unacceptable due to branching and stack usage.

Add a Comment

Comments are closed.

Comments (0)

There are currently no comments on this entry.