Add support for C++20 concepts
- Some compilers already have support for concepts, hence, it would be a good idea to provide some basic compiler checks to enable it through DUNE.
- Additionally, since some compilers do not provide the concepts library (e.g. clang), some concepts are provided as a fallback implementation.
In particular, this would enable one of my two Grid
concept implementations for those using C++20.
I tested this with clang-11
. Pipelines for supported compilers seem to be passing.
Usage: dune-grid!377 (merged)
Merge request reports
Activity
mentioned in merge request dune-grid!377 (merged)
added 100 commits
-
bddcdb47...ab73b25c - 99 commits from branch
master
- f3ce2652 - Add check for concepts and fallback implementation of some concepts frim std
-
bddcdb47...ab73b25c - 99 commits from branch
- dune/common/std/concepts.hh 0 → 100644
1 #ifndef DUNE_COMMON_STD_CONCEPTS_HH 2 #define DUNE_COMMON_STD_CONCEPTS_HH 3 4 // This header assumes that concepts are availalbe 5 6 #if __cpp_lib_concepts >= 201806L changed this line in version 3 of the diff
Today, checking the libc++ 11 and 12, I realized that the
<concepts>
header is defined but is almost empty. Thus, the check @simon.praetorius proposed should be avoided. We should indeed check for the feature macro tests. Notice that this also holds for !953 (closed) and dune-grid!377 (merged)
- dune/common/std/concepts.hh 0 → 100644
16 concept name = std::name<T>; 17 18 #define DUNE_CONCEPT_ALIAS_2(name) \ 19 template<class T0, class T1> \ 20 concept name = std::name<T0,T1>; 21 22 #define DUNE_CONCEPT_ALIAS_1_VAR(name) \ 23 template<class T, class... Args> \ 24 concept name = std::name<T,Args...>; 25 26 DUNE_CONCEPT_ALIAS_2(convertible_to) 27 DUNE_CONCEPT_ALIAS_1(destructible) 28 DUNE_CONCEPT_ALIAS_1_VAR(constructible_from) 29 DUNE_CONCEPT_ALIAS_1(default_initializable) 30 DUNE_CONCEPT_ALIAS_1(move_constructible) 31 DUNE_CONCEPT_ALIAS_1(copy_constructible) Good point, but I guess it depends on how many concepts you expect to put here
. The ranges library uses quite an amount of them for example, then handwriting them would be tedious.Btw, I just did this MR in order to share how I got the
Grid
concept implementation to work. So my intention is not that this file grows to contain all the concepts in the standard library.
- Resolved by Santiago Ospina De Los Ríos
- Resolved by Santiago Ospina De Los Ríos
mentioned in merge request !953 (closed)
Closing as this got outdated and not so relevant. See https://gitlab.dune-project.org/santiago.ospina/dune-concepts for a more up to date version.