AFAIK, In non-templated functions, arguments can be implicitly converted rather than explicitly creating the parameter type:
auto foo(const std::vector<int>& input) {
// implementation here...
}
foo({ 1, 2, 3, 4, 5 }); // implicitly converted to a std::vector<int>
I'd like to apply this to variadic templates whose types are known. In my case I've enforced a homogeneous parameter pack so all types are the same:
using Range = std::pair<int, int>;
template <class ... Ranges,
class = std::enable_if_t<std::conjunction_v<std::is_same<Range, Ranges >...>>>
auto bar(Range&& range, Ranges&& ... ranges) {
// implementation here...
}
bar({ 1, 2 }, Range{ 3, 4 });
Unfortunately, if I try to call bar({1, 2}, {3, 4});
I will encounter a compile error indicating:
E0304: no instances of function template "bar" matches the argument list
I realize I can make an initializer list, but I'd like to make it work for variadic templates (homogeneous or heterogeneous).
How can I modify my function bar
so that arguments of the parameter pack Ranges
will implicitly convert to std::pair<int, int>
?