Skip to content

Commit

Permalink
Replace Yes/No with int/char
Browse files Browse the repository at this point in the history
  • Loading branch information
bblanchon committed Nov 22, 2022
1 parent 079ccad commit 6447520
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 30 deletions.
9 changes: 3 additions & 6 deletions src/ArduinoJson/Polyfills/type_traits/is_base_of.hpp
Expand Up @@ -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
9 changes: 3 additions & 6 deletions src/ArduinoJson/Polyfills/type_traits/is_class.hpp
Expand Up @@ -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
9 changes: 3 additions & 6 deletions src/ArduinoJson/Polyfills/type_traits/is_convertible.hpp
Expand Up @@ -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
Expand Down
9 changes: 3 additions & 6 deletions src/ArduinoJson/Variant/ConverterImpl.hpp
Expand Up @@ -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
9 changes: 3 additions & 6 deletions src/ArduinoJson/Variant/VariantAttorney.hpp
Expand Up @@ -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;
};

Expand Down

0 comments on commit 6447520

Please sign in to comment.