From feaf383339beff509091995dba0c3dfc345a2677 Mon Sep 17 00:00:00 2001
From: Timo Koch <timo.koch@iws.uni-stuttgart.de>
Date: Mon, 12 Jul 2021 12:15:28 +0200
Subject: [PATCH] [std/typetraits] Deprecate Dune::Std::to_false/true_type. Use
 Dune::AlwaysFalse/True

---
 CHANGELOG.md                              | 5 +++++
 dune/common/documentation.hh              | 2 +-
 dune/common/simd/test.hh                  | 2 +-
 dune/common/simd/test/looptest.cc.in      | 8 ++++----
 dune/common/simd/test/standardtest.cc.in  | 3 ++-
 dune/common/std/type_traits.hh            | 8 ++++----
 dune/common/test/debugalignsimdtest.cc.in | 3 ++-
 dune/common/tupleutility.hh               | 4 ++--
 8 files changed, 21 insertions(+), 14 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index d1a2587a4..027f3106d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,6 +11,11 @@
 - Deprecate fallback implementations `Dune::Std::apply`, `Dune::Std::bool_constant`, and
   `Dune::Std::make_array` in favor of std c++ implementations.
 
+- Deprecate type traits `Dune::Std::to_false_type`, `Dune::Std::to_true_type`.
+  `Dune::AlwaysFalse` and `Dune::AlwaysTrue` (from header `dune/common/typetraits.hh`)
+  now inherit from `std::true_type` and `std::false_type` and are therefore
+  exact replacements for these two type traits.
+
 - Remove c++ feature tests in cmake for existing c++-17 standards. Add default
   defines for `DUNE_HAVE_CXX_BOOL_CONSTANT`, `DUNE_HAVE_CXX_EXPERIMENTAL_BOOL_CONSTANT`,
   `DUNE_HAVE_HEADER_EXPERIMENTAL_TYPE_TRAITS`, `DUNE_HAVE_CXX_APPLY`,
diff --git a/dune/common/documentation.hh b/dune/common/documentation.hh
index 06e6deceb..934edfc89 100644
--- a/dune/common/documentation.hh
+++ b/dune/common/documentation.hh
@@ -19,7 +19,7 @@ namespace Dune {
    * // Traits class that determines some property for some other type T
    * template<class T>
    * class SomeTraits {
-   *   static_assert(Std::to_false_type<T>::value,
+   *   static_assert(Dune::AlwaysFalse<T>::value,
    *                 "Sorry, SomeTraits must be specialized for all types");
    * public:
    *   // The type of some property of T
diff --git a/dune/common/simd/test.hh b/dune/common/simd/test.hh
index fd3e729b5..eb22cc191 100644
--- a/dune/common/simd/test.hh
+++ b/dune/common/simd/test.hh
@@ -1845,7 +1845,7 @@ namespace Dune {
        */
       template<class V, class Rebinds,
                template<class> class RebindPrune = IsLoop,
-               template<class> class RebindAccept = Std::to_true_type>
+               template<class> class RebindAccept = Dune::AlwaysTrue>
       void check() {
         // check whether the test for this type already started
         if(seen_.emplace(typeid (V)).second == false)
diff --git a/dune/common/simd/test/looptest.cc.in b/dune/common/simd/test/looptest.cc.in
index 3eaa1b125..e84de3467 100644
--- a/dune/common/simd/test/looptest.cc.in
+++ b/dune/common/simd/test/looptest.cc.in
@@ -10,7 +10,7 @@
 #include <dune/common/simd/loop.hh>
 #include <dune/common/simd/test.hh>
 #include <dune/common/simd/test/looptest.hh>
-#include <dune/common/std/type_traits.hh>
+#include <dune/common/typetraits.hh>
 
 template<class> struct RebindAccept : std::false_type {};
 #cmake @template@
@@ -32,11 +32,11 @@ int main()
 
 #cmake @template@
   test.check<Dune::LoopSIMD<@SCALAR@, 5>,
-             Rebinds, Dune::Std::to_false_type, RebindAccept>();
+             Rebinds, Dune::AlwaysFalse, RebindAccept>();
   test.check<Dune::LoopSIMD<@SCALAR@, 5, 64>,
-             Rebinds, Dune::Std::to_false_type, RebindAccept>();
+             Rebinds, Dune::AlwaysFalse, RebindAccept>();
   test.check<Dune::LoopSIMD<Dune::LoopSIMD<@SCALAR@, 2>, 5>,
-             Rebinds, Dune::Std::to_false_type, RebindAccept>();
+             Rebinds, Dune::AlwaysFalse, RebindAccept>();
 #cmake @endtemplate@
 
   return test.good() ? EXIT_SUCCESS : EXIT_FAILURE;
diff --git a/dune/common/simd/test/standardtest.cc.in b/dune/common/simd/test/standardtest.cc.in
index 6b5821b1a..5e540d48a 100644
--- a/dune/common/simd/test/standardtest.cc.in
+++ b/dune/common/simd/test/standardtest.cc.in
@@ -7,6 +7,7 @@
 #include <cstdlib>
 #include <type_traits>
 
+#include <dune/common/typetraits.hh>
 #include <dune/common/simd/test.hh>
 #include <dune/common/simd/test/standardtest.hh>
 
@@ -26,7 +27,7 @@ int main()
   Dune::Simd::UnitTest test;
 
 #cmake @template@
-  test.check<@SCALAR@, Rebinds, Dune::Std::to_false_type, RebindAccept>();
+  test.check<@SCALAR@, Rebinds, Dune::AlwaysFalse, RebindAccept>();
 #cmake @endtemplate@
 
   return test.good() ? EXIT_SUCCESS : EXIT_FAILURE;
diff --git a/dune/common/std/type_traits.hh b/dune/common/std/type_traits.hh
index 60b82b79f..e77e946eb 100644
--- a/dune/common/std/type_traits.hh
+++ b/dune/common/std/type_traits.hh
@@ -33,7 +33,7 @@ namespace Std
   /** \class to_false_type
    *
    *  \brief template mapping a type to <tt>std::false_type</tt>
-   *
+   *  \deprecated Use Dune::AlwaysFalse (from dune/common/typetraits.hh) instead
    *  \tparam T Some type
    *
    *  Suppose you have a template class. You want to document the required
@@ -76,7 +76,7 @@ namespace Std
    * \ingroup CxxUtilities
    */
   template< typename T >
-  struct to_false_type : public std::false_type {};
+  struct [[deprecated("Will be removed after release 2.8. Use Dune::AlwaysFalse (from dune/common/typetraits.hh)")]] to_false_type : public std::false_type {};
 
 
 
@@ -86,7 +86,7 @@ namespace Std
   /** \class to_true_type
    *
    *  \brief template mapping a type to <tt>std::true_type</tt>
-   *
+   *  \deprecated Use Dune::AlwaysFalse (from dune/common/typetraits.hh) instead
    *  \tparam T Some type
    *
    *  \note This class exists mostly for consistency with to_false_type.
@@ -94,7 +94,7 @@ namespace Std
    * \ingroup CxxUtilities
    */
   template< typename T >
-  struct to_true_type : public std::true_type {};
+  struct [[deprecated("Will be removed after release 2.8. Use Dune::AlwaysTrue (from dune/common/typetraits.hh)")]] to_true_type : public std::true_type {};
 
 
   /// A helper alias template std::bool_constant imported into the namespace Dune::Std
diff --git a/dune/common/test/debugalignsimdtest.cc.in b/dune/common/test/debugalignsimdtest.cc.in
index e96ae2507..2937a2536 100644
--- a/dune/common/test/debugalignsimdtest.cc.in
+++ b/dune/common/test/debugalignsimdtest.cc.in
@@ -5,6 +5,7 @@
 #include <cstdlib>
 #include <type_traits>
 
+#include <dune/common/typetraits.hh>
 #include <dune/common/debugalign.hh>
 #include <dune/common/parallel/mpihelper.hh>
 #include <dune/common/simd/test.hh>
@@ -30,7 +31,7 @@ int main(int argc, char **argv)
 
 #cmake @template@
   test.check<Dune::AlignedNumber<@SCALAR@>,
-             Rebinds, Dune::Std::to_false_type, RebindAccept>();
+             Rebinds, Dune::AlwaysFalse, RebindAccept>();
 #cmake @endtemplate@
 
   return test.good() ? EXIT_SUCCESS : EXIT_FAILURE;
diff --git a/dune/common/tupleutility.hh b/dune/common/tupleutility.hh
index 4907e3628..f49240db5 100644
--- a/dune/common/tupleutility.hh
+++ b/dune/common/tupleutility.hh
@@ -10,7 +10,7 @@
 #include <utility>
 
 #include <dune/common/hybridutilities.hh>
-#include <dune/common/std/type_traits.hh>
+#include <dune/common/typetraits.hh>
 
 namespace Dune {
 
@@ -424,7 +424,7 @@ namespace Dune {
   template<class Tuple, template<class> class Predicate, std::size_t size>
   class FirstPredicateIndex<Tuple, Predicate, size, size>
   {
-    static_assert(Std::to_false_type<Tuple>::value, "None of the std::tuple element "
+    static_assert(AlwaysFalse<Tuple>::value, "None of the std::tuple element "
                        "types matches the predicate!");
   };
 #endif // !DOXYGEN
-- 
GitLab