From a7a0f97b7659a1b551aa4b465376abb0c0a6492e Mon Sep 17 00:00:00 2001 From: CCat <103255096+autobotoptimusprime@users.noreply.github.com> Date: Thu, 28 Dec 2023 23:23:03 +0800 Subject: [PATCH] =?UTF-8?q?Create=20mq=E8=B4=A5.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 第十题求聚合类成员数量 --- .../mq\350\264\245.cpp" | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 "src/\347\276\244\345\217\213\346\217\220\344\272\244/\347\254\25410\351\242\230/mq\350\264\245.cpp" diff --git "a/src/\347\276\244\345\217\213\346\217\220\344\272\244/\347\254\25410\351\242\230/mq\350\264\245.cpp" "b/src/\347\276\244\345\217\213\346\217\220\344\272\244/\347\254\25410\351\242\230/mq\350\264\245.cpp" new file mode 100644 index 00000000..2a5822f0 --- /dev/null +++ "b/src/\347\276\244\345\217\213\346\217\220\344\272\244/\347\254\25410\351\242\230/mq\350\264\245.cpp" @@ -0,0 +1,66 @@ +#include +#include +#include + +namespace detail { + template + constexpr bool always_false = false; + + template + using remove_cvref_t = std::remove_cv_t>; + + template + using size_constant = std::integral_constant; + + struct enable_as_any_type_helper { + template + operator T () noexcept; + }; + + template + using enable_as_any_type = enable_as_any_type_helper; + + template + struct test_constructible_helper : std::false_type {}; + + template + struct test_constructible_helper, std::void_t>()}...})>> : std::true_type {}; + + template + struct test_constructible : test_constructible_helper> {}; + + template + struct size_helper : std::conditional_t::value, size_helper, size_constant> {}; + + template + struct size { + static_assert(always_false, "type `T` must be an aggregate-type!"); + }; + + template + struct size>> : size_helper<0, Aggregate> {}; +} + +template +constexpr std::size_t size = detail::size::value; + +struct Pos { + int x; + int y; + int z; +}; + +struct Agg { + int i; + Pos pos; + int arr[4]; + std::string str; + std::vector vec; + float f; +}; + +auto main() ->int { + std::cout << size << std::endl; + // 遍历成员那个就不写了, 😊 + return 0; +}