Is there a way to construct the elements of an enum from another source of inputs(it is constexpr), like std::array
, which is compile time known, like following:
std::array<std::string_view, 3> strs{"AA","BB","CC"};
constexpr int convert(const std::string_view& str) { .... };
enum class MyEnum {
AA = convert(strs[0]), // <== how to generate this 3 lines automatically
BB = convert(strs[1]),
CC = convert(strs[2])
};
The purpose is to maintain only the strs, like adding a new enum element, instead of maintaining two copies of same data. Is there anyway to do this in C++17?