Pages

Thursday, September 26, 2013

C++ Variadic Templates

 I've been using Visual Studio 2013 RC which supports C++ 11 variadic templates.

 Here are a few things I've noticed.

Good
  • Compile time reduced. Replacing my N duplicates of a template with a single instance means less work for the compiler
  • Less code. Is some cases *way* less code. This is great! Can replace manually duplicated templates with 1 instance, can also replace Boost Preprocessor generated templates with variadics
Bad
  • If you step into a variadic function in the debugger it does not always allow you to see what values were passed into the function.  I did see it work once, so perhaps it is just buggy/incomplete and the final release for VS 2013 will fix this.
  • The following code does not compile, to work around it, as far as I can tell, you must resort to C++ 03 code(boilerplate). You couldn't instantiate this type because it doesn't map to a struct/class, but it would make it easier to pass type information around.  


edit: Looks like there is a proposal to fix my last point- N3728

No comments:

Post a Comment