tisdag 4 juni 2013

A way to use C++11 variadic template functions

  
namespace Log {
    inline void write() {
      std::cout << std::endl;
    }

    template<typename T, typename ...U>
    inline void write(T head, U... tail){
      std::cout << head;
      Log::write(tail...);
    }
  }
Overload an empty write() to end recursion. Then you can use it like this:

Log::write("test", 10.0f, 'd'); 

Log::write(1,2,3,4,5,6,7);

Inga kommentarer: