Quick question (Theory really). I have a variable that its type alternates depending on a value, for example:
8, 16, 24, 32
And I define this by doing, for example:
uint8_t = 10; // example
But, at the minute I’m switching the “number” and repeating the code but declaring the integer value differently. Which, as you can tell, is a lot of wasteful code and I want to code more effectively.
I’m wondering if It’s possible to have template that assigns the variable depending on the value? (If that makes sense)..
if value == 8
uint8_t = foo;
elseif value == 16
uint32_t
...
Any ideas or suggestions? Thank you 🙂
Like so:
The template argument has to be a constant expression.