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.
This commit is contained in:
yyc12345 2024-08-15 16:50:15 +08:00
parent f3a88e951c
commit 3858b4f3ec
2 changed files with 5 additions and 7 deletions

View File

@ -72,10 +72,6 @@ PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:_UNICODE>
)
target_compile_options(YYCCommonplace
# Enable new __cplusplus macro in MSVC.
# Because we use it in header, so we need populate it.
PUBLIC
$<$<CXX_COMPILER_ID:MSVC>:/Zc:__cplusplus>
# Order build as UTF-8 in MSVC
PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:/utf-8>

View File

@ -204,10 +204,12 @@ namespace YYCC::StdPatch {
*/
template<class _TContainer, class _TKey>
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
}