c++type-traitsvalarray

Why is std::valarray non-arithmetic?


I've noticed that std::is_arithmetic<std::valarray<float>> evaluates to false. Isn't the entire point of valarrays to facilitate overloading scalar code to 'auto-vectorise' without resorting to boost etc. ?

Why does it not inherit the arithmetic properties of its templated type?

My question isn't necessarily a problem, but rather a fundamental misunderstanding on my part as I must be missing some philosophical insight if this is indeed intended.


Solution

  • std::is_arithmetic tells you if the type is a fundamental numeric type like an integer or a float. It does not work for classes. And you are not allowed to specialize it yourself, so you can't "fix" it, but you can write your own type traits that do whatever you want.

    By the way, std::is_array<std::array<int, 5>> is false too!