1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
#include <iostream>
template< typename F, typename ...T > void call( F&& f, T&&... t) {
std::forward<F>(f)( std::forward<T>(t)... );
}
int main() {
call( [] { std::cout << "nullary closure()\n" ; } ) ; // fine: empty argument pack
// call( [](){ std::cout << "nullary closure()\n" ; }, 100 ) ; // *** error: too many arguments
call( [] (int) { std::cout << "unary closure(int)\n" ; }, 100 ) ; // fine: argument pack of size one
// call( [] (int) { std::cout << "unary closure(int)\n" ; } ) ; // *** error: too few arguments
// call( [] (int) { std::cout << "unary closure(int)\n" ; }, 100, 200 ) ; // *** error: too many arguments
call( [] (int,int) { std::cout << "binary closure(int,int)\n" ; }, 100, 200 ) ; // fine: argument pack of size two
// call( [] (int,int) { std::cout << "binary closure(int,int)\n" ; }, 100 ) ; // *** error: too few arguments
// call( [] (int,int) { std::cout << "binary closure(int,int)\n" ; }, 100, 200, 300 ) ; // *** error: too many arguments
}
|