Replace Yes/No with int/char

This commit is contained in:
Benoit Blanchon
2022-11-22 18:56:42 +01:00
parent 079ccadbee
commit 6447520b5b
5 changed files with 15 additions and 30 deletions

View File

@ -13,14 +13,11 @@ namespace ARDUINOJSON_NAMESPACE {
template <typename TBase, typename TDerived>
class is_base_of {
protected: // <- to avoid GCC's "all member functions in class are private"
typedef char Yes[1];
typedef char No[2];
static Yes& probe(const TBase*);
static No& probe(...);
static int probe(const TBase*);
static char probe(...);
public:
static const bool value =
sizeof(probe(reinterpret_cast<TDerived*>(0))) == sizeof(Yes);
sizeof(probe(reinterpret_cast<TDerived*>(0))) == sizeof(int);
};
} // namespace ARDUINOJSON_NAMESPACE

View File

@ -11,16 +11,13 @@ namespace ARDUINOJSON_NAMESPACE {
template <typename T>
struct is_class {
protected: // <- to avoid GCC's "all member functions in class are private"
typedef char Yes[1];
typedef char No[2];
template <typename U>
static Yes& probe(void (U::*)(void));
static int probe(void (U::*)(void));
template <typename>
static No& probe(...);
static char probe(...);
public:
static const bool value = sizeof(probe<T>(0)) == sizeof(Yes);
static const bool value = sizeof(probe<T>(0)) == sizeof(int);
};
} // namespace ARDUINOJSON_NAMESPACE

View File

@ -24,16 +24,13 @@ namespace ARDUINOJSON_NAMESPACE {
template <typename From, typename To>
struct is_convertible {
protected: // <- to avoid GCC's "all member functions in class are private"
typedef char Yes[1];
typedef char No[2];
static Yes& probe(To);
static No& probe(...);
static int probe(To);
static char probe(...);
static From& _from;
public:
static const bool value = sizeof(probe(_from)) == sizeof(Yes);
static const bool value = sizeof(probe(_from)) == sizeof(int);
};
} // namespace ARDUINOJSON_NAMESPACE

View File

@ -307,15 +307,12 @@ inline bool canConvertFromJson(VariantConstRef src, const std::string_view&) {
template <typename T>
struct ConverterNeedsWriteableRef {
protected: // <- to avoid GCC's "all member functions in class are private"
typedef char Yes[1];
typedef char No[2];
static Yes& probe(T (*f)(VariantRef));
static No& probe(T (*f)(VariantConstRef));
static int probe(T (*f)(VariantRef));
static char probe(T (*f)(VariantConstRef));
public:
static const bool value =
sizeof(probe(Converter<T>::fromJson)) == sizeof(Yes);
sizeof(probe(Converter<T>::fromJson)) == sizeof(int);
};
} // namespace ARDUINOJSON_NAMESPACE

View File

@ -17,16 +17,13 @@ class VariantAttorney {
template <typename TClient>
struct ResultOfGetData {
protected: // <- to avoid GCC's "all member functions in class are private"
typedef char Yes[1];
typedef char No[2];
static Yes& probe(const VariantData*);
static No& probe(VariantData*);
static int probe(const VariantData*);
static char probe(VariantData*);
static TClient& client;
public:
typedef typename conditional<sizeof(probe(client.getData())) == sizeof(Yes),
typedef typename conditional<sizeof(probe(client.getData())) == sizeof(int),
const VariantData*, VariantData*>::type type;
};