Minh Nguyen / ArduinoJson
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers limits.hpp Source File

limits.hpp

00001 // ArduinoJson - arduinojson.org
00002 // Copyright Benoit Blanchon 2014-2021
00003 // MIT License
00004 
00005 #pragma once
00006 
00007 #include "type_traits.hpp"
00008 
00009 #ifdef _MSC_VER
00010 #pragma warning(push)
00011 #pragma warning(disable : 4310)
00012 #endif
00013 
00014 namespace ARDUINOJSON_NAMESPACE {
00015 
00016 // Differs from standard because we can't use the symbols "min" and "max"
00017 template <typename T, typename Enable = void>
00018 struct numeric_limits;
00019 
00020 template <typename T>
00021 struct numeric_limits<T, typename enable_if<is_unsigned<T>::value>::type> {
00022   static T lowest() {
00023     return 0;
00024   }
00025   static T highest() {
00026     return T(-1);
00027   }
00028 };
00029 
00030 template <typename T>
00031 struct numeric_limits<
00032     T, typename enable_if<is_integral<T>::value && is_signed<T>::value>::type> {
00033   static T lowest() {
00034     return T(T(1) << (sizeof(T) * 8 - 1));
00035   }
00036   static T highest() {
00037     return T(~lowest());
00038   }
00039 };
00040 
00041 }  // namespace ARDUINOJSON_NAMESPACE
00042 
00043 #ifdef _MSC_VER
00044 #pragma warning(pop)
00045 #endif