Posts

Can template deduction guides call constexpr functions?

Image
14 I have my own fixed-size array type I want to be constexpr constructible from an std::initializer_list without having to explicitly define the size template argument. I thought I'd be able to use a template deduction guide but it looks like it's not treating std::initializer_list::size() as a constexpr function for it. Here's an example of trying to make a deduction guide for std::array (which is similar to my type and has the same problem): namespace std { template<typename T> array(initializer_list<T> initialiserList) -> array<T, initialiserList.size()>; } static constexpr std::array myArray = {1,2,3}; static constexpr std::array myArray2 = {{1,2,3}}; I've tried on MSVC and Clang, both give roughly the same errors: myArray has an error complaining ab...