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); 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