martinus / robin-hood-hashing

Fast & memory efficient hashtable based on robin hood hashing for C++11/14/17/20
https://gitter.im/martinus/robin-hood-hashing
MIT License
1.5k stars 142 forks source link

__cplusplus in MSVC is always 199711L #134

Open Leopard20 opened 2 years ago

Leopard20 commented 2 years ago

Hi. I recently realized that MSVC always sets __cplusplus to 199711L unless /Zc:__cplusplus is enabled: https://docs.microsoft.com/en-us/cpp/build/reference/zc-cplusplus?view=msvc-160&viewFallbackFrom=vs-2017

Since you use this macro in your code, I figured I should ask whether it matters in terms of performance: https://github.com/martinus/robin-hood-hashing/blob/9dbc277088703f47395ae1d95bb656bade9592ba/src/include/robin_hood.h#L51 https://github.com/martinus/robin-hood-hashing/blob/9dbc277088703f47395ae1d95bb656bade9592ba/src/include/robin_hood.h#L216

For now I just replaced the macro with a custom macro I wrote myself so that it uses the latest compiler features.

martinus commented 2 years ago

This only enables the ability to use std::string_view as key in a hashmap. So it's not a performance issue but one feature could be disabled

harayuu9 commented 2 years ago

Hi. I think it is better to use __cplusplus and _MSVC_LANG together in MSVC environment. (This is only available in Visual Studio 2015 or later, but _MSVC_LANG returns the correct value in the standard configuration.

https://docs.microsoft.com/en-us/cpp/preprocessor/predefined-macros?view=msvc-170