]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Ensure that Lazy functions are called with a callable argument. 16267/head
authorWolfgang Bangerth <bangerth@colostate.edu>
Tue, 14 Nov 2023 00:23:02 +0000 (17:23 -0700)
committerWolfgang Bangerth <bangerth@colostate.edu>
Tue, 14 Nov 2023 00:23:02 +0000 (17:23 -0700)
include/deal.II/base/lazy.h

index 450230cd0a5469047ef578f234eb8dc9352d6e53..2375e86813415f9ec477f3bec04d6c97ab2ae593 100644 (file)
@@ -26,6 +26,8 @@
 #include <atomic>
 #include <mutex>
 #include <optional>
+#include <type_traits>
+
 
 DEAL_II_NAMESPACE_OPEN
 
@@ -136,7 +138,8 @@ public:
    */
   template <typename Callable>
   void
-  ensure_initialized(const Callable &creator) const;
+  ensure_initialized(const Callable &creator) const
+    DEAL_II_CXX20_REQUIRES((std::is_invocable_r_v<T, Callable>));
 
 
   /**
@@ -184,7 +187,8 @@ public:
    */
   template <typename Callable>
   const T &
-  value_or_initialize(const Callable &creator) const;
+  value_or_initialize(const Callable &creator) const
+    DEAL_II_CXX20_REQUIRES((std::is_invocable_r_v<T, Callable>));
 
 
   /**
@@ -192,7 +196,8 @@ public:
    */
   template <typename Callable>
   DEAL_II_ALWAYS_INLINE inline T &
-  value_or_initialize(const Callable &creator);
+  value_or_initialize(const Callable &creator)
+    DEAL_II_CXX20_REQUIRES((std::is_invocable_r_v<T, Callable>));
 
 
   /**
@@ -284,6 +289,7 @@ template <typename T>
 template <typename Callable>
 inline DEAL_II_ALWAYS_INLINE void
 Lazy<T>::ensure_initialized(const Callable &creator) const
+  DEAL_II_CXX20_REQUIRES((std::is_invocable_r_v<T, Callable>))
 {
   //
   // Use Schmidt's double checking [1] for checking and initializing the
@@ -387,6 +393,7 @@ template <typename T>
 template <typename Callable>
 inline DEAL_II_ALWAYS_INLINE const T &
 Lazy<T>::value_or_initialize(const Callable &creator) const
+  DEAL_II_CXX20_REQUIRES((std::is_invocable_r_v<T, Callable>))
 {
   ensure_initialized(creator);
   return object.value();
@@ -397,6 +404,7 @@ template <typename T>
 template <typename Callable>
 inline DEAL_II_ALWAYS_INLINE T &
 Lazy<T>::value_or_initialize(const Callable &creator)
+  DEAL_II_CXX20_REQUIRES((std::is_invocable_r_v<T, Callable>))
 {
   ensure_initialized(creator);
   return object.value();

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.