Advertisement
spacechase0

Fancy Log

Feb 20th, 2012
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. void Log( const std::string& str )
  2. {
  3.     std::cout << str;
  4. }
  5.  
  6. // http://en.wikipedia.org/wiki/Variadic_templates
  7. template< typename T, typename... Args >
  8. void Log( const std::string& str, T value, Args... args )
  9. {
  10.     for ( auto it = str.begin(); it != str.end(); ++it )
  11.     {
  12.         size_t dist = std::distance( str.begin(), it );
  13.        
  14.         char cc = ( * it );
  15.         if ( dist >= str.size() - 1 )
  16.         {
  17.             std::cout << cc;
  18.             break;
  19.         }
  20.        
  21.         char nc = ( * ( it + 1 ) );
  22.         if ( cc == '%' and nc != '%' )
  23.         {
  24.             std::cout << value;
  25.             Log( str.substr( dist + 2 ), args... );
  26.             return;
  27.         }
  28.        
  29.         std::cout << cc;
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement