fork download
  1. #include <cstdio>
  2. #include <string>
  3.  
  4. template< typename T >
  5. T const &printf_helper( T const &x )
  6. { return x; }
  7.  
  8. char const *printf_helper( std::string const &x )
  9. { return x.c_str(); }
  10.  
  11. template< typename ... Req, typename ... Given >
  12. int wrap_printf( int (*fn)( Req ...... ), Given ... args ) {
  13. return fn( printf_helper( args ) ... );
  14. }
  15.  
  16. int main() {
  17. wrap_printf( std::printf, "Hello %s\n", std::string( "world!" ) );
  18. wrap_printf( std::fprintf, stderr, std::string( "Error %d" ), 5 );
  19. }
Success #stdin #stdout 0s 3016KB
stdin
Standard input is empty
stdout
Hello world!