From abc4d755f7fe191061af49ef9a23747b185f83f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stanislav=20Angelovi=C4=8D?= Date: Mon, 19 Feb 2024 19:49:31 +0100 Subject: [PATCH] fix: conditional use and tests of span (#411) --- include/sdbus-c++/Message.h | 14 ++++++++------ include/sdbus-c++/TypeTraits.h | 8 +++++--- tests/unittests/Message_test.cpp | 4 ++-- tests/unittests/TypeTraits_test.cpp | 8 ++++---- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/include/sdbus-c++/Message.h b/include/sdbus-c++/Message.h index 743604c..db5f658 100644 --- a/include/sdbus-c++/Message.h +++ b/include/sdbus-c++/Message.h @@ -36,8 +36,10 @@ #include #include #include -#if __cplusplus >= 202002L -#include +#ifdef __has_include +# if __has_include() +# include +# endif #endif #include #include @@ -104,7 +106,7 @@ namespace sdbus { Message& operator<<(const std::vector<_Element, _Allocator>& items); template Message& operator<<(const std::array<_Element, _Size>& items); -#if __cplusplus >= 202002L +#ifdef __cpp_lib_span template Message& operator<<(const std::span<_Element, _Extent>& items); #endif @@ -140,7 +142,7 @@ namespace sdbus { Message& operator>>(std::vector<_Element, _Allocator>& items); template Message& operator>>(std::array<_Element, _Size>& items); -#if __cplusplus >= 202002L +#ifdef __cpp_lib_span template Message& operator>>(std::span<_Element, _Extent>& items); #endif @@ -339,7 +341,7 @@ namespace sdbus { return *this; } -#if __cplusplus >= 202002L +#ifdef __cpp_lib_span template inline Message& Message::operator<<(const std::span<_Element, _Extent>& items) { @@ -498,7 +500,7 @@ namespace sdbus { return *this; } -#if __cplusplus >= 202002L +#ifdef __cpp_lib_span template inline Message& Message::operator>>(std::span<_Element, _Extent>& items) { diff --git a/include/sdbus-c++/TypeTraits.h b/include/sdbus-c++/TypeTraits.h index e7bc59a..4fd0343 100644 --- a/include/sdbus-c++/TypeTraits.h +++ b/include/sdbus-c++/TypeTraits.h @@ -35,8 +35,10 @@ #include #include #include -#if __cplusplus >= 202002L -#include +#ifdef __has_include +# if __has_include() +# include +# endif #endif #include #include @@ -399,7 +401,7 @@ namespace sdbus { } }; -#if __cplusplus >= 202002L +#ifdef __cpp_lib_span template struct signature_of> { diff --git a/tests/unittests/Message_test.cpp b/tests/unittests/Message_test.cpp index 73e792f..c91f230 100644 --- a/tests/unittests/Message_test.cpp +++ b/tests/unittests/Message_test.cpp @@ -311,7 +311,7 @@ TEST(AMessage, CanCarryDBusArrayOfNontrivialTypesGivenAsStdArray) ASSERT_THAT(dataRead, Eq(dataWritten)); } -#if __cplusplus >= 202002L +#ifdef __cpp_lib_span TEST(AMessage, CanCarryDBusArrayOfTrivialTypesGivenAsStdSpan) { auto msg = sdbus::createPlainMessage(); @@ -378,7 +378,7 @@ TEST(AMessage, ThrowsWhenDestinationStdArrayIsTooSmallDuringDeserialization) ASSERT_THROW(msg >> dataRead, sdbus::Error); } -#if __cplusplus >= 202002L +#ifdef __cpp_lib_span TEST(AMessage, ThrowsWhenDestinationStdSpanIsTooSmallDuringDeserialization) { auto msg = sdbus::createPlainMessage(); diff --git a/tests/unittests/TypeTraits_test.cpp b/tests/unittests/TypeTraits_test.cpp index 9f69895..3e7e092 100644 --- a/tests/unittests/TypeTraits_test.cpp +++ b/tests/unittests/TypeTraits_test.cpp @@ -88,13 +88,13 @@ namespace TYPE(sdbus::ObjectPath)HAS_DBUS_TYPE_SIGNATURE("o") TYPE(sdbus::Signature)HAS_DBUS_TYPE_SIGNATURE("g") TYPE(sdbus::Variant)HAS_DBUS_TYPE_SIGNATURE("v") + TYPE(std::variant)HAS_DBUS_TYPE_SIGNATURE("v") TYPE(sdbus::UnixFd)HAS_DBUS_TYPE_SIGNATURE("h") TYPE(sdbus::Struct)HAS_DBUS_TYPE_SIGNATURE("(b)") TYPE(sdbus::Struct)HAS_DBUS_TYPE_SIGNATURE("(qdsv)") TYPE(std::vector)HAS_DBUS_TYPE_SIGNATURE("an") TYPE(std::array)HAS_DBUS_TYPE_SIGNATURE("an") - TYPE(std::variant)HAS_DBUS_TYPE_SIGNATURE("v") -#if __cplusplus >= 202002L +#ifdef __cpp_lib_span TYPE(std::span)HAS_DBUS_TYPE_SIGNATURE("an") #endif TYPE(SomeEnumClass)HAS_DBUS_TYPE_SIGNATURE("y") @@ -138,13 +138,13 @@ namespace , sdbus::ObjectPath , sdbus::Signature , sdbus::Variant + , std::variant , sdbus::UnixFd , sdbus::Struct , sdbus::Struct , std::vector , std::array - , std::variant -#if __cplusplus >= 202002L +#ifdef __cpp_lib_span , std::span #endif , SomeEnumClass