From 0edd15d85e7e7f36d886d01f232ba434c91856de Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dennis=20Gl=C3=A4ser?= <dennis.glaeser@iws.uni-stuttgart.de>
Date: Wed, 27 Sep 2023 19:08:19 +0200
Subject: [PATCH] [experimental][typetraits] add NonVoidOr type helper

---
 dumux/experimental/assembly/cclocalassembler.hh    | 13 ++-----------
 dumux/experimental/assembly/cvfelocalassembler.hh  | 13 ++-----------
 dumux/experimental/common/typetraits/typetraits.hh |  7 +++++++
 3 files changed, 11 insertions(+), 22 deletions(-)

diff --git a/dumux/experimental/assembly/cclocalassembler.hh b/dumux/experimental/assembly/cclocalassembler.hh
index ea58dfcf7d..4b82b8e4d4 100644
--- a/dumux/experimental/assembly/cclocalassembler.hh
+++ b/dumux/experimental/assembly/cclocalassembler.hh
@@ -34,15 +34,6 @@
 
 namespace Dumux::Experimental {
 
-#ifndef DOXYGEN
-namespace Detail::CC {
-
-template<class X, class Y>
-using Impl = std::conditional_t<!std::is_same_v<X, void>, X, Y>;
-
-} // end namespace Detail
-#endif // DOXYGEN
-
 /*!
  * \ingroup Assembly
  * \ingroup CCDiscretization
@@ -194,10 +185,10 @@ class CCLocalAssembler;
 template<class TypeTag, class Assembler, class Implementation>
 class CCLocalAssembler<TypeTag, Assembler, DiffMethod::numeric, Implementation>
 : public CCLocalAssemblerBase<TypeTag, Assembler,
-                              Detail::CC::Impl<Implementation, CCLocalAssembler<TypeTag, Assembler, DiffMethod::numeric, Implementation>>>
+                              NonVoidOr<CCLocalAssembler<TypeTag, Assembler, DiffMethod::numeric, Implementation>, Implementation>>
 {
     using ThisType = CCLocalAssembler<TypeTag, Assembler, DiffMethod::numeric, Implementation>;
-    using ParentType = CCLocalAssemblerBase<TypeTag, Assembler, Detail::CC::Impl<Implementation, ThisType>>;
+    using ParentType = CCLocalAssemblerBase<TypeTag, Assembler, NonVoidOr<ThisType, Implementation>>;
     using Scalar = GetPropType<TypeTag, Properties::Scalar>;
     using NumEqVector = Dumux::NumEqVector<GetPropType<TypeTag, Properties::PrimaryVariables>>;
     using GridGeometry = GetPropType<TypeTag, Properties::GridGeometry>;
diff --git a/dumux/experimental/assembly/cvfelocalassembler.hh b/dumux/experimental/assembly/cvfelocalassembler.hh
index bec9d86816..dcb0bb0b52 100644
--- a/dumux/experimental/assembly/cvfelocalassembler.hh
+++ b/dumux/experimental/assembly/cvfelocalassembler.hh
@@ -37,15 +37,6 @@
 
 namespace Dumux::Experimental {
 
-#ifndef DOXYGEN
-namespace Detail::CVFE {
-
-template<class X, class Y>
-using Impl = std::conditional_t<!std::is_same_v<X, void>, X, Y>;
-
-} // end namespace Detail
-#endif // DOXYGEN
-
 /*!
  * \ingroup Assembly
  * \ingroup CVFEDiscretization
@@ -339,10 +330,10 @@ class CVFELocalAssembler;
 template<class TypeTag, class Assembler, class Implementation>
 class CVFELocalAssembler<TypeTag, Assembler, DiffMethod::numeric, Implementation>
 : public CVFELocalAssemblerBase<TypeTag, Assembler,
-                                Detail::CVFE::Impl<Implementation, CVFELocalAssembler<TypeTag, Assembler, DiffMethod::numeric, Implementation>>>
+                                NonVoidOr<CVFELocalAssembler<TypeTag, Assembler, DiffMethod::numeric, Implementation>, Implementation>>
 {
     using ThisType = CVFELocalAssembler<TypeTag, Assembler, DiffMethod::numeric, Implementation>;
-    using ParentType = CVFELocalAssemblerBase<TypeTag, Assembler, Detail::CVFE::Impl<Implementation, ThisType>>;
+    using ParentType = CVFELocalAssemblerBase<TypeTag, Assembler, NonVoidOr<ThisType, Implementation>>;
     using Scalar = GetPropType<TypeTag, Properties::Scalar>;
     using GridVariables = GetPropType<TypeTag, Properties::GridVariables>;
     using VolumeVariables = GetPropType<TypeTag, Properties::VolumeVariables>;
diff --git a/dumux/experimental/common/typetraits/typetraits.hh b/dumux/experimental/common/typetraits/typetraits.hh
index ad1aad6c4b..e9ab11bd8f 100644
--- a/dumux/experimental/common/typetraits/typetraits.hh
+++ b/dumux/experimental/common/typetraits/typetraits.hh
@@ -22,6 +22,13 @@ namespace Dumux {
 inline constexpr auto noop = [] (auto...) {};
 using Noop = decltype(noop);
 
+/*!
+ * \brief Helper template to select type T if it is not void
+ *        or fall back to the given default type otherwise.
+ */
+template<typename Default, typename T>
+using NonVoidOr = std::conditional_t<!std::is_void_v<T>, T, Default>;
 
 } // end namespace Dumux
+
 #endif
-- 
GitLab