nemequ / hedley

A C/C++ header to help move #ifdefs out of your code
https://nemequ.github.io/hedley/
Creative Commons Zero v1.0 Universal
774 stars 51 forks source link

C++2a-based likely/unlikely/predict... macros #29

Open nemequ opened 5 years ago

nemequ commented 5 years ago

I just pushed some implementations of HEDLEY_LIKELY, HEDLEY_UNLIKELY, HEDLEY_PREDICT, HEDLEY_PREDICT_TRUE, and HEDLEY_PREDICT_FALSE to a new wip/c++2a branch (commit ID f57289ea9774401c1f872bacd1067564b1011226). They work as expected on GCC 9 (AFAIK the only compiler which supports the [[likely]]/[[unlikely]] attributes, but I'd like to do a bit more testing before including them in a release.

The good news is that Microsoft generally implements new C++ features (unlike C), so the next release of Visual Studio will probably support the required attributes, meaning we may actually get a working implementation on MSVC. Most other compilers already support __builtin_expect, so MSVC is where this should be important.

travisdowns commented 5 years ago

Nice to see this finally getting some love in the standard.