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

View File

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

View File

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

View File

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

View File

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