From f2f856e89f9ff7d26b54a31d20f23c767e0a0b15 Mon Sep 17 00:00:00 2001 From: Benoit Blanchon Date: Sat, 4 Jan 2020 15:05:20 +0100 Subject: [PATCH] Auto enable std::string and stream on modern compilers (closes #1156) --- CHANGELOG.md | 2 ++ src/ArduinoJson/Configuration.hpp | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0ff87d372..101b8eb2d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ HEAD * Added `BasicJsonDocument::shrinkToFit()` * Added support of `uint8_t` for `serializeJson()`, `serializeJsonPretty()`, and `serializeMsgPack()` (issue #1142) +* Auto enable support for `std::string` and `std::stream` on modern compilers (issue #1156) + No need to define `ARDUINOJSON_ENABLE_STD_STRING` and `ARDUINOJSON_ENABLE_STD_STREAM`. v6.13.0 (2019-11-01) ------- diff --git a/src/ArduinoJson/Configuration.hpp b/src/ArduinoJson/Configuration.hpp index ecaf68168..0ca789087 100644 --- a/src/ArduinoJson/Configuration.hpp +++ b/src/ArduinoJson/Configuration.hpp @@ -31,6 +31,29 @@ #endif #endif +// Auto enable std::stream if the right headers are here and no conflicting +// macro is defined +#if !defined(ARDUINOJSON_ENABLE_STD_STREAM) && defined(__has_include) +#if __has_include() && \ + __has_include() && \ + !defined(min) && \ + !defined(max) +#define ARDUINOJSON_ENABLE_STD_STREAM 1 +#else +#define ARDUINOJSON_ENABLE_STD_STREAM 0 +#endif +#endif + +// Auto enable std::string if the right header is here and no conflicting +// macro is defined +#if !defined(ARDUINOJSON_ENABLE_STD_STRING) && defined(__has_include) +#if __has_include() && !defined(min) && !defined(max) +#define ARDUINOJSON_ENABLE_STD_STRING 1 +#else +#define ARDUINOJSON_ENABLE_STD_STRING 0 +#endif +#endif + #if ARDUINOJSON_EMBEDDED_MODE // Store floats by default to reduce the memory usage (issue #134)