1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
#include <iostream>
namespace cpp17 // requires c++17: uses fold expression (binary left fold)
{
template < typename... ARGS >
std::ostream& print( ARGS&&... args ) { return ( std::cout << ... << args ) ; }
}
namespace cpp11
{
std::ostream& print() { return std::cout ; }
template < typename FIRST, typename... REST >
std::ostream& print( FIRST&& first, REST&&... rest )
{
std::cout << first ;
return print(rest...) ;
}
}
int main()
{
{
using cpp17::print ;
print() ;
print( 1234567898765 ) ;
print( '\t', 1, ' ', 23.4, " hello ", 78.567, '\n' ) ;
}
{
using cpp11::print ;
print() ;
print( 1234567898765 ) ;
print( '\t', 1, ' ', 23.4, " hello ", 78.567, '\n' ) ;
}
}
|