c++マルチパラメータ

625 ワード

#include <iostream>
#include <vector>
#include "stdarg.h"
using namespace std;

template<class T>
vector<T>* funs(T a, ...)
{
	va_list params;
	va_start(params, a);
	T now;
	vector<T> *ve = new vector<T>;
	ve->push_back(a);
	while (a)
	{
		now = va_arg(params, T);
		if (now )
		{
			ve->push_back(now);
		} 
		else
		{
			ve->pop_back();
			break;
		}
	}
	va_end(params);
	return ve;
	
}

int main()
{
	vector<int> *ve = funs(1,2,3,4,5,6,7);
	for (auto const & child : *ve)
	{
		cout<<child<<endl;
	}
	return 0;
}