I am not as good with my powers of two as I should be so I thought maybe I could #define
something.
Unfortunately I am very inexperienced when it comes to preprocessor directives and I couldn't figure out how to do things like for loops. I looked at:
But neither of them have examples of for loops. All I want is to be able to write something like pwrtwo(5)
instead of using a calculator to figure out that 25 is 32.
Why not do it right and use a function? This even allows us to generate the result at compile time using the powerfull constexpr!
template <class T>
constexpr T pwrtwo(T exponent) {
return (T(1) << exponent);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With