Consider the following example.
static constexpr std::array<bool, 2> Default{true, false};
template <size_t n>
void process(const std::array<bool, n>& values = Default) {
// do some work...
}
template <size_t n = Default.size()>
void process2(const std::array<bool, n>& values = Default) {
// do some work...
}
void test() {
process(); // error: cannot infer n
process(Default); // works fine
process2(); // works fine
}
The call to process()
fails because it cannot infer n
, even though it should in theory be able to. To get this to work, I have to specify the default in 2 places, as in process2
, which seems inelegant and prone to error.
Is this the expected behavior? If so, is it possible that support for this could be added to the language?