From af416f81b14a3bee682e300b165a6efdb9739d54 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Fri, 23 Nov 2018 16:41:24 +0100 Subject: o Trying to improve compatibility with some feature checks. o Misc nits. --- include/ble/Bluetooth.h | 4 --- include/ble/att.h | 6 ++-- include/ble/compiler-support.h | 62 ++++++++++++++++++++++++++++++++++++++++++ include/ble/misc.h | 4 +-- 4 files changed, 68 insertions(+), 8 deletions(-) create mode 100644 include/ble/compiler-support.h (limited to 'include') diff --git a/include/ble/Bluetooth.h b/include/ble/Bluetooth.h index 5f7cd17..28e2794 100644 --- a/include/ble/Bluetooth.h +++ b/include/ble/Bluetooth.h @@ -1,7 +1,6 @@ #ifndef BLUETOOTH_H #define BLUETOOTH_H -#include #include #include #include @@ -23,9 +22,6 @@ using std::vector; using std::map; using std::runtime_error; -template -using o = std::optional; - class BluetoothAdapter; class BluetoothDevice; class BluetoothGatt; diff --git a/include/ble/att.h b/include/ble/att.h index 152a779..7b77812 100644 --- a/include/ble/att.h +++ b/include/ble/att.h @@ -1,6 +1,5 @@ #pragma once -#include #include #include "ble/ByteBuffer.h" @@ -9,6 +8,9 @@ namespace trygvis { namespace bluetooth { +using ::trygvis::compiler::variant; +using ::trygvis::compiler::monostate; + /** * BLUETOOTH SPECIFICATION Version 4.0 [Vol 3] - Attribute Protocol (ATT) - 3.4.8 Attribute Opcode Summary * Table 3.37 @@ -144,7 +146,7 @@ struct HandleValueIndication { ByteBuffer data; }; -using AttVariant = std::variant) +# include +# define have_optional 1 +# elif __has_include() +# include +# define have_optional 1 +# define have_experimental_optional 1 +# else +# define have_optional 0 +# endif + +# if __has_include() +# include +# define have_variant 1 +# elif __has_include() +# include +# define have_variant 1 +# define have_experimental_variant 1 +# else +# define have_variant 0 +# endif + +#endif + +namespace trygvis { +namespace compiler { + +#if have_experimental_optional + +template +using o = std::experimental::optional; + +#elif have_optional + +template +using o = std::optional; + +#endif + +#if have_experimental_variant + +template +using variant = std::experimental::variant; +using monostate = std::experimental::monostate; + +#elif have_variant + +template +using variant = std::variant; +using monostate = std::monostate; + +#endif + +} // namespace compiler +} // namespace trygvis + + +#endif diff --git a/include/ble/misc.h b/include/ble/misc.h index 563d039..aa0ba2e 100644 --- a/include/ble/misc.h +++ b/include/ble/misc.h @@ -1,5 +1,6 @@ #pragma once +#include "ble/compiler-support.h" #include "ByteBuffer.h" #include @@ -10,8 +11,7 @@ namespace trygvis { namespace bluetooth { -template -using o = std::optional; +using ::trygvis::compiler::o; class BluetoothAdapter; class BluetoothDevice; -- cgit v1.2.3