Minh Nguyen / ArduinoJson
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers is_convertible.hpp Source File

is_convertible.hpp

00001 // ArduinoJson - arduinojson.org
00002 // Copyright Benoit Blanchon 2014-2021
00003 // MIT License
00004 
00005 #pragma once
00006 
00007 #include "declval.hpp"
00008 
00009 #ifdef _MSC_VER
00010 #pragma warning(push)
00011 // conversion from 'T' to 'To', possible loss of data
00012 #pragma warning(disable : 4244)
00013 #endif
00014 
00015 // clang-format off
00016 #ifdef __ICCARM__
00017 // Suppress IAR Compiler Warning[Pa093]: implicit conversion from floating point to integer
00018 #pragma diag_suppress=Pa093
00019 #endif
00020 // clang-format on
00021 
00022 namespace ARDUINOJSON_NAMESPACE {
00023 
00024 template <typename From, typename To>
00025 struct is_convertible {
00026  protected:  // <- to avoid GCC's "all member functions in class are private"
00027   typedef char Yes[1];
00028   typedef char No[2];
00029 
00030   static Yes &probe(To);
00031   static No &probe(...);
00032 
00033  public:
00034   static const bool value = sizeof(probe(declval<From>())) == sizeof(Yes);
00035 };
00036 
00037 }  // namespace ARDUINOJSON_NAMESPACE
00038 
00039 #ifdef _MSC_VER
00040 #pragma warning(pop)
00041 #endif
00042 
00043 // clang-format off
00044 #ifdef __ICCARM__
00045 #pragma diag_default=Pa093
00046 #endif
00047 // clang-format on