2

Is there a way to determine whether a variable is of an arithmetic type or not?

  • arithmetic: integer, floating point numbers, boolean values
  • not arithmetic: pointers, references; e.g. strings, and probably all other implementation- and user-defined types. However if someone for some reason defines typedef int myInt myInt should be considered arithmetic as well (because it is!)

In a normal C++ program I could use std::is_arithmetic<T>::value, where T is the type I need to check, but this doesn't seem to work in the Arduino environment. (Am I wrong? If it works, could someone please tell me how to use it?)

I imagine I could make a list of allowed types, e.g. as described in this answer to a similar question (I'm referring to the second option, the Alternative). But given that I don't need to exactly know the type of T I was wondering whether there is a more elegant and flexible solution...

noearchimede
  • 482
  • 2
  • 7
  • 19

1 Answers1

1

Is there a way to determine whether a variable is of an arithmetic type or not?

no. end of the day, those are just bit pieces and it only makes sense to the computer with the right context. Another way to put it, the same bit pieces can and will mean different things under different situations.

dannyf
  • 2,813
  • 11
  • 13