Код: Выделить всё
template
concept myrequirement= requires(T s)
{
{ s.type() } -> std::same_as;
};
enum MyType
{
TYPE1,
TYPE2,
TYPE3,
};
Код: Выделить всё
struct
{
static constexpr uint8_t type() { return TYPE1;}
} foo;
struct
{
static constexpr uint8_t type() { return TYPE2;}
} bar;
struct
{
static constexpr uint8_t type() { return TYPE3;}
} baz;
Код: Выделить всё
auto my_struct = get_instance();
Код: Выделить всё
template
constexpr auto& get_instance_amongst(const StructTypes&... structs)
{
// how do we do this ?
}
template
constexpr auto& get_instance()
{
return get_instance_amongst(foo, bar, baz);
}
Возможно ли что-нибудь близкое к этому? Может быть, с выражением сгиба?
Подробнее здесь: https://stackoverflow.com/questions/794 ... named-stru
Мобильная версия