diff --git a/riegeli/base/BUILD b/riegeli/base/BUILD index 2b208b72..e7e3fb3c 100644 --- a/riegeli/base/BUILD +++ b/riegeli/base/BUILD @@ -394,7 +394,6 @@ cc_library( ":external_ref_support", ":initializer", ":new_aligned", - ":reset", "@com_google_absl//absl/base:core_headers", "@com_google_absl//absl/base:nullability", "@com_google_absl//absl/meta:type_traits", diff --git a/riegeli/base/intrusive_shared_ptr.h b/riegeli/base/intrusive_shared_ptr.h index 84c4cd01..64799ea6 100644 --- a/riegeli/base/intrusive_shared_ptr.h +++ b/riegeli/base/intrusive_shared_ptr.h @@ -30,7 +30,6 @@ #include "riegeli/base/external_ref_support.h" // IWYU pragma: keep #include "riegeli/base/initializer.h" #include "riegeli/base/ownership.h" -#include "riegeli/base/reset.h" namespace riegeli { @@ -334,33 +333,26 @@ class if (ptr != nullptr) ptr->Unref(); } - template < - typename DependentT = T, - std::enable_if_t< - absl::conjunction< - intrusive_shared_ptr_internal::HasHasUniqueOwner, - absl::disjunction< - absl::negation>, - std::is_final>, - std::is_move_assignable>::value, - int> = 0> + template + struct IsAssignable + : absl::conjunction< + intrusive_shared_ptr_internal::HasHasUniqueOwner, + absl::disjunction< + absl::negation>, + std::is_final>, + std::is_move_assignable> {}; + + template ::value, int> = 0> void ResetImpl(Initializer value) { if (IsUnique()) { - riegeli::Reset(*ptr_, std::move(value)); + *ptr_ = std::move(value); return; } Unref(std::exchange(ptr_, std::move(value).MakeUnique().release())); } - template < - typename DependentT = T, - std::enable_if_t< - absl::disjunction< - absl::negation< - intrusive_shared_ptr_internal::HasHasUniqueOwner>, - absl::conjunction, - absl::negation>>, - absl::negation>>::value, - int> = 0> + template ::value, int> = 0> void ResetImpl(Initializer value) { Unref(std::exchange(ptr_, std::move(value).MakeUnique().release())); } diff --git a/riegeli/base/maker.h b/riegeli/base/maker.h index 21d466ac..9f27cd93 100644 --- a/riegeli/base/maker.h +++ b/riegeli/base/maker.h @@ -160,8 +160,7 @@ class MakerType : public ConditionallyAssignable>, - std::is_constructible, - std::is_move_assignable>::value, + SupportsReset>::value, int> = 0> friend void RiegeliReset(T& dest, MakerType&& src) { absl::apply( @@ -173,8 +172,7 @@ class MakerType : public ConditionallyAssignable>, - std::is_constructible, - std::is_move_assignable>::value, + SupportsReset>::value, int> = 0> friend void RiegeliReset(T& dest, const MakerType& src) { absl::apply([&](const Args&... args) { riegeli::Reset(dest, args...); }, @@ -339,8 +337,7 @@ class MakerTypeFor : public ConditionallyAssignable>, - std::is_constructible, - std::is_move_assignable>::value, + SupportsReset>::value, int> = 0> friend void RiegeliReset(T& dest, MakerTypeFor&& src) { riegeli::Reset(dest, std::move(src).maker()); @@ -349,8 +346,7 @@ class MakerTypeFor : public ConditionallyAssignable>, - std::is_constructible, - std::is_move_assignable>::value, + SupportsReset>::value, int> = 0> friend void RiegeliReset(T& dest, const MakerTypeFor& src) { riegeli::Reset(dest, src.maker()); diff --git a/riegeli/base/reset.h b/riegeli/base/reset.h index 89648474..f2b5984c 100644 --- a/riegeli/base/reset.h +++ b/riegeli/base/reset.h @@ -111,6 +111,16 @@ struct HasAssignment : HasAssignmentImpl {}; } // namespace reset_internal +// `SupportsReset::value` is true if `riegeli::Reset(T&, Args...)` +// is supported. +template +struct SupportsReset + : absl::disjunction, + reset_internal::HasReset, + reset_internal::HasAssignment, + absl::conjunction, + std::is_move_assignable>> {}; + template ::value, int> = 0> diff --git a/riegeli/base/shared_ptr.h b/riegeli/base/shared_ptr.h index 312fa1d3..1117c03c 100644 --- a/riegeli/base/shared_ptr.h +++ b/riegeli/base/shared_ptr.h @@ -33,7 +33,6 @@ #include "riegeli/base/initializer.h" #include "riegeli/base/new_aligned.h" #include "riegeli/base/ref_count.h" -#include "riegeli/base/reset.h" namespace riegeli { @@ -413,7 +412,7 @@ class std::enable_if_t::value, int> = 0> void ResetImpl(Initializer value) { if (IsUnique()) { - riegeli::Reset(*ptr_, std::move(value)); + *ptr_ = std::move(value); return; } Unref(std::exchange(ptr_, New(std::move(value))));