From b1002fd198f8251cb1b55ad78bc13fbdd1f9ae84 Mon Sep 17 00:00:00 2001 From: nemtrif Date: Sun, 30 Jun 2019 13:06:11 -0400 Subject: [PATCH] Introduce UTF_CPP_CPLUSPLUS macro. Let the users set the C++ standard version they want to support. --- README.md | 6 +++++- source/utf8.h | 10 +++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4ec9a1b..0c689cf 100644 --- a/README.md +++ b/README.md @@ -94,7 +94,11 @@ With a more modern compiler, the same operation would look like: ``` If `__cplusplus` macro points to a C++ 11 or later, the library exposes API that takes into account C++ standard Unicode strings and move semantics. With an older compiler, it is still -possible to use the same functionality, just in a little less convenient way. +possible to use the same functionality, just in a little less convenient way + +In case you do not trust the `__cplusplus` macro or, for instance, do not want to include +the C++ 11 helper functions even with a modern compiler, define `UTF_CPP_CPLUSPLUS` macro +before including `utf8.h` and assign it a value for the standard you want to use - the values are the same as for the `__cplusplus` macro. This can be also useful with compilers that are conservative in setting the `__cplusplus` macro even if they have a good support for a recent standard edition - Microsoft's Visual C++ is one example. ### Checking if a file contains valid UTF-8 text diff --git a/source/utf8.h b/source/utf8.h index c2c85d6..d8c58d9 100644 --- a/source/utf8.h +++ b/source/utf8.h @@ -31,7 +31,15 @@ DEALINGS IN THE SOFTWARE. #include "utf8/checked.h" #include "utf8/unchecked.h" -#if __cplusplus >= 201103L // C++ 11 or later +// Determine whether to include C++ 11 specific header +// If the user defines UTF_CPP_CPLUSPLUS, use that. +// Otherwise, trust the unreliable predefined macro __cplusplus + +#if !defined UTF_CPP_CPLUSPLUS + #define UTF_CPP_CPLUSPLUS __cplusplus +#endif + +#if UTF_CPP_CPLUSPLUS >= 201103L // C++ 11 or later #include "utf8/cpp11.h" #endif // C++ 11 or later