MultiTypeBlockVector: Use std::common_type for field_type
This change should make the field_type
more meaningful. As far as I see it should not break any application.
If this is fine I'll add something similar to `MultiTypeBlockMatrix".
Merge request reports
Activity
- Resolved by Patrick Jaap
mentioned in commit patrick.jaap/dune-istl@baca4efc
added 1 commit
- baca4efc - Replace std::vector by Dune::DynamicVector in a unit test
- Resolved by Patrick Jaap
I like the
common_type
approach, but I'm wondering about the exact semantics. We should document how it works.What is the
field_type
of e.g.MultiTypeBlockVector<DynamicVector<FieldVector<double,3>>,DynamicVector<FieldVector<float,1>>>
?Do we get a meaningful type? If not, we should ensure that we get a static error.
mentioned in commit patrick.jaap/dune-istl@86dda7dc
@christi I added a test for some simple
double
andfloat
combinations.mentioned in commit patrick.jaap/dune-istl@876a5440
added 7 commits
-
86dda7dc...576775c4 - 4 commits from branch
core:master
- 5e4d9dbc - MultiTypeBlockVector: Use std::common_type for field_type
- 876a5440 - Replace std::vector by Dune::DynamicVector in a unit test
- fa4cbd1d - MultiTypeBlockVector: Add static error message if no std::common_type exists
Toggle commit list-
86dda7dc...576775c4 - 4 commits from branch
added 1 commit
- 00674d8e - MultiTypeBlockVector: Add static error message if no std::common_type exists
added 1 commit
- de10df78 - MultiTypeBlockVector: Add static error message if no std::common_type exists
- Resolved by Patrick Jaap
- Resolved by Patrick Jaap
- Resolved by Patrick Jaap
added 1 commit
- fb8d4fd7 - MultiTypeBlockVector: Add static error message if no std::common_type exists
- Resolved by Patrick Jaap
Thanks @carsten.graeser for the hints. I included all of them in the current update.
109 * for an empty tuple. 110 * We have to wrap `double` by `std::decay` in order to call `::type` in the end, 111 * since an empty `std::common_type` has no type member and the construction of 112 * `std::conditional_t`would fail. 113 * We use the helper struct `Impl_::CommonTypeOrNoCommonType` to set the dummy `NoCommonType` 114 * for a more readable error message in case of a missing `std::common_type` implementation. 80 115 */ 81 typedef double field_type; 116 using field_type = typename std::conditional_t< sizeof...(Args) == 0, 117 std::decay<double>, // in C++20 std::type_identity is preferrable 118 Impl_::CommonTypeOrNoCommonType< typename std::decay_t<Args>::field_type... > 119 >::type; 120 121 // make sure that we have an std::common_type: using an assertion produces a more readable error message 122 // than a compiler template instatiation error 123 static_assert ( not std::is_same_v<field_type, Impl_::NoCommonType>, If you trigger a
static_assertion
anyway, I don't see any reason to defineNoCommonType
andCommonTypeEnabled
. This could be replaced bystatic_assert(Dune::is_detected_v<std::common_type_t, T...>, ...);
If you want to represent that there is no common type, you can use
using field_type = Dune::detected_t<std::common_type_t, T...>;
which is either
std::common_type_t<T...>
orDune::nonesuch
.Both rely on (Dune-implementation of) the
detected
mechanism from TSv2, and are thus probably more idiomatic.Edited by Carsten Gräserchanged this line in version 8 of the diff
added 1 commit
- b552a3ac - MultiTypeBlockVector: Add static error message if no std::common_type exists
added 1 commit
- cb6aea69 - MultiTypeBlockVector: adapt FieldTraits to the new field_type