From 66d682b28c9e28efc8fe5f0898432e0daceb3080 Mon Sep 17 00:00:00 2001 From: qicosmos Date: Tue, 8 Oct 2024 15:46:41 +0800 Subject: [PATCH 1/2] fix check --- include/ylt/reflection/member_names.hpp | 2 +- include/ylt/reflection/member_value.hpp | 4 ++-- src/reflection/tests/test_reflection.cpp | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/include/ylt/reflection/member_names.hpp b/include/ylt/reflection/member_names.hpp index e4a8c7bb2..cf53e5b3a 100644 --- a/include/ylt/reflection/member_names.hpp +++ b/include/ylt/reflection/member_names.hpp @@ -299,7 +299,7 @@ inline constexpr size_t index_of(std::string_view name) { return arr.size(); } -#if __has_include() +#if __cplusplus >= 202002L template inline constexpr size_t index_of() { return index_of(name.str()); diff --git a/include/ylt/reflection/member_value.hpp b/include/ylt/reflection/member_value.hpp index f1b85b1d0..dbdafbabe 100644 --- a/include/ylt/reflection/member_value.hpp +++ b/include/ylt/reflection/member_value.hpp @@ -156,7 +156,7 @@ inline constexpr auto& get(T& t) { return std::get(ref_tp); } -#if __has_include() +#if __cplusplus >= 202002L template inline constexpr auto& get(T& t) { constexpr size_t index = index_of(); @@ -257,7 +257,7 @@ inline constexpr void for_each(T&& t, Visit&& func) { #if (defined(__GNUC__) && __GNUC__ > 10) || \ ((defined(__clang__) || defined(_MSC_VER)) && __has_include()) -#if __has_include() +#if __cplusplus >= 202002L template inline constexpr auto operator""_ylts() { return s; diff --git a/src/reflection/tests/test_reflection.cpp b/src/reflection/tests/test_reflection.cpp index 598732801..fb5cb939e 100644 --- a/src/reflection/tests/test_reflection.cpp +++ b/src/reflection/tests/test_reflection.cpp @@ -83,7 +83,7 @@ void test_pt() { static_assert(y == 4); CHECK(y == 4); -#if __has_include() +#if __cplusplus >= 202002L constexpr auto x = get<"x"_ylts>(pt); static_assert(x == 2); #endif @@ -118,7 +118,7 @@ TEST_CASE("test member value") { auto& age1 = get(p, "age"); CHECK(age1 == 6); -#if __has_include() +#if __cplusplus >= 202002L auto& age2 = get<"age"_ylts>(p); CHECK(age2 == 6); @@ -178,7 +178,7 @@ TEST_CASE("test member value") { constexpr std::string_view name2 = name_of(2); CHECK(name2 == "str"); -#if __has_include() +#if __cplusplus >= 202002L constexpr size_t idx = index_of(); CHECK(idx == 2); @@ -359,7 +359,7 @@ TEST_CASE("test macros") { auto var = get(t, 3); CHECK(*std::get<3>(var) == 6); -#if __has_include() +#if __cplusplus >= 202002L auto& age2 = get<"age"_ylts>(t); CHECK(age2 == 6); From f3f07dcc4fe515961ef5e90fa0daa9eed634b42c Mon Sep 17 00:00:00 2001 From: qicosmos Date: Tue, 8 Oct 2024 16:03:37 +0800 Subject: [PATCH 2/2] update --- src/struct_pb/examples/main.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/struct_pb/examples/main.cpp b/src/struct_pb/examples/main.cpp index 0c440175a..c0fd83dde 100644 --- a/src/struct_pb/examples/main.cpp +++ b/src/struct_pb/examples/main.cpp @@ -27,7 +27,8 @@ struct person { std::string name; int age; }; -#if __cplusplus >= 202002L + +#if __GNUC__ < 11 || __cplusplus < 202002L YLT_REFL(person, id, name, age); #endif