How do I create a set from arguments of variadic templated function?
template<class T>
concept Int = std::same_as<T, int>;
template<Int... Ints>
std::set<int> fun (Ints... ints)
{
// create and return a set containing arguments to this function
}
CodePudding user response:
You can expand the pack using pack expansion as shown below:
template<Int... Ints>
std::set<int> fun (Ints... ints)
{
return {ints...}; //use unary right fold
}
int main()
{
std::set<int> myset = fun(1,2,3);
}