Take the 2-minute tour ×

I'm trying to create a constructor that takes a variable number of arguments and I would very much like to keep things type-safe. I googled around and kept finding the term "Faux variadics" (Example: http://msdn.microsoft.com/en-us/library/hh567368.aspx) However I'm not able to find any examples of how to use these Faux variadics, and I'd like to avoid having to look directly in the source file for std::tuple.

So does anyone know of a relatively simple example of these Faux variadics?

share|improve this question
A relatively simple example? Not possible. <g> This is nasty stuff. –  Pete Becker Oct 8 '12 at 16:53
I suggest if that's an option to use a different compiler if you need variadic templates, microsoft is incredibly slow in adopting c++11 features. I recently wrote a small-to-medium sized c++11 application which compiled fine in gcc but when trying to use visual studio 2012 it took me almost 3 days to find different ways of writing all kind of stuff which VS2012 didn't know about. A relatively simple example using the actual variadic templates can be found here generic-programming.org/~dgregor/cpp/variadic-templates.html - a type-safe printf, don't know how that maps to MS's vision. –  xception Oct 8 '12 at 16:54
Visual Studio 2012 added patched in variadics: microsoft.com/en-us/download/details.aspx?id=35515 –  Mooing Duck Nov 26 '12 at 18:34
add comment

2 Answers

up vote 4 down vote accepted

You can use the boost preprocessor library to do this:

A simple sample using BOOST_PP_REPEAT:

#include <boost/preprocessor/repetition.hpp>
#include <boost/preprocessor/arithmetic/sub.hpp>
#include <boost/preprocessor/punctuation/comma_if.hpp>

#define TINY_print(z, n, data) data

#define TINY_size(z, n, unused)                                 \
  template <BOOST_PP_ENUM_PARAMS(n, class T)>                   \
  struct tiny_size<                                             \
      BOOST_PP_ENUM_PARAMS(n,T)                                 \
      BOOST_PP_COMMA_IF(n)                                      \
      BOOST_PP_ENUM(                                            \
          BOOST_PP_SUB(TINY_MAX_SIZE,n), TINY_print, none)      \
  >                                                             \
    : mpl::int_<n> {};


#undef TINY_size
#undef TINY_print
share|improve this answer
Link to official docs: boost.org/libs/preprocessor –  ildjarn Oct 9 '12 at 18:15
add comment

Now you can also use the November CTP and try their variadic template implementation.

share|improve this answer
add comment

Your Answer


