Can template deduction guides call constexpr functions?

You can do:

template <class T, class... U>
array(T, U...) -> array<T, 1 + sizeof...(U)>;

The problem is not that you cannot call constexpr functions in deduction guides. You can. This example is ridiculous, but works:

constexpr size_t plus_one(size_t i) { return i + 1; }

template <class T, class... U>
array(T, U...) -> array<T, plus_one(sizeof...(U))>;

The problem is that function parameters are not constexpr objects, so you cannot invoke constexpr member functions on them if those member functions read kind of local state.


Parameter/argument values are not constexpr.

You might use variadic template to know size at compile time, or type with know size (std::array or C-array reference).


Is there a way to make this work without going down the make_array() route?

Why don't you try with the following deduction guide ?

template <typename T, std::size_t N>
array(T const (&)[N]) -> array<T, N>;

This way, the argument in myArray2 = {{1,2,3}} isn't interpreted as a std::initializer_list (that as argument can't be considered constexpr, so it's size() can't be used for a template argument) but as a C-style array.

So can be deduced, as template arguments, type and size (T and N) and also the size (N) can be used as template argument.