Background: I am trying to repurpose some C++ code written for GCC in a MSVC project. I have been trying to refactor code to make it compatible with MSVC compiler.
Simplified, one of the functions originally was this:
[[nodiscard]] constexpr int count() const noexcept {
return __builtin_popcountll(mask);//gcc-specific function
}
Where mask is a 64-bit member variable. The obvious conversion to MSVC is:
[[nodiscard]] constexpr int count() const noexcept {
return __popcnt64(mask); // MSVC replacement
}
However, it doesn't compile because __popcnt64 in not allowed in a constexpr function.
I am using C++17, and I would prefer to avoid having to switch to C++20 if possible.
Is there a way to make it work?