#include <iostream>
using namespace std;
template<typename U, typename ... T>
void run(T... a){
((cout << a << ' '), ...);
}
int main(){
// run(1,2,32,4);
run<int>(1,3, 42.0, "haha");
}
Showing posts with label cpp11_tmp_variadic. Show all posts
Showing posts with label cpp11_tmp_variadic. Show all posts
Aug 30, 2018
[C++] fold expression for inserting space between value for print out.
trick:
, as binary operator
Feb 8, 2015
[C++11] variadic parameter deduse
#include <iostream>
using namespace std;
template<typename, typename>
struct FunType
{
void fun()
{
cout << "fun" << endl;
}
};
template<typename ...T, template<typename...> class ITYPE>
void usage(ITYPE<T...>& in, T... t) // type deduce is evaluated with order left -> right
{
in.fun();
}
int main()
{
FunType<int,double> f;
usage(f,1,2.0);
}
Subscribe to:
Posts (Atom)