Consider a constructor accepting a parameter pack, such as
template<typename First, typename... Rest>
consteval explicit foo(const First& first, const Rest... rest)
: arrayMember{first, rest...}
{
}
where First and Rest... all have arithmetic types,
And another, different constructor that takes two arithmetic types:
explicit foo(std::size_t low, std::size_t high) { /* ... */ }
Imagine now that we wish to call the second constructor taking the two arithmetic types parameters:
foo f(3,4);
... But this actually calls the constructor that takes a parameter pack.
I am wondering whether there is a way to disambiguate the calls.
For example, is there a way (through preprocessor magics or something) to call the parameter pack constructor with brace initialization ({ ... }
), and to call the other constructor with direct initialization ((..., ...)
)?
I have thought of disabling the parameter pack constructor if the passed arguments are 2, but what if I actually wanted to call it with two parameters?
Minimal reproducible example: https://godbolt.org/z/5P9cEdf7v