If the T
values as known at compile-time, you can pass they as template parameters and write something like
template<typename T, T ... Is>
void foo() {
std::vector<T> x { { Is.. } };
for( auto xx:x )
std::cout << xx << std::endl;
}
that is called
foo<int, 2, 3, 5, 7>();
Otherwise you have to pass they as arguments; something like
template <typename T, typename ... ARGS>
void foo (ARGS const & ... args) {
std::vector<T> x { { args... } };
for( auto xx:x )
std::cout << xx << std::endl;
}
that is called
foo<int>(2, 3, 5, 7);
or also (deducing the type T
from the first argument)
template <typename T, typename ... ARGS>
void foo (T const & arg0, ARGS const & ... args) {
std::vector<T> x { { arg0, args... } };
for( auto xx:x )
std::cout << xx << std::endl;
}
that is called
foo(2, 3, 5, 7);
-- EDIT --
The OP write
It should work like this
foo<int>(1,2,3,4) returns std::vector<int> x{1,2,3,4}
foo<double>(0.1,0.2,0.3) returns std::vector<double> x{0.1,0.2,0.3}
So I suppose you can simply write
template <typename T, typename ... ARGS>
std::vector<T> foo (ARGS const & ... args)
{ return { args... }; }