Skip to content
Snippets Groups Projects

Add IsNumber trait, extending std::is_arithmetic

Merged Elias Pipping requested to merge pipping/dune-common:feature/isnumber-trait into master

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

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
  • Elias Pipping mentioned in merge request !52 (merged)

    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 with std::is_scalar which is a different thing
    • IsArithmetic would highlight the relation to std::is_arithmetic which almost does what we want, but is not extensible and does not cover std::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 like IsNumber even more.

  • Furthermore some documentation would be nice.

  • Author Developer

    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 to HasNaN or HasNan with the old name as a deprecated alias...

  • Author Developer

    I've now pushed a switch to IsNumber with a capital I. But gitlab was down while I pushed and so it still hasn't picked up the change.

  • Elias Pipping Changed title: Add isNumber trait, extending std::is_arithmeticAdd IsNumber trait, extending std::is_arithmetic

    Changed title: Add isNumber trait, extending std::is_arithmeticAdd IsNumber trait, extending std::is_arithmetic

  • Carsten Gräser mentioned in commit 9bf86305

    mentioned in commit 9bf86305

  • Carsten Gräser Status changed to merged

    Status changed to merged

  • Carsten Gräser Mentioned in commit 9bf86305

    Mentioned in commit 9bf86305

Please register or sign in to reply
Loading