Currently using C++20, GCC 11.1.0.
I'm trying to create types in a namespace with a unique value
and name
. I came up with this structure specifically to be able to access the variables with the scope resolution operator like so: foo::bar::name
. However, I have no idea how to initialize the name
variable. I tried adding a second non-type parameter const char* barName
, but it wouldn't let me use string literals as template arguments.
Code:
namespace foo
{
template<uint32_t id>
struct bar
{
static constexpr uint32_t value {id};
static constexpr std::string_view name {};
};
using a = bar<0>;
using b = bar<1>;
}
Error Code:
namespace foo
{
template<uint32_t id, const char* barName>
struct bar
{
static constexpr uint32_t value {id};
static constexpr std::string_view name {barName};
};
using a = bar<0, "a">;
using b = bar<1, "b">;
}