From 51d7ee349346c43325ebbe7e575c2d164c1e2d91 Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Thu, 14 Sep 2023 13:01:16 +0200 Subject: [PATCH] Fix to support pre-C++17 Signed-off-by: Simon Rozman --- include/stdex/compat.hpp | 6 ++++++ include/stdex/unicode.hpp | 6 +++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/include/stdex/compat.hpp b/include/stdex/compat.hpp index c73266921..961555d69 100644 --- a/include/stdex/compat.hpp +++ b/include/stdex/compat.hpp @@ -162,6 +162,12 @@ #endif #endif +#if _HAS_CXX17 +#define _Constexpr_ constexpr +#else +#define _Constexpr_ +#endif + #ifdef _MSC_VER #define _Deprecated_(message) __declspec(deprecated(message)) #else diff --git a/include/stdex/unicode.hpp b/include/stdex/unicode.hpp index 369592fb9..31f2ec58e 100644 --- a/include/stdex/unicode.hpp +++ b/include/stdex/unicode.hpp @@ -101,7 +101,7 @@ namespace stdex return; } - if constexpr (sizeof(T_from) == sizeof(char) && sizeof(T_to) == sizeof(wchar_t)) { + if _Constexpr_ (sizeof(T_from) == sizeof(char) && sizeof(T_to) == sizeof(wchar_t)) { assert(count_src < INT_MAX || count_src == SIZE_MAX); // Try to convert to stack buffer first. @@ -124,7 +124,7 @@ namespace stdex throw std::runtime_error("MultiByteToWideChar failed"); } - if constexpr (sizeof(T_from) == sizeof(wchar_t) && sizeof(T_to) == sizeof(char)) { + if _Constexpr_ (sizeof(T_from) == sizeof(wchar_t) && sizeof(T_to) == sizeof(char)) { assert(count_src < INT_MAX || count_src == SIZE_MAX); // Try to convert to stack buffer first. @@ -147,7 +147,7 @@ namespace stdex throw std::runtime_error("WideCharToMultiByte failed"); } - if constexpr (sizeof(T_from) == sizeof(char) && sizeof(T_to) == sizeof(char)) { + if _Constexpr_ (sizeof(T_from) == sizeof(char) && sizeof(T_to) == sizeof(char)) { assert(count_src < INT_MAX || count_src == SIZE_MAX); // Try to convert to stack buffer first.