Add IsNumber trait, extending std::is_arithmetic
Since it's very difficult to make progress on !52 (merged), I'll start to break it up into smaller, less controversial changes. This is the first piece that I'd also like to use in other places. An IsNumber
trait allows us to determine when we've hit the bottom in a recursion without a blocklevel
and things like FieldVector<ctype, 1>
.
IsNumber
is currently true for: floating point types, gmp fields, and such types wrapped in std::complex
.
Merge request reports
Activity
mentioned in merge request !52 (merged)
I like this proposal. Unfortunately @pipping missed one of the main arguments why this is desperately needed: If you want to implement algorithms on nested containers you often need to terminate a recursion in some way. The current istl philosophy is, to determine such things by the blocklevel. However, for heterogeneous containers there is in general no well-defined blocklevel, because this level can be different for different children. As a remedy, such a type trait could help to mark the scalar at the recursion end. This could also be achieved by checking if there is another
operator[]
. But compared to the type trait this is much more clumsy.A note regarding the naming: While
isNumber
is quite generic, other natural options would be dangerous:-
IsScalar
may lead to confusion withstd::is_scalar
which is a different thing -
IsArithmetic
would highlight the relation tostd::is_arithmetic
which almost does what we want, but is not extensible and does not coverstd::complex
which is again misleading -
IsField
is misleading, because those types don't store a field but its elements.
That said, I like
isNumber
but in view of our naming convention I'd likeIsNumber
even more.-
Oh, true. Since it's a trait, it's a class and should thus be upper-cased. I somehow overlooked the uppercase 'I' when you suggested the name.
I'm not quite sure if there's anything non-trivial to write documentation about here, though (as in: when
IsNumber
is true) - or would you like the documentation to answer the question "whydo we need such a thing?" (which would end up being a copy-and-paste of what you said above)? Thanks for repeating that here btw. I should've explicitly mentioned heterogeneous containers indeed.PS: I feel a bit bad for bringing
has_nan
into this world now. Wonder if I should rename it toHasNaN
orHasNan
with the old name as a deprecated alias...mentioned in commit 9bf86305
Mentioned in commit 9bf86305