Skip to content

Add a collection of useful concept definitions

Simon Praetorius requested to merge feature/concepts into master

Summary

In this MR some c++20 concepts are added to the dune-common module to be used in downstream modules if C++20 compiler is available. These concepts are not provided by the c++ standard library but useful, e.g., in the definition of concepts for dune-grid. All concepts are tested for types from c++ standard library but also from the dune-common module.

Concepts

  • BooleanTestable: anything that can be converted to bool and allows negation which also is convertible to bool. Thus, these types can be used in if-then-else conditions. Examples include bool, int, int*, std::vector<bool>::reference
    • Instead of requiring that a method like empty() returns exactly bool, it can be anything behaving like a boolean.
  • Integer: a restriction of integral types to those that are not bool or char types.
    • Possibility to constrain integer return types, e.g., of size() methods
  • Hashable: a type that can be hashed using std::hash utility and thus can be used in hash maps directly.
    • Can be used in the concept definition of an IdType in IdSets
  • Container and RandomAccessContainer: types following the stl definition of containers. RandomAccess here means that the iterators are random-access iterators and that we have an operator[] in the container.
    • Can be used in multiple places where generic containers are required, but it doesn't matter whether it is a std::array or std::vector or ReservedVector or...
    • Example: The definition of IndexSet::Types in the dune-grid interface

TODO

  • Add documentation of the concepts
  • Add changelog entry
Edited by Simon Praetorius

Merge request reports