From: Wolfgang Bangerth Date: Sun, 26 Nov 2023 16:20:04 +0000 (-0700) Subject: Annotate Lazy with requirements on T. X-Git-Tag: relicensing~277^2~1 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4fa72298a75702f088a4cc5e7b4260ffac45010e;p=dealii.git Annotate Lazy with requirements on T. --- diff --git a/include/deal.II/base/lazy.h b/include/deal.II/base/lazy.h index 01653affbf..a26dea1d62 100644 --- a/include/deal.II/base/lazy.h +++ b/include/deal.II/base/lazy.h @@ -76,8 +76,13 @@ DEAL_II_NAMESPACE_OPEN * Lazy> prolongation_matrix; * }; * ``` + * + * @dealiiConceptRequires{std::is_constructible_v && + std::is_assignable_v} */ template +DEAL_II_CXX20_REQUIRES((std::is_constructible_v && + std::is_assignable_v)) class Lazy { public: @@ -241,12 +246,16 @@ private: template +DEAL_II_CXX20_REQUIRES((std::is_constructible_v && + std::is_assignable_v)) inline Lazy::Lazy() : object_is_initialized(false) {} template +DEAL_II_CXX20_REQUIRES((std::is_constructible_v && + std::is_assignable_v)) inline Lazy::Lazy(const Lazy &other) : object(other.object) { @@ -255,6 +264,8 @@ inline Lazy::Lazy(const Lazy &other) template +DEAL_II_CXX20_REQUIRES((std::is_constructible_v && + std::is_assignable_v)) inline Lazy::Lazy(Lazy &&other) noexcept : object(other.object) { @@ -263,8 +274,9 @@ inline Lazy::Lazy(Lazy &&other) noexcept template -inline Lazy & -Lazy::operator=(const Lazy &other) +DEAL_II_CXX20_REQUIRES((std::is_constructible_v && + std::is_assignable_v)) +inline Lazy &Lazy::operator=(const Lazy &other) { object = other.object; object_is_initialized.store(other.object_is_initialized.load()); @@ -273,8 +285,9 @@ Lazy::operator=(const Lazy &other) template -inline Lazy & -Lazy::operator=(Lazy &&other) noexcept +DEAL_II_CXX20_REQUIRES((std::is_constructible_v && + std::is_assignable_v)) +inline Lazy &Lazy::operator=(Lazy &&other) noexcept { object = other.object; object_is_initialized.store(other.object_is_initialized.load()); @@ -283,8 +296,9 @@ Lazy::operator=(Lazy &&other) noexcept template -inline void -Lazy::reset() noexcept +DEAL_II_CXX20_REQUIRES((std::is_constructible_v && + std::is_assignable_v)) +inline void Lazy::reset() noexcept { object_is_initialized.store(false); object.reset(); @@ -292,9 +306,11 @@ Lazy::reset() noexcept template +DEAL_II_CXX20_REQUIRES((std::is_constructible_v && + std::is_assignable_v)) template -inline DEAL_II_ALWAYS_INLINE void -Lazy::ensure_initialized(const Callable &creator) const +inline DEAL_II_ALWAYS_INLINE + void Lazy::ensure_initialized(const Callable &creator) const DEAL_II_CXX20_REQUIRES((std::is_invocable_r_v)) { // @@ -354,8 +370,9 @@ Lazy::ensure_initialized(const Callable &creator) const template -inline DEAL_II_ALWAYS_INLINE bool -Lazy::has_value() const +DEAL_II_CXX20_REQUIRES((std::is_constructible_v && + std::is_assignable_v)) +inline DEAL_II_ALWAYS_INLINE bool Lazy::has_value() const { // // In principle it would be sufficient to solely check the atomic @@ -368,8 +385,9 @@ Lazy::has_value() const template -inline DEAL_II_ALWAYS_INLINE const T & -Lazy::value() const +DEAL_II_CXX20_REQUIRES((std::is_constructible_v && + std::is_assignable_v)) +inline DEAL_II_ALWAYS_INLINE const T &Lazy::value() const { Assert( object_is_initialized && object.has_value(), @@ -382,8 +400,9 @@ Lazy::value() const template -inline DEAL_II_ALWAYS_INLINE T & -Lazy::value() +DEAL_II_CXX20_REQUIRES((std::is_constructible_v && + std::is_assignable_v)) +inline DEAL_II_ALWAYS_INLINE T &Lazy::value() { Assert( object_is_initialized && object.has_value(), @@ -396,9 +415,11 @@ Lazy::value() template +DEAL_II_CXX20_REQUIRES((std::is_constructible_v && + std::is_assignable_v)) template -inline DEAL_II_ALWAYS_INLINE const T & -Lazy::value_or_initialize(const Callable &creator) const +inline DEAL_II_ALWAYS_INLINE const T &Lazy::value_or_initialize( + const Callable &creator) const DEAL_II_CXX20_REQUIRES((std::is_invocable_r_v)) { ensure_initialized(creator); @@ -407,9 +428,11 @@ Lazy::value_or_initialize(const Callable &creator) const template +DEAL_II_CXX20_REQUIRES((std::is_constructible_v && + std::is_assignable_v)) template -inline DEAL_II_ALWAYS_INLINE T & -Lazy::value_or_initialize(const Callable &creator) +inline DEAL_II_ALWAYS_INLINE T &Lazy::value_or_initialize( + const Callable &creator) DEAL_II_CXX20_REQUIRES((std::is_invocable_r_v)) { ensure_initialized(creator); @@ -418,8 +441,9 @@ Lazy::value_or_initialize(const Callable &creator) template -std::size_t -Lazy::memory_consumption() const +DEAL_II_CXX20_REQUIRES((std::is_constructible_v && + std::is_assignable_v)) +std::size_t Lazy::memory_consumption() const { return MemoryConsumption::memory_consumption(object) + // sizeof(*this) - sizeof(object);