#include #include using namespace std; using namespace struct_pack; using UniversalVectorType = detail::UniversalVectorType; using UniversalType = detail::UniversalType; using UniversalOptionalType = detail::UniversalOptionalType; using UniversalIntegralType = detail::UniversalIntegralType; using UniversalNullptrType = detail::UniversalNullptrType; using UniversalCompatibleType = detail::UniversalCompatibleType; struct person { int64_t id; std::string name; int age; double salary; }; template struct is_constructable_impl : std::false_type {}; template struct is_constructable_impl < T, construct_param_t, std::void_t< decltype(T{ {Args{}}..., {construct_param_t{}} }) > , Args... > : std::true_type {}; template bool is_constructable = is_constructable_impl::value; template std::size_t members_count_impl() { if (is_constructable) { cout << "is_constructable UniversalVectorType \n"; //return members_count_impl(); } else if (is_constructable) { cout << "is_constructable UniversalType \n"; //return members_count_impl(); } else { return sizeof...(Args); } return sizeof...(Args); } int main() { person person1{ .id = 1, .name = "hello struct pack", .age = 20, .salary = 1024.42 }; using type = remove_cvref_t; using type2 = remove_cvref_t; auto Count = members_count; int isc = members_count_impl(); int c2 = detail::members_count(); // 1行代码序列化 vector buffer = serialize(person1); // 只反序列化person的第2个字段 auto name = get_field(buffer.data(), buffer.size()); cout << "hello " << name.value() << "Count == " << Count << c2; }