I am trying to create a templated class containing enum-string pairs and unable to make type deduction work. With a following code i have two problems:
namespace {
template<typename T, size_t S>
using EnumStringArray = std::array<std::pair<T, const char*>, S>;
}
template<typename T, size_t S>
class EnumToString {
public:
constexpr EnumToString(const EnumStringArray<T, S>& array) :
_array(array)
{}
private:
EnumStringArray<T, S> _array;
};
template<typename T, size_t S>
EnumToString(const EnumStringArray<T, S>&) -> EnumToString<T, S>;
enum MyEnum {
One,
Two
};
constexpr EnumToString enumStrings = {{{ //<---- does not compile without explicit types
{One, "One"},
{Two, "Two"}
}}};
- Why compiler can't deduce parameters of EnumToString by himself within constructor?
- Why user deduction guide does not help?