typedef bool Bool;
typedef std::monostate Empty;
template using TupleT = std::tuple;
template struct VariantT {
static_assert(sizeof...(Types) > 0, "VariantT must have at least one type");
std::uint8_t tag;
std::aligned_union_t value;
};
Когда я определяю следующие рекурсивные типы:
struct ConsBool;
struct ConsListBool;
struct Nil;
typedef VariantT ListBool;
typedef VariantT ListListBool;
struct ConsBool
{
using type = TupleT;
type value;
};
struct ConsListBool
{
using type = TupleT;
type value; //
ошибка: недопустимое применение 'sizeof' к неполному типу 'nil' < /p>
< /blockquote>
Но когда я использую альтернативный заказ: < /p>
struct Nil;
struct ConsBool;
struct ConsListBool;
typedef VariantT ListBool;
typedef VariantT ListListBool;
struct Nil
{
Empty value;
};
struct ConsBool
{
using type = TupleT;
type value;
};
struct ConsListBool
{
using type = TupleT;
type value;
};
< /code>
это компилируется. < /p>
Почему это? И какова логика заказа? включено ниже: < /p>
/usr/include/c++/12/type_traits: In instantiation of ‘const std::size_t std::__strictest_alignment::_S_size’:
/usr/include/c++/12/type_traits
/usr/include/c++/12/type_traits
/usr/include/c++/12/type_traits
/usr/include/c++/12/type_traits
include/types/compound.hpp:19:39: required from ‘struct VariantT’
/usr/include/c++/12/tuple:69:23: required from ‘struct std::_Tuple_impl’
/usr/include/c++/12/tuple:981:11: required from ‘class std::tuple’
include/main/main.hpp: required from here
/usr/include/c++/12/type_traits
2136 | sizeof(_Tp) > __strictest_alignment::_S_size
Подробнее здесь: https://stackoverflow.com/questions/793 ... reordering
Мобильная версия