Open bob-kerner opened 3 weeks ago
I thought I'd contribute a tiny snippet of code to constrain the integer values used for template specialization to powers of two using the new c++20 requires feature.
requires
#include <concepts> constexpr bool is_power_of_two(std::integral auto value) { return (value > 0) && ((value & (value - 1)) == 0); } template<std::integral auto i> requires (is_power_of_two(i)) struct Foo{ };
Hi. Many thanks for this snippet. That is a neat test for whether an integer is a power of two - haven't seen it before.
I thought I'd contribute a tiny snippet of code to constrain the integer values used for template specialization to powers of two using the new c++20
requires
feature.