From 3858b4f3ec1d56fe36c8f7fee476ffaeaab023c0 Mon Sep 17 00:00:00 2001 From: yyc12345 Date: Thu, 15 Aug 2024 16:50:15 +0800 Subject: [PATCH] fix: use new way to detect c++ version in MSVC. - use new macro to check C++ version in MSVC, instead of use compiler switch and __cplusplus macro. --- src/CMakeLists.txt | 4 ---- src/StdPatch.hpp | 8 +++++--- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index dbcf12d..b050eac 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -72,10 +72,6 @@ PRIVATE $<$:_UNICODE> ) target_compile_options(YYCCommonplace -# Enable new __cplusplus macro in MSVC. -# Because we use it in header, so we need populate it. -PUBLIC - $<$:/Zc:__cplusplus> # Order build as UTF-8 in MSVC PRIVATE $<$:/utf-8> diff --git a/src/StdPatch.hpp b/src/StdPatch.hpp index 1cfddf0..69388e1 100644 --- a/src/StdPatch.hpp +++ b/src/StdPatch.hpp @@ -204,10 +204,12 @@ namespace YYCC::StdPatch { */ template bool Contains(const _TContainer& container, const _TKey& key) { -#if __cplusplus < 202002L - return container.find(key) != container.end(); -#else + // __cplusplus macro need special compiler switch enabled when compiling. + // So we use _MSVC_LANG check it instead. +#if __cplusplus >= 202002L || (defined(_MSVC_LANG) && _MSVC_LANG >= 202002L) return container.contains(key); +#else + return container.find(key) != container.end(); #endif }