diff --git a/riegeli/base/BUILD b/riegeli/base/BUILD index 0505004b..6116ecfc 100644 --- a/riegeli/base/BUILD +++ b/riegeli/base/BUILD @@ -260,11 +260,11 @@ cc_library( ) cc_library( - name = "any_dependency", - srcs = ["any_dependency_internal.h"], + name = "any", + srcs = ["any_internal.h"], hdrs = [ - "any_dependency.h", - "any_dependency_initializer.h", + "any.h", + "any_initializer.h", ], deps = [ ":arithmetic", @@ -282,6 +282,18 @@ cc_library( ], ) +cc_library( + name = "any_dependency", + hdrs = [ + "any_dependency.h", + "any_dependency_initializer.h", + ], + deps = [ + ":any", + "@com_google_absl//absl/base:core_headers", + ], +) + cc_library( name = "iterable", hdrs = ["iterable.h"], diff --git a/riegeli/base/any.h b/riegeli/base/any.h new file mode 100644 index 00000000..e6ec6d37 --- /dev/null +++ b/riegeli/base/any.h @@ -0,0 +1,695 @@ +// Copyright 2022 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef RIEGELI_BASE_ANY_H_ +#define RIEGELI_BASE_ANY_H_ + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "absl/base/attributes.h" +#include "absl/base/optimization.h" +#include "absl/meta/type_traits.h" +#include "absl/strings/string_view.h" +#include "riegeli/base/any_initializer.h" +#include "riegeli/base/any_internal.h" +#include "riegeli/base/arithmetic.h" +#include "riegeli/base/assert.h" +#include "riegeli/base/compare.h" +#include "riegeli/base/dependency.h" +#include "riegeli/base/dependency_base.h" +#include "riegeli/base/dependency_manager.h" +#include "riegeli/base/initializer.h" +#include "riegeli/base/memory_estimator.h" +#include "riegeli/base/type_id.h" +#include "riegeli/base/type_traits.h" + +namespace riegeli { + +namespace any_internal { + +// Common base class of `Any` and `AnyRef`. +// +// `ABSL_ATTRIBUTE_TRIVIAL_ABI` is effective if `inline_size == 0`. +template +class +#ifdef ABSL_ATTRIBUTE_TRIVIAL_ABI + ABSL_ATTRIBUTE_TRIVIAL_ABI +#endif + AnyBase : public WithEqual>, + public ConditionallyAbslNullabilityCompatible< + IsComparableAgainstNullptr::value>, + public ConditionallyTrivialAbi { + public: + // Makes `*this` equivalent to a newly constructed `AnyBase`. This avoids + // constructing a temporary `AnyBase` and moving from it. + ABSL_ATTRIBUTE_REINITIALIZES void Reset(); + + // Returns a `Handle` to the `Manager`, or a default `Handle` for an empty + // `AnyBase`. + Handle get() const { return methods_and_handle_.handle; } + + // If `Handle` is `Base*`, `AnyBase` can be used as a smart pointer to + // `Base`, for convenience. + template ::value, int> = 0> + decltype(*std::declval()) operator*() const { + AssertNotNull("Failed precondition of AnyBase::operator*: null handle"); + return *get(); + } + + template ::value, int> = 0> + Handle operator->() const { + AssertNotNull("Failed precondition of AnyBase::operator->: null handle"); + return get(); + } + + // If `Handle` is `Base*`, `AnyBase` can be compared against `nullptr`. + template ::value, + int> = 0> + friend bool operator==(const AnyBase& a, std::nullptr_t) { + return a.get() == nullptr; + } + + // If `true`, the `AnyBase` owns the dependent object, i.e. closing the host + // object should close the dependent object. + bool IsOwning() const { + return methods_and_handle_.methods->is_owning(repr_.storage); + } + + // If `true`, `get()` stays unchanged when an `AnyBase` is moved. + static constexpr bool kIsStable = inline_size == 0; + + // If the `Manager` has exactly this type or a reference to it, returns a + // pointer to the `Manager`. If the `Manager` is an `AnyBase` (possibly + // wrapped in a reference or `std::unique_ptr`), propagates `GetIf()` to it. + // Otherwise returns `nullptr`. + template < + typename Manager, + std::enable_if_t::value, int> = 0> + Manager* GetIf(); + template < + typename Manager, + std::enable_if_t::value, int> = 0> + const Manager* GetIf() const; + + // A variant of `GetIf()` with the expected type passed as a `TypeId`. + void* GetIf(TypeId type_id); + const void* GetIf(TypeId type_id) const; + + // Support `MemoryEstimator`. + friend void RiegeliRegisterSubobjects(const AnyBase* self, + MemoryEstimator& memory_estimator) { + self->methods_and_handle_.methods->register_subobjects(self->repr_.storage, + memory_estimator); + } + + protected: + // The state is left uninitialized. + AnyBase() noexcept {} + + AnyBase(AnyBase&& that) noexcept; + AnyBase& operator=(AnyBase&& that) noexcept; + + ~AnyBase() { Destroy(); } + + // Initializes the state, avoiding a redundant indirection and adopting them + // from `manager` instead if `Manager` is already a compatible `Any` or + // `AnyRef`. + void Initialize(); + template ::value, int> = 0> + void Initialize(Manager&& manager); + template ::value, int> = 0> + void Initialize(Manager&& manager); + template ::value, int> = 0> + void Initialize(Initializer manager); + template ::value, int> = 0> + void Initialize(Initializer manager); + void Initialize(AnyInitializer manager); + + // Destroys the state, leaving it uninitialized. + void Destroy(); + + private: + // For adopting the state from an instantiation with a different `inline_size` + // and `inline_align. + template + friend class AnyBase; + // For adopting the state from an instantiation held in an `AnyInitializer`. + friend class AnyInitializer; + + using Repr = any_internal::Repr; + using MethodsAndHandle = any_internal::MethodsAndHandle; + using NullMethods = any_internal::NullMethods; + template + using MethodsFor = any_internal::MethodsFor< + Handle, Manager, IsInline()>; + + static constexpr size_t kAvailableSize = + AvailableSize(); + static constexpr size_t kAvailableAlign = + AvailableAlign(); + + template ::value, + int> = 0> + void AssertNotNull(absl::string_view message) const { + RIEGELI_ASSERT(get() != nullptr) << message; + } + template ::value, int> = 0> + void AssertNotNull(ABSL_ATTRIBUTE_UNUSED absl::string_view message) const {} + + MethodsAndHandle methods_and_handle_; + Repr repr_; +}; + +// Before C++17 if a constexpr static data member is ODR-used, its definition at +// namespace scope is required. Since C++17 these definitions are deprecated: +// http://en.cppreference.com/w/cpp/language/static +#if !__cpp_inline_variables +template +constexpr size_t AnyBase::kAvailableSize; +constexpr size_t AnyBase::kAvailableAlign; +#endif + +} // namespace any_internal + +// `Any` refers to an optionally owned object which is accessed as +// `Handle` and stored as some `Manager` type decided when the `Any` is +// initialized. +// +// Often `Handle` is some pointer `Base*`, and then `Manager` can be e.g. +// `T*` (not owned), `T` (owned), or `std::unique_ptr` (owned), with some `T` +// derived from `Base`. +// +// `Any` holds a `Dependency` for some `Manager` type, +// erasing the `Manager` parameter from the type of the `Any`, or is empty. +template +class Any : public any_internal::AnyBase { + public: + // `Any::Inlining` enlarges inline storage of + // `Any`. + // + // `InlineManagers` specify the size of inline storage, which allows to avoid + // heap allocation if `Manager` is among `InlineManagers`, or if + // `Dependency` fits there regarding size and alignment. + // By default inline storage is enough for a pointer. + template + using Inlining = + Any)...), + UnsignedMax(inline_align, + alignof(Dependency)...)>; + + // Creates an empty `Any`. + Any() noexcept { this->Initialize(); } + + // Holds a `Dependency>`. + template < + typename Manager, + std::enable_if_t< + absl::conjunction< + absl::negation, Any>>, + IsValidDependency>>::value, + int> = 0> + /*implicit*/ Any(Manager&& manager); + template < + typename Manager, + std::enable_if_t< + absl::conjunction< + absl::negation, Any>>, + IsValidDependency>>::value, + int> = 0> + Any& operator=(Manager&& manager); + + // Holds the `Dependency` specified when the `AnyInitializer` was constructed. + /*implicit*/ Any(AnyInitializer manager); + Any& operator=(AnyInitializer manager); + + Any(Any&& that) = default; + Any& operator=(Any&& that) = default; +}; + +// Specialization of `DependencyManagerImpl>`: +// a dependency with ownership determined at runtime. +template +class DependencyManagerImpl, + ManagerStorage> + : public DependencyBase { + public: + using DependencyManagerImpl::DependencyBase::DependencyBase; + + bool IsOwning() const { return this->manager().IsOwning(); } + + static constexpr bool kIsStable = + DependencyManagerImpl::DependencyBase::kIsStable || + Any::kIsStable; + + void* GetIf(TypeId type_id) { return this->manager().GetIf(type_id); } + const void* GetIf(TypeId type_id) const { + return this->manager().GetIf(type_id); + } + + protected: + DependencyManagerImpl(DependencyManagerImpl&& that) = default; + DependencyManagerImpl& operator=(DependencyManagerImpl&& that) = default; + + ~DependencyManagerImpl() = default; + + Handle ptr() const { return this->manager().get(); } +}; + +// Specialization of +// `DependencyManagerImpl, Deleter>>`: +// a dependency with ownership determined at runtime. +// +// It covers `ClosingPtrType>`. +template +class DependencyManagerImpl< + std::unique_ptr, Deleter>, + ManagerStorage> + : public DependencyBase::value, + std::unique_ptr, Deleter>, + ManagerStorage>> { + public: + using DependencyManagerImpl::DependencyBase::DependencyBase; + + bool IsOwning() const { + return this->manager() != nullptr && this->manager()->IsOwning(); + } + + static constexpr bool kIsStable = true; + + void* GetIf(TypeId type_id) { + if (this->manager() == nullptr) return nullptr; + return this->manager()->GetIf(type_id); + } + const void* GetIf(TypeId type_id) const { + if (this->manager() == nullptr) return nullptr; + return this->manager()->GetIf(type_id); + } + + protected: + DependencyManagerImpl(DependencyManagerImpl&& that) = default; + DependencyManagerImpl& operator=(DependencyManagerImpl&& that) = default; + + ~DependencyManagerImpl() = default; + + Handle ptr() const { return this->manager()->get(); } +}; + +// `AnyRef` refers to an optionally owned object which is accessed as +// `Handle` and was passed as some `Manager` type decided when the `AnyRef` was +// initialized. +// +// Often `Handle` is some pointer `Base*`, and then `Manager` can be e.g. +// `T&` (not owned), `T&&` (owned), or `std::unique_ptr` (owned), with some +// `T` derived from `Base`. +// +// `AnyRef` holds a `Dependency` (which collapses to +// `Dependency` if `Manager` is itself an lvalue reference) +// for some `Manager` type, erasing the `Manager` parameter from the type of the +// `AnyRef`, or is empty. +// +// `AnyRef(manager)` does not own `manager`, even if it involves +// temporaries, hence it should be used only as a parameter of a function or +// constructor, so that the temporaries outlive its usage. Instead of storing an +// `AnyRef` in a variable or returning it from a function, consider +// `riegeli::OwningMaker()`, `MakerTypeFor`, +// or `Any`. +// +// This allows to pass an unowned dependency by lvalue reference instead of by +// pointer, which allows for a more idiomatic API for passing an object which +// does not need to be valid after the function returns. And this allows to pass +// an owned dependency by rvalue reference instead of by value, which avoids +// moving it. +template +class AnyRef : public any_internal::AnyBase { + public: + // Creates an empty `AnyRef`. + AnyRef() noexcept { this->Initialize(); } + + // Holds a `Dependency`. + template , AnyRef>>, + IsValidDependency>::value, + int> = 0> + /*implicit*/ AnyRef(Manager&& manager ABSL_ATTRIBUTE_LIFETIME_BOUND); + + AnyRef(AnyRef&& that) = default; + AnyRef& operator=(AnyRef&& that) = default; +}; + +// Specialization of `DependencyManagerImpl>`: +// a dependency with ownership determined at runtime. +template +class DependencyManagerImpl, ManagerStorage> + : public DependencyBase { + public: + using DependencyManagerImpl::DependencyBase::DependencyBase; + + bool IsOwning() const { return this->manager().IsOwning(); } + + static constexpr bool kIsStable = + DependencyManagerImpl::DependencyBase::kIsStable || + AnyRef::kIsStable; + + void* GetIf(TypeId type_id) { return this->manager().GetIf(type_id); } + const void* GetIf(TypeId type_id) const { + return this->manager().GetIf(type_id); + } + + protected: + DependencyManagerImpl(DependencyManagerImpl&& that) = default; + DependencyManagerImpl& operator=(DependencyManagerImpl&& that) = default; + + ~DependencyManagerImpl() = default; + + Handle ptr() const { return this->manager().get(); } +}; + +// Specialization of +// `DependencyManagerImpl, Deleter>>`: +// a dependency with ownership determined at runtime. +// +// It covers `ClosingPtrType>`. +template +class DependencyManagerImpl, Deleter>, + ManagerStorage> + : public DependencyBase::value, + std::unique_ptr, Deleter>, ManagerStorage>> { + public: + using DependencyManagerImpl::DependencyBase::DependencyBase; + + bool IsOwning() const { + return this->manager() != nullptr && this->manager()->IsOwning(); + } + + static constexpr bool kIsStable = true; + + void* GetIf(TypeId type_id) { + if (this->manager() == nullptr) return nullptr; + return this->manager()->GetIf(type_id); + } + const void* GetIf(TypeId type_id) const { + if (this->manager() == nullptr) return nullptr; + return this->manager()->GetIf(type_id); + } + + protected: + DependencyManagerImpl(DependencyManagerImpl&& that) = default; + DependencyManagerImpl& operator=(DependencyManagerImpl&& that) = default; + + ~DependencyManagerImpl() = default; + + Handle ptr() const { return this->manager()->get(); } +}; + +// Implementation details follow. + +namespace any_internal { + +template +inline AnyBase::AnyBase( + AnyBase&& that) noexcept { + if (inline_size == 0) { + // Replace an indirect call to `methods_and_handle_.methods->move()` with + // a plain assignment of `methods_and_handle_.handle` and `repr_`. + methods_and_handle_.methods = + std::exchange(that.methods_and_handle_.methods, &NullMethods::kMethods); + methods_and_handle_.handle = std::exchange(that.methods_and_handle_.handle, + SentinelHandle()); + repr_ = that.repr_; + } else { + that.methods_and_handle_.handle = SentinelHandle(); + methods_and_handle_.methods = + std::exchange(that.methods_and_handle_.methods, &NullMethods::kMethods); + methods_and_handle_.methods->move( + repr_.storage, &methods_and_handle_.handle, that.repr_.storage); + } +} + +template +inline AnyBase& +AnyBase::operator=(AnyBase&& that) noexcept { + if (ABSL_PREDICT_TRUE(&that != this)) { + Destroy(); + if (inline_size == 0) { + // Replace an indirect call to `methods_and_handle_.methods->move()` with + // a plain assignment of `methods_and_handle_.handle` and `repr_`. + methods_and_handle_.methods = std::exchange( + that.methods_and_handle_.methods, &NullMethods::kMethods); + methods_and_handle_.handle = std::exchange( + that.methods_and_handle_.handle, SentinelHandle()); + repr_ = that.repr_; + } else { + that.methods_and_handle_.handle = SentinelHandle(); + methods_and_handle_.methods = std::exchange( + that.methods_and_handle_.methods, &NullMethods::kMethods); + methods_and_handle_.methods->move( + repr_.storage, &methods_and_handle_.handle, that.repr_.storage); + } + } + return *this; +} + +template +inline void AnyBase::Initialize() { + methods_and_handle_.methods = &NullMethods::kMethods; + new (&methods_and_handle_.handle) + Handle(any_internal::SentinelHandle()); +} + +template +template ::value, int>> +inline void AnyBase::Initialize( + Manager&& manager) { + Initialize(Initializer(std::forward(manager))); +} + +template +template ::value, int>> +inline void AnyBase::Initialize( + Manager&& manager) { + // `manager.methods_and_handle_.methods->used_size <= + // Manager::kAvailableSize`, hence if + // `Manager::kAvailableSize <= + // AvailableSize()` then + // `manager.methods_and_handle_.methods->used_size <= + // AvailableSize()`. + // No need to check possibly at runtime. + if ((Manager::kAvailableSize <= + AvailableSize() || + manager.methods_and_handle_.methods->used_size <= + AvailableSize()) && + // Same for alignment. + (Manager::kAvailableAlign <= + AvailableAlign() || + manager.methods_and_handle_.methods->used_align <= + AvailableAlign())) { + // Adopt `manager` instead of wrapping it. + if (Manager::kAvailableSize == 0 || inline_size == 0) { + // Replace an indirect call to `methods_and_handle_.methods->move()` with + // a plain assignment of `methods_and_handle_.handle` and a memory copy of + // `repr_`. + // + // This would safe whenever + // `manager.methods_and_handle_.methods->used_size == 0`, but this is + // handled specially only if the condition can be determined at compile + // time. + methods_and_handle_.methods = std::exchange( + manager.methods_and_handle_.methods, &NullMethods::kMethods); + methods_and_handle_.handle = std::exchange( + manager.methods_and_handle_.handle, SentinelHandle()); + std::memcpy(&repr_, &manager.repr_, + UnsignedMin(sizeof(repr_), sizeof(manager.repr_))); + } else { + manager.methods_and_handle_.handle = SentinelHandle(); + methods_and_handle_.methods = std::exchange( + manager.methods_and_handle_.methods, &NullMethods::kMethods); + methods_and_handle_.methods->move( + repr_.storage, &methods_and_handle_.handle, manager.repr_.storage); + } + return; + } + methods_and_handle_.methods = &MethodsFor::kMethods; + MethodsFor::Construct(repr_.storage, &methods_and_handle_.handle, + std::forward(manager)); +} + +template +template ::value, int>> +inline void AnyBase::Initialize( + Initializer manager) { + methods_and_handle_.methods = &MethodsFor::kMethods; + MethodsFor::Construct(repr_.storage, &methods_and_handle_.handle, + std::move(manager)); +} + +template +template ::value, int>> +inline void AnyBase::Initialize( + Initializer manager) { + // This is called only from `Any` so the + // type of `*this` matches. + if (std::is_same>::value) { + // Adopt `manager` instead of wrapping it. Doing this here if possible + // avoids creating a temporary `Any` and moving from it. + // + // `*this` is formally already constructed, but nothing was initialized yet. + new (this) Manager(std::move(manager).Construct()); + return; + } + // Materialize `Manager` to consider adopting its storage. + Initialize(std::move(manager).Reference()); +} + +template +inline void AnyBase::Initialize( + AnyInitializer manager) { + std::move(manager).Construct( + methods_and_handle_, repr_.storage, + AvailableSize(), + AvailableAlign()); +} + +template +inline void AnyBase::Destroy() { + methods_and_handle_.handle.~Handle(); + methods_and_handle_.methods->destroy(repr_.storage); +} + +template +inline void AnyBase::Reset() { + methods_and_handle_.handle = SentinelHandle(); + methods_and_handle_.methods->destroy(repr_.storage); + methods_and_handle_.methods = &NullMethods::kMethods; +} + +template +template ::value, int>> +inline Manager* AnyBase::GetIf() { + return static_cast(GetIf(TypeId::For())); +} + +template +template ::value, int>> +inline const Manager* AnyBase::GetIf() + const { + return static_cast(GetIf(TypeId::For())); +} + +template +inline void* AnyBase::GetIf(TypeId type_id) { + return methods_and_handle_.methods->mutable_get_if(repr_.storage, type_id); +} + +template +inline const void* AnyBase::GetIf( + TypeId type_id) const { + return methods_and_handle_.methods->const_get_if(repr_.storage, type_id); +} + +} // namespace any_internal + +template +template < + typename Manager, + std::enable_if_t< + absl::conjunction< + absl::negation, Any>>, + IsValidDependency>>::value, + int>> +inline Any::Any(Manager&& manager) { + this->template Initialize>( + std::forward(manager)); +} + +template +template < + typename Manager, + std::enable_if_t< + absl::conjunction< + absl::negation, Any>>, + IsValidDependency>>::value, + int>> +inline Any& +Any::operator=(Manager&& manager) { + this->Destroy(); + this->template Initialize>( + std::forward(manager)); + return *this; +} + +template +inline Any::Any( + AnyInitializer manager) { + this->Initialize(std::move(manager)); +} + +template +inline Any& +Any::operator=( + AnyInitializer manager) { + this->Destroy(); + this->Initialize(std::move(manager)); + return *this; +} + +template +template < + typename Manager, + std::enable_if_t< + absl::conjunction< + absl::negation, AnyRef>>, + IsValidDependency>::value, + int>> +inline AnyRef::AnyRef(Manager&& manager) { + this->template Initialize(std::forward(manager)); +} + +} // namespace riegeli + +#endif // RIEGELI_BASE_ANY_H_ diff --git a/riegeli/base/any_dependency.h b/riegeli/base/any_dependency.h index 9560d12c..03dd6485 100644 --- a/riegeli/base/any_dependency.h +++ b/riegeli/base/any_dependency.h @@ -17,699 +17,17 @@ #include -#include -#include -#include -#include -#include -#include -#include - -#include "absl/base/attributes.h" -#include "absl/base/optimization.h" -#include "absl/meta/type_traits.h" -#include "absl/strings/string_view.h" -#include "riegeli/base/any_dependency_initializer.h" -#include "riegeli/base/any_dependency_internal.h" -#include "riegeli/base/arithmetic.h" -#include "riegeli/base/assert.h" -#include "riegeli/base/compare.h" -#include "riegeli/base/dependency.h" -#include "riegeli/base/dependency_base.h" -#include "riegeli/base/dependency_manager.h" -#include "riegeli/base/initializer.h" -#include "riegeli/base/memory_estimator.h" -#include "riegeli/base/type_id.h" -#include "riegeli/base/type_traits.h" +#include "absl/base/macros.h" +#include "riegeli/base/any.h" namespace riegeli { -namespace any_dependency_internal { - -// Common base class of `AnyDependency` and `AnyDependencyRef`. -// -// `ABSL_ATTRIBUTE_TRIVIAL_ABI` is effective if `inline_size == 0`. -template -class -#ifdef ABSL_ATTRIBUTE_TRIVIAL_ABI - ABSL_ATTRIBUTE_TRIVIAL_ABI -#endif - AnyDependencyBase - : public WithEqual>, - public ConditionallyAbslNullabilityCompatible< - IsComparableAgainstNullptr::value>, - public ConditionallyTrivialAbi { - public: - // Makes `*this` equivalent to a newly constructed `AnyDependencyBase`. This - // avoids constructing a temporary `AnyDependencyBase` and moving from it. - ABSL_ATTRIBUTE_REINITIALIZES void Reset(); - - // Returns a `Handle` to the `Manager`, or a default `Handle` for an empty - // `AnyDependencyBase`. - Handle get() const { return methods_and_handle_.handle; } - - // If `Handle` is `Base*`, `AnyDependencyBase` can be used as a smart - // pointer to `Base`, for convenience. - template ::value, int> = 0> - decltype(*std::declval()) operator*() const { - AssertNotNull( - "Failed precondition of AnyDependencyBase::operator*: null handle"); - return *get(); - } - - template ::value, int> = 0> - Handle operator->() const { - AssertNotNull( - "Failed precondition of AnyDependencyBase::operator->: null handle"); - return get(); - } - - // If `Handle` is `Base*`, `AnyDependencyBase` can be compared against - // `nullptr`. - template ::value, - int> = 0> - friend bool operator==(const AnyDependencyBase& a, std::nullptr_t) { - return a.get() == nullptr; - } - - // If `true`, the `AnyDependencyBase` owns the dependent object, i.e. closing - // the host object should close the dependent object. - bool IsOwning() const { - return methods_and_handle_.methods->is_owning(repr_.storage); - } - - // If `true`, `get()` stays unchanged when an `AnyDependencyBase` is moved. - static constexpr bool kIsStable = inline_size == 0; - - // If the `Manager` has exactly this type or a reference to it, returns a - // pointer to the `Manager`. If the `Manager` is an `AnyDependencyBase` - // (possibly wrapped in a reference or `std::unique_ptr`), propagates - // `GetIf()` to it. Otherwise returns `nullptr`. - template < - typename Manager, - std::enable_if_t::value, int> = 0> - Manager* GetIf(); - template < - typename Manager, - std::enable_if_t::value, int> = 0> - const Manager* GetIf() const; - - // A variant of `GetIf()` with the expected type passed as a `TypeId`. - void* GetIf(TypeId type_id); - const void* GetIf(TypeId type_id) const; - - // Support `MemoryEstimator`. - friend void RiegeliRegisterSubobjects(const AnyDependencyBase* self, - MemoryEstimator& memory_estimator) { - self->methods_and_handle_.methods->register_subobjects(self->repr_.storage, - memory_estimator); - } - - protected: - // The state is left uninitialized. - AnyDependencyBase() noexcept {} - - AnyDependencyBase(AnyDependencyBase&& that) noexcept; - AnyDependencyBase& operator=(AnyDependencyBase&& that) noexcept; - - ~AnyDependencyBase() { Destroy(); } - - // Initializes the state, avoiding a redundant indirection and adopting them - // from `manager` instead if `Manager` is already a compatible `AnyDependency` - // or `AnyDependencyRef`. - void Initialize(); - template ::value, int> = 0> - void Initialize(Manager&& manager); - template ::value, int> = 0> - void Initialize(Manager&& manager); - template ::value, int> = 0> - void Initialize(Initializer manager); - template ::value, int> = 0> - void Initialize(Initializer manager); - void Initialize(AnyDependencyInitializer manager); - - // Destroys the state, leaving it uninitialized. - void Destroy(); - - private: - // For adopting the state from an instantiation with a different `inline_size` - // and `inline_align. - template - friend class AnyDependencyBase; - // For adopting the state from an instantiation held in an - // `AnyDependencyInitializer`. - friend class AnyDependencyInitializer; - - using Repr = any_dependency_internal::Repr; - using MethodsAndHandle = any_dependency_internal::MethodsAndHandle; - using NullMethods = any_dependency_internal::NullMethods; - template - using MethodsFor = any_dependency_internal::MethodsFor< - Handle, Manager, IsInline()>; - - static constexpr size_t kAvailableSize = - AvailableSize(); - static constexpr size_t kAvailableAlign = - AvailableAlign(); - - template ::value, - int> = 0> - void AssertNotNull(absl::string_view message) const { - RIEGELI_ASSERT(get() != nullptr) << message; - } - template ::value, int> = 0> - void AssertNotNull(ABSL_ATTRIBUTE_UNUSED absl::string_view message) const {} - - MethodsAndHandle methods_and_handle_; - Repr repr_; -}; - -// Before C++17 if a constexpr static data member is ODR-used, its definition at -// namespace scope is required. Since C++17 these definitions are deprecated: -// http://en.cppreference.com/w/cpp/language/static -#if !__cpp_inline_variables -template -constexpr size_t - AnyDependencyBase::kAvailableSize; -constexpr size_t - AnyDependencyBase::kAvailableAlign; -#endif - -} // namespace any_dependency_internal - -// `AnyDependency` refers to an optionally owned object which is -// accessed as `Handle` and stored as some `Manager` type decided when the -// `AnyDependency` is initialized. -// -// Often `Handle` is some pointer `Base*`, and then `Manager` can be e.g. -// `T*` (not owned), `T` (owned), or `std::unique_ptr` (owned), with some `T` -// derived from `Base`. -// -// `AnyDependency` holds a `Dependency` for some -// `Manager` type, erasing the `Manager` parameter from the type of the -// `AnyDependency`, or is empty. template -class AnyDependency - : public any_dependency_internal::AnyDependencyBase { - public: - // `AnyDependency::Inlining` enlarges inline - // storage of `AnyDependency`. - // - // `InlineManagers` specify the size of inline storage, which allows to avoid - // heap allocation if `Manager` is among `InlineManagers`, or if - // `Dependency` fits there regarding size and alignment. - // By default inline storage is enough for a pointer. - template - using Inlining = AnyDependency< - Handle, - UnsignedMax(inline_size, sizeof(Dependency)...), - UnsignedMax(inline_align, - alignof(Dependency)...)>; - - // Creates an empty `AnyDependency`. - AnyDependency() noexcept { this->Initialize(); } - - // Holds a `Dependency>`. - template < - typename Manager, - std::enable_if_t< - absl::conjunction< - absl::negation< - std::is_same, AnyDependency>>, - IsValidDependency>>::value, - int> = 0> - /*implicit*/ AnyDependency(Manager&& manager); - template < - typename Manager, - std::enable_if_t< - absl::conjunction< - absl::negation< - std::is_same, AnyDependency>>, - IsValidDependency>>::value, - int> = 0> - AnyDependency& operator=(Manager&& manager); - - // Holds the `Dependency` specified when the `AnyDependencyInitializer` was - // constructed. - /*implicit*/ AnyDependency(AnyDependencyInitializer manager); - AnyDependency& operator=(AnyDependencyInitializer manager); - - AnyDependency(AnyDependency&& that) = default; - AnyDependency& operator=(AnyDependency&& that) = default; -}; - -// Specialization of `DependencyManagerImpl>`: -// a dependency with ownership determined at runtime. -template -class DependencyManagerImpl, - ManagerStorage> - : public DependencyBase { - public: - using DependencyManagerImpl::DependencyBase::DependencyBase; - - bool IsOwning() const { return this->manager().IsOwning(); } - - static constexpr bool kIsStable = - DependencyManagerImpl::DependencyBase::kIsStable || - AnyDependency::kIsStable; - - void* GetIf(TypeId type_id) { return this->manager().GetIf(type_id); } - const void* GetIf(TypeId type_id) const { - return this->manager().GetIf(type_id); - } - - protected: - DependencyManagerImpl(DependencyManagerImpl&& that) = default; - DependencyManagerImpl& operator=(DependencyManagerImpl&& that) = default; - - ~DependencyManagerImpl() = default; - - Handle ptr() const { return this->manager().get(); } -}; - -// Specialization of -// `DependencyManagerImpl, Deleter>>`: -// a dependency with ownership determined at runtime. -// -// It covers `ClosingPtrType>`. -template -class DependencyManagerImpl< - std::unique_ptr, Deleter>, - ManagerStorage> - : public DependencyBase::value, - std::unique_ptr, - Deleter>, - ManagerStorage>> { - public: - using DependencyManagerImpl::DependencyBase::DependencyBase; - - bool IsOwning() const { - return this->manager() != nullptr && this->manager()->IsOwning(); - } - - static constexpr bool kIsStable = true; - - void* GetIf(TypeId type_id) { - if (this->manager() == nullptr) return nullptr; - return this->manager()->GetIf(type_id); - } - const void* GetIf(TypeId type_id) const { - if (this->manager() == nullptr) return nullptr; - return this->manager()->GetIf(type_id); - } - - protected: - DependencyManagerImpl(DependencyManagerImpl&& that) = default; - DependencyManagerImpl& operator=(DependencyManagerImpl&& that) = default; - - ~DependencyManagerImpl() = default; - - Handle ptr() const { return this->manager()->get(); } -}; - -// `AnyDependencyRef` refers to an optionally owned object which is -// accessed as `Handle` and was passed as some `Manager` type decided when the -// `AnyDependencyRef` was initialized. -// -// Often `Handle` is some pointer `Base*`, and then `Manager` can be e.g. -// `T&` (not owned), `T&&` (owned), or `std::unique_ptr` (owned), with some -// `T` derived from `Base`. -// -// `AnyDependencyRef` holds a `Dependency` (which -// collapses to `Dependency` if `Manager` is itself an lvalue -// reference) for some `Manager` type, erasing the `Manager` parameter from the -// type of the `AnyDependencyRef`, or is empty. -// -// `AnyDependencyRef(manager)` does not own `manager`, even if it -// involves temporaries, hence it should be used only as a parameter of a -// function or constructor, so that the temporaries outlive its usage. -// Instead of storing an `AnyDependencyRef` in a variable or returning -// it from a function, consider `riegeli::OwningMaker()`, -// `MakerTypeFor`, or `AnyDependency`. -// -// This allows to pass an unowned dependency by lvalue reference instead of by -// pointer, which allows for a more idiomatic API for passing an object which -// does not need to be valid after the function returns. And this allows to pass -// an owned dependency by rvalue reference instead of by value, which avoids -// moving it. -template -class AnyDependencyRef - : public any_dependency_internal::AnyDependencyBase { - public: - // Creates an empty `AnyDependencyRef`. - AnyDependencyRef() noexcept { this->Initialize(); } - - // Holds a `Dependency`. - template , AnyDependencyRef>>, - IsValidDependency>::value, - int> = 0> - /*implicit*/ AnyDependencyRef( - Manager&& manager ABSL_ATTRIBUTE_LIFETIME_BOUND); - - AnyDependencyRef(AnyDependencyRef&& that) = default; - AnyDependencyRef& operator=(AnyDependencyRef&& that) = default; -}; - -// Specialization of `DependencyManagerImpl>`: -// a dependency with ownership determined at runtime. -template -class DependencyManagerImpl, ManagerStorage> - : public DependencyBase { - public: - using DependencyManagerImpl::DependencyBase::DependencyBase; - - bool IsOwning() const { return this->manager().IsOwning(); } - - static constexpr bool kIsStable = - DependencyManagerImpl::DependencyBase::kIsStable || - AnyDependencyRef::kIsStable; - - void* GetIf(TypeId type_id) { return this->manager().GetIf(type_id); } - const void* GetIf(TypeId type_id) const { - return this->manager().GetIf(type_id); - } - - protected: - DependencyManagerImpl(DependencyManagerImpl&& that) = default; - DependencyManagerImpl& operator=(DependencyManagerImpl&& that) = default; - - ~DependencyManagerImpl() = default; - - Handle ptr() const { return this->manager().get(); } -}; - -// Specialization of -// `DependencyManagerImpl, Deleter>>`: -// a dependency with ownership determined at runtime. -// -// It covers `ClosingPtrType>`. -template -class DependencyManagerImpl, Deleter>, - ManagerStorage> - : public DependencyBase::value, - std::unique_ptr, Deleter>, ManagerStorage>> { - public: - using DependencyManagerImpl::DependencyBase::DependencyBase; - - bool IsOwning() const { - return this->manager() != nullptr && this->manager()->IsOwning(); - } - - static constexpr bool kIsStable = true; - - void* GetIf(TypeId type_id) { - if (this->manager() == nullptr) return nullptr; - return this->manager()->GetIf(type_id); - } - const void* GetIf(TypeId type_id) const { - if (this->manager() == nullptr) return nullptr; - return this->manager()->GetIf(type_id); - } - - protected: - DependencyManagerImpl(DependencyManagerImpl&& that) = default; - DependencyManagerImpl& operator=(DependencyManagerImpl&& that) = default; - - ~DependencyManagerImpl() = default; - - Handle ptr() const { return this->manager()->get(); } -}; - -// Implementation details follow. - -namespace any_dependency_internal { - -template -inline AnyDependencyBase::AnyDependencyBase( - AnyDependencyBase&& that) noexcept { - if (inline_size == 0) { - // Replace an indirect call to `methods_and_handle_.methods->move()` with - // a plain assignment of `methods_and_handle_.handle` and `repr_`. - methods_and_handle_.methods = - std::exchange(that.methods_and_handle_.methods, &NullMethods::kMethods); - methods_and_handle_.handle = std::exchange(that.methods_and_handle_.handle, - SentinelHandle()); - repr_ = that.repr_; - } else { - that.methods_and_handle_.handle = SentinelHandle(); - methods_and_handle_.methods = - std::exchange(that.methods_and_handle_.methods, &NullMethods::kMethods); - methods_and_handle_.methods->move( - repr_.storage, &methods_and_handle_.handle, that.repr_.storage); - } -} - -template -inline AnyDependencyBase& -AnyDependencyBase::operator=( - AnyDependencyBase&& that) noexcept { - if (ABSL_PREDICT_TRUE(&that != this)) { - Destroy(); - if (inline_size == 0) { - // Replace an indirect call to `methods_and_handle_.methods->move()` with - // a plain assignment of `methods_and_handle_.handle` and `repr_`. - methods_and_handle_.methods = std::exchange( - that.methods_and_handle_.methods, &NullMethods::kMethods); - methods_and_handle_.handle = std::exchange( - that.methods_and_handle_.handle, SentinelHandle()); - repr_ = that.repr_; - } else { - that.methods_and_handle_.handle = SentinelHandle(); - methods_and_handle_.methods = std::exchange( - that.methods_and_handle_.methods, &NullMethods::kMethods); - methods_and_handle_.methods->move( - repr_.storage, &methods_and_handle_.handle, that.repr_.storage); - } - } - return *this; -} - -template -inline void AnyDependencyBase::Initialize() { - methods_and_handle_.methods = &NullMethods::kMethods; - new (&methods_and_handle_.handle) - Handle(any_dependency_internal::SentinelHandle()); -} - -template -template ::value, int>> -inline void AnyDependencyBase::Initialize( - Manager&& manager) { - Initialize(Initializer(std::forward(manager))); -} - -template -template ::value, int>> -inline void AnyDependencyBase::Initialize( - Manager&& manager) { - // `manager.methods_and_handle_.methods->used_size <= - // Manager::kAvailableSize`, hence if - // `Manager::kAvailableSize <= - // AvailableSize()` then - // `manager.methods_and_handle_.methods->used_size <= - // AvailableSize()`. - // No need to check possibly at runtime. - if ((Manager::kAvailableSize <= - AvailableSize() || - manager.methods_and_handle_.methods->used_size <= - AvailableSize()) && - // Same for alignment. - (Manager::kAvailableAlign <= - AvailableAlign() || - manager.methods_and_handle_.methods->used_align <= - AvailableAlign())) { - // Adopt `manager` instead of wrapping it. - if (Manager::kAvailableSize == 0 || inline_size == 0) { - // Replace an indirect call to `methods_and_handle_.methods->move()` with - // a plain assignment of `methods_and_handle_.handle` and a memory copy of - // `repr_`. - // - // This would safe whenever - // `manager.methods_and_handle_.methods->used_size == 0`, but this is - // handled specially only if the condition can be determined at compile - // time. - methods_and_handle_.methods = std::exchange( - manager.methods_and_handle_.methods, &NullMethods::kMethods); - methods_and_handle_.handle = std::exchange( - manager.methods_and_handle_.handle, SentinelHandle()); - std::memcpy(&repr_, &manager.repr_, - UnsignedMin(sizeof(repr_), sizeof(manager.repr_))); - } else { - manager.methods_and_handle_.handle = SentinelHandle(); - methods_and_handle_.methods = std::exchange( - manager.methods_and_handle_.methods, &NullMethods::kMethods); - methods_and_handle_.methods->move( - repr_.storage, &methods_and_handle_.handle, manager.repr_.storage); - } - return; - } - methods_and_handle_.methods = &MethodsFor::kMethods; - MethodsFor::Construct(repr_.storage, &methods_and_handle_.handle, - std::forward(manager)); -} - -template -template ::value, int>> -inline void AnyDependencyBase::Initialize( - Initializer manager) { - methods_and_handle_.methods = &MethodsFor::kMethods; - MethodsFor::Construct(repr_.storage, &methods_and_handle_.handle, - std::move(manager)); -} - -template -template ::value, int>> -inline void AnyDependencyBase::Initialize( - Initializer manager) { - // This is called only from `AnyDependency` - // so the type of `*this` matches. - if (std::is_same>::value) { - // Adopt `manager` instead of wrapping it. Doing this here if possible - // avoids creating a temporary `AnyDependency` and moving from it. - // - // `*this` is formally already constructed, but nothing was initialized yet. - new (this) Manager(std::move(manager).Construct()); - return; - } - // Materialize `Manager` to consider adopting its storage. - Initialize(std::move(manager).Reference()); -} - -template -inline void AnyDependencyBase::Initialize( - AnyDependencyInitializer manager) { - std::move(manager).Construct( - methods_and_handle_, repr_.storage, - AvailableSize(), - AvailableAlign()); -} - -template -inline void AnyDependencyBase::Destroy() { - methods_and_handle_.handle.~Handle(); - methods_and_handle_.methods->destroy(repr_.storage); -} - -template -inline void AnyDependencyBase::Reset() { - methods_and_handle_.handle = SentinelHandle(); - methods_and_handle_.methods->destroy(repr_.storage); - methods_and_handle_.methods = &NullMethods::kMethods; -} - -template -template ::value, int>> -inline Manager* AnyDependencyBase::GetIf() { - return static_cast(GetIf(TypeId::For())); -} - -template -template ::value, int>> -inline const Manager* -AnyDependencyBase::GetIf() const { - return static_cast(GetIf(TypeId::For())); -} - -template -inline void* AnyDependencyBase::GetIf( - TypeId type_id) { - return methods_and_handle_.methods->mutable_get_if(repr_.storage, type_id); -} - -template -inline const void* AnyDependencyBase::GetIf( - TypeId type_id) const { - return methods_and_handle_.methods->const_get_if(repr_.storage, type_id); -} - -} // namespace any_dependency_internal - -template -template < - typename Manager, - std::enable_if_t< - absl::conjunction< - absl::negation< - std::is_same, - AnyDependency>>, - IsValidDependency>>::value, - int>> -inline AnyDependency::AnyDependency( - Manager&& manager) { - this->template Initialize>( - std::forward(manager)); -} - -template -template < - typename Manager, - std::enable_if_t< - absl::conjunction< - absl::negation< - std::is_same, - AnyDependency>>, - IsValidDependency>>::value, - int>> -inline AnyDependency& -AnyDependency::operator=(Manager&& manager) { - this->Destroy(); - this->template Initialize>( - std::forward(manager)); - return *this; -} - -template -inline AnyDependency::AnyDependency( - AnyDependencyInitializer manager) { - this->Initialize(std::move(manager)); -} - -template -inline AnyDependency& -AnyDependency::operator=( - AnyDependencyInitializer manager) { - this->Destroy(); - this->Initialize(std::move(manager)); - return *this; -} +using AnyDependency ABSL_DEPRECATE_AND_INLINE() = + Any; template -template < - typename Manager, - std::enable_if_t< - absl::conjunction, AnyDependencyRef>>, - IsValidDependency>::value, - int>> -inline AnyDependencyRef::AnyDependencyRef(Manager&& manager) { - this->template Initialize(std::forward(manager)); -} +using AnyDependencyRef ABSL_DEPRECATE_AND_INLINE() = AnyRef; } // namespace riegeli diff --git a/riegeli/base/any_dependency_initializer.h b/riegeli/base/any_dependency_initializer.h index d528161a..dd30200c 100644 --- a/riegeli/base/any_dependency_initializer.h +++ b/riegeli/base/any_dependency_initializer.h @@ -15,250 +15,14 @@ #ifndef RIEGELI_BASE_ANY_DEPENDENCY_INITIALIZER_H_ #define RIEGELI_BASE_ANY_DEPENDENCY_INITIALIZER_H_ -#include - -#include -#include -#include -#include -#include -#include - -#include "absl/base/attributes.h" -#include "absl/meta/type_traits.h" -#include "riegeli/base/any_dependency_internal.h" -#include "riegeli/base/dependency.h" -#include "riegeli/base/initializer.h" +#include "absl/base/macros.h" +#include "riegeli/base/any_initializer.h" namespace riegeli { -namespace any_dependency_internal { -template -class AnyDependencyBase; -} // namespace any_dependency_internal - -// A parameter of type `AnyDependencyInitializer` allows the caller -// to specify an `AnyDependency` by passing a value convertible to -// `AnyDependency`. -// -// In contrast to accepting `AnyDependency` directly, this allows to -// construct the object in-place, avoiding constructing a temporary and moving -// from it. This also avoids specifying `::Inlining<...>` in the interface while -// benefiting from that in the implementation. -// -// This is similar to `Initializer>`, except that it -// efficiently handles `AnyDependency` specializations with any inline -// storage constraints. -// -// `AnyDependencyInitializer(manager)` does not own `manager`, even if -// it involves temporaries, hence it should be used only as a parameter of a -// function or constructor, so that the temporaries outlive its usage. Instead -// of storing an `AnyDependencyInitializer` in a variable or returning -// it from a function, consider -// `riegeli::OwningMaker(manager_args...)`, -// `MakerTypeFor`, or `AnyDependency`. -template -class AnyDependencyInitializer { - public: - // An `AnyDependency` will be empty. - AnyDependencyInitializer() : construct_(ConstructMethodEmpty) {} - - // An `AnyDependency` will hold a - // `Dependency>`. - template , - AnyDependencyInitializer>>, - absl::disjunction< - any_dependency_internal::IsAnyDependency< - Handle, InitializerTargetT>, - IsValidDependency>>>::value, - int> = 0> - /*implicit*/ AnyDependencyInitializer( - Manager&& manager ABSL_ATTRIBUTE_LIFETIME_BOUND) - : construct_(ConstructMethod), - context_(const_cast*>(&manager)) {} - - AnyDependencyInitializer(AnyDependencyInitializer&& that) = default; - AnyDependencyInitializer& operator=(AnyDependencyInitializer&&) = delete; - - private: - // For `Construct()`. - template - friend class any_dependency_internal::AnyDependencyBase; - - using Storage = any_dependency_internal::Storage; - using MethodsAndHandle = any_dependency_internal::MethodsAndHandle; - using NullMethods = any_dependency_internal::NullMethods; - template - using MethodsFor = - any_dependency_internal::MethodsFor; - - static void ConstructMethodEmpty(void* context, - MethodsAndHandle& methods_and_handle, - Storage storage, size_t available_size, - size_t available_align); - - template >::value, - int> = 0> - static void ConstructMethod(void* context, - MethodsAndHandle& methods_and_handle, - Storage storage, size_t available_size, - size_t available_align); - template >::value, - int> = 0> - static void ConstructMethod(void* context, - MethodsAndHandle& methods_and_handle, - Storage storage, size_t available_size, - size_t available_align); - - // Constructs `methods_and_handle` and `storage` by moving from `*this`. - void Construct(MethodsAndHandle& methods_and_handle, Storage storage, - size_t available_size, size_t available_align) && { - construct_(context_, methods_and_handle, storage, available_size, - available_align); - } - - void (*construct_)(void* context, MethodsAndHandle& methods_and_handle, - Storage storage, size_t available_size, - size_t available_align); - void* context_ = nullptr; -}; - -// Implementation details follow. - -template -void AnyDependencyInitializer::ConstructMethodEmpty( - ABSL_ATTRIBUTE_UNUSED void* context, MethodsAndHandle& methods_and_handle, - ABSL_ATTRIBUTE_UNUSED Storage storage, - ABSL_ATTRIBUTE_UNUSED size_t available_size, - ABSL_ATTRIBUTE_UNUSED size_t available_align) { - methods_and_handle.methods = &NullMethods::kMethods; - new (&methods_and_handle.handle) - Handle(any_dependency_internal::SentinelHandle()); -} - -template -template >::value, - int>> -void AnyDependencyInitializer::ConstructMethod( - void* context, MethodsAndHandle& methods_and_handle, Storage storage, - size_t available_size, size_t available_align) { - using Target = InitializerTargetT; - // This is equivalent to calling `MethodsFor::Construct()` - // or `MethodsFor::Construct()`. Separate allocation of - // `Dependency` from its construction, so that the code for - // construction can be shared between the two cases, reducing the code size. - const any_dependency_internal::Methods* methods_ptr; - Dependency* dep_ptr; - bool constructed = false; - if (any_dependency_internal::ReprIsInline(available_size, - available_align)) { - methods_ptr = &MethodsFor::kMethods; - dep_ptr = reinterpret_cast*>(storage); - } else { - methods_ptr = &MethodsFor::kMethods; -#if __cpp_aligned_new - if (alignof(Dependency) > - __STDCPP_DEFAULT_NEW_ALIGNMENT__) { - dep_ptr = static_cast*>(operator new( - sizeof(Dependency), - std::align_val_t(alignof(Dependency)))); - } -#else -#ifdef __STDCPP_DEFAULT_NEW_ALIGNMENT__ - constexpr size_t kDefaultNewAlignment = __STDCPP_DEFAULT_NEW_ALIGNMENT__; -#else - constexpr size_t kDefaultNewAlignment = alignof(max_align_t); -#endif - if (alignof(Dependency) > kDefaultNewAlignment) { - // Factoring out the code constructing `Dependency` is - // not feasible. - dep_ptr = new Dependency(std::forward( - *static_cast*>(context))); - constructed = true; - } -#endif - else { - dep_ptr = static_cast*>(operator new( - sizeof(Dependency))); - } - new (storage) Dependency*(dep_ptr); - } - methods_and_handle.methods = methods_ptr; - if (!constructed) { - new (dep_ptr) Dependency(std::forward( - *static_cast*>(context))); - } - new (&methods_and_handle.handle) Handle(dep_ptr->get()); -} - template -template >::value, - int>> -void AnyDependencyInitializer::ConstructMethod( - void* context, MethodsAndHandle& methods_and_handle, Storage storage, - size_t available_size, size_t available_align) { - using Target = InitializerTargetT; - // Materialize `Target` to consider adopting its storage. - [&](Target&& target) { - // `target.methods_and_handle_.methods->used_size <= - // Target::kAvailableSize`, hence if `Target::kAvailableSize == 0` then - // `target.methods_and_handle_.methods->used_size <= available_size`. - // No need to check possibly at runtime. - if ((Target::kAvailableSize == 0 || - target.methods_and_handle_.methods->used_size <= available_size) && - // Same for alignment. - (Target::kAvailableAlign == 0 || - target.methods_and_handle_.methods->used_align <= available_align)) { - // Adopt `target` instead of wrapping it. - if (Target::kAvailableSize == 0) { - // Replace an indirect call to `methods_and_handle_.methods->move()` - // with a plain assignment of `methods_and_handle_.handle` and a memory - // copy of `repr_`. - // - // This would safe whenever - // `target.methods_and_handle_.methods->used_size == 0`, but this is - // handled specially only if the condition can be determined at compile - // time. - methods_and_handle.methods = std::exchange( - target.methods_and_handle_.methods, &NullMethods::kMethods); - methods_and_handle.handle = - std::exchange(target.methods_and_handle_.handle, - any_dependency_internal::SentinelHandle()); - std::memcpy(storage, &target.repr_, sizeof(target.repr_)); - } else { - target.methods_and_handle_.handle = - any_dependency_internal::SentinelHandle(); - methods_and_handle.methods = std::exchange( - target.methods_and_handle_.methods, &NullMethods::kMethods); - methods_and_handle.methods->move(storage, &methods_and_handle.handle, - target.repr_.storage); - } - return; - } - methods_and_handle.methods = - &MethodsFor::kMethods; - // `std::move(target)` is correct and `std::forward(target)` is not - // necessary: `Target` is always an `AnyDependency`, never an lvalue - // reference. - MethodsFor::Construct( - storage, &methods_and_handle.handle, std::move(target)); - }(Initializer>( - std::forward( - *static_cast*>(context))) - .Reference()); -} +using AnyDependencyInitializer ABSL_DEPRECATE_AND_INLINE() = + AnyInitializer; } // namespace riegeli diff --git a/riegeli/base/any_initializer.h b/riegeli/base/any_initializer.h new file mode 100644 index 00000000..c939faaa --- /dev/null +++ b/riegeli/base/any_initializer.h @@ -0,0 +1,258 @@ +// Copyright 2022 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef RIEGELI_BASE_ANY_INITIALIZER_H_ +#define RIEGELI_BASE_ANY_INITIALIZER_H_ + +#include + +#include +#include +#include +#include +#include +#include + +#include "absl/base/attributes.h" +#include "absl/meta/type_traits.h" +#include "riegeli/base/any_internal.h" +#include "riegeli/base/dependency.h" +#include "riegeli/base/initializer.h" + +namespace riegeli { + +namespace any_internal { +template +class AnyBase; +} // namespace any_internal + +// A parameter of type `AnyInitializer` allows the caller to specify an +// `Any` by passing a value convertible to `Any`. +// +// In contrast to accepting `Any` directly, this allows to construct the +// object in-place, avoiding constructing a temporary and moving from it. This +// also avoids specifying `::Inlining<...>` in the interface while benefiting +// from that in the implementation. +// +// This is similar to `Initializer>`, except that it efficiently +// handles `Any` specializations with any inline storage constraints. +// +// `AnyInitializer(manager)` does not own `manager`, even if it involves +// temporaries, hence it should be used only as a parameter of a function or +// constructor, so that the temporaries outlive its usage. Instead of storing an +// `AnyInitializer` in a variable or returning it from a function, +// consider `riegeli::OwningMaker(manager_args...)`, +// `MakerTypeFor`, or `Any`. +template +class AnyInitializer { + public: + // An `Any` will be empty. + AnyInitializer() : construct_(ConstructMethodEmpty) {} + + // An `Any` will hold a `Dependency>`. + template < + typename Manager, + std::enable_if_t< + absl::conjunction< + absl::negation< + std::is_same, AnyInitializer>>, + absl::disjunction< + any_internal::IsAny>, + IsValidDependency>>>:: + value, + int> = 0> + /*implicit*/ AnyInitializer(Manager&& manager ABSL_ATTRIBUTE_LIFETIME_BOUND) + : construct_(ConstructMethod), + context_(const_cast*>(&manager)) {} + + AnyInitializer(AnyInitializer&& that) = default; + AnyInitializer& operator=(AnyInitializer&&) = delete; + + private: + // For `Construct()`. + template + friend class any_internal::AnyBase; + + using Storage = any_internal::Storage; + using MethodsAndHandle = any_internal::MethodsAndHandle; + using NullMethods = any_internal::NullMethods; + template + using MethodsFor = any_internal::MethodsFor; + + static void ConstructMethodEmpty(void* context, + MethodsAndHandle& methods_and_handle, + Storage storage, size_t available_size, + size_t available_align); + + template >::value, + int> = 0> + static void ConstructMethod(void* context, + MethodsAndHandle& methods_and_handle, + Storage storage, size_t available_size, + size_t available_align); + template >::value, + int> = 0> + static void ConstructMethod(void* context, + MethodsAndHandle& methods_and_handle, + Storage storage, size_t available_size, + size_t available_align); + + // Constructs `methods_and_handle` and `storage` by moving from `*this`. + void Construct(MethodsAndHandle& methods_and_handle, Storage storage, + size_t available_size, size_t available_align) && { + construct_(context_, methods_and_handle, storage, available_size, + available_align); + } + + void (*construct_)(void* context, MethodsAndHandle& methods_and_handle, + Storage storage, size_t available_size, + size_t available_align); + void* context_ = nullptr; +}; + +// Implementation details follow. + +template +void AnyInitializer::ConstructMethodEmpty( + ABSL_ATTRIBUTE_UNUSED void* context, MethodsAndHandle& methods_and_handle, + ABSL_ATTRIBUTE_UNUSED Storage storage, + ABSL_ATTRIBUTE_UNUSED size_t available_size, + ABSL_ATTRIBUTE_UNUSED size_t available_align) { + methods_and_handle.methods = &NullMethods::kMethods; + new (&methods_and_handle.handle) + Handle(any_internal::SentinelHandle()); +} + +template +template < + typename Manager, + std::enable_if_t< + !any_internal::IsAny>::value, int>> +void AnyInitializer::ConstructMethod( + void* context, MethodsAndHandle& methods_and_handle, Storage storage, + size_t available_size, size_t available_align) { + using Target = InitializerTargetT; + // This is equivalent to calling `MethodsFor::Construct()` + // or `MethodsFor::Construct()`. Separate allocation of + // `Dependency` from its construction, so that the code for + // construction can be shared between the two cases, reducing the code size. + const any_internal::Methods* methods_ptr; + Dependency* dep_ptr; + bool constructed = false; + if (any_internal::ReprIsInline(available_size, + available_align)) { + methods_ptr = &MethodsFor::kMethods; + dep_ptr = reinterpret_cast*>(storage); + } else { + methods_ptr = &MethodsFor::kMethods; +#if __cpp_aligned_new + if (alignof(Dependency) > + __STDCPP_DEFAULT_NEW_ALIGNMENT__) { + dep_ptr = static_cast*>(operator new( + sizeof(Dependency), + std::align_val_t(alignof(Dependency)))); + } +#else +#ifdef __STDCPP_DEFAULT_NEW_ALIGNMENT__ + constexpr size_t kDefaultNewAlignment = __STDCPP_DEFAULT_NEW_ALIGNMENT__; +#else + constexpr size_t kDefaultNewAlignment = alignof(max_align_t); +#endif + if (alignof(Dependency) > kDefaultNewAlignment) { + // Factoring out the code constructing `Dependency` is + // not feasible. + dep_ptr = new Dependency(std::forward( + *static_cast*>(context))); + constructed = true; + } +#endif + else { + dep_ptr = static_cast*>(operator new( + sizeof(Dependency))); + } + new (storage) Dependency*(dep_ptr); + } + methods_and_handle.methods = methods_ptr; + if (!constructed) { + new (dep_ptr) Dependency(std::forward( + *static_cast*>(context))); + } + new (&methods_and_handle.handle) Handle(dep_ptr->get()); +} + +template +template < + typename Manager, + std::enable_if_t< + any_internal::IsAny>::value, int>> +void AnyInitializer::ConstructMethod( + void* context, MethodsAndHandle& methods_and_handle, Storage storage, + size_t available_size, size_t available_align) { + using Target = InitializerTargetT; + // Materialize `Target` to consider adopting its storage. + [&](Target&& target) { + // `target.methods_and_handle_.methods->used_size <= + // Target::kAvailableSize`, hence if `Target::kAvailableSize == 0` then + // `target.methods_and_handle_.methods->used_size <= available_size`. + // No need to check possibly at runtime. + if ((Target::kAvailableSize == 0 || + target.methods_and_handle_.methods->used_size <= available_size) && + // Same for alignment. + (Target::kAvailableAlign == 0 || + target.methods_and_handle_.methods->used_align <= available_align)) { + // Adopt `target` instead of wrapping it. + if (Target::kAvailableSize == 0) { + // Replace an indirect call to `methods_and_handle_.methods->move()` + // with a plain assignment of `methods_and_handle_.handle` and a memory + // copy of `repr_`. + // + // This would safe whenever + // `target.methods_and_handle_.methods->used_size == 0`, but this is + // handled specially only if the condition can be determined at compile + // time. + methods_and_handle.methods = std::exchange( + target.methods_and_handle_.methods, &NullMethods::kMethods); + methods_and_handle.handle = + std::exchange(target.methods_and_handle_.handle, + any_internal::SentinelHandle()); + std::memcpy(storage, &target.repr_, sizeof(target.repr_)); + } else { + target.methods_and_handle_.handle = + any_internal::SentinelHandle(); + methods_and_handle.methods = std::exchange( + target.methods_and_handle_.methods, &NullMethods::kMethods); + methods_and_handle.methods->move(storage, &methods_and_handle.handle, + target.repr_.storage); + } + return; + } + methods_and_handle.methods = + &MethodsFor::kMethods; + // `std::move(target)` is correct and `std::forward(target)` is not + // necessary: `Target` is always an `Any`, never an lvalue reference. + MethodsFor::Construct( + storage, &methods_and_handle.handle, std::move(target)); + }(Initializer>( + std::forward( + *static_cast*>(context))) + .Reference()); +} + +} // namespace riegeli + +#endif // RIEGELI_BASE_ANY_INITIALIZER_H_ diff --git a/riegeli/base/any_dependency_internal.h b/riegeli/base/any_internal.h similarity index 91% rename from riegeli/base/any_dependency_internal.h rename to riegeli/base/any_internal.h index 26ed0c45..29d1fb8b 100644 --- a/riegeli/base/any_dependency_internal.h +++ b/riegeli/base/any_internal.h @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef RIEGELI_BASE_ANY_DEPENDENCY_INTERNAL_H_ -#define RIEGELI_BASE_ANY_DEPENDENCY_INTERNAL_H_ +#ifndef RIEGELI_BASE_ANY_INTERNAL_H_ +#define RIEGELI_BASE_ANY_INTERNAL_H_ #include @@ -36,14 +36,14 @@ namespace riegeli { template -class AnyDependency; +class Any; template -class AnyDependencyRef; +class AnyRef; -namespace any_dependency_internal { +namespace any_internal { // Variants of `Repr`: -// * Empty `AnyDependency`: `Repr` is not used +// * Empty `Any`: `Repr` is not used // * Stored inline: `storage` holds `Dependency` // * Held by pointer: `storage` holds `Dependency*` template @@ -60,21 +60,21 @@ using Storage = char[]; // A `Dependency` is stored inline in // `Repr` if it is movable and it fits there. // -// If `inline_size == 0`, the dependency is also required to be stable -// (because then `AnyDependency` declares itself stable) and trivially -// relocatable (because then `AnyDependency` declares itself with trivial ABI -// and optimizes moving to a plain memory copy of the representation). +// If `inline_size == 0`, the dependency is also required to be stable (because +// then `Any` declares itself stable) and trivially relocatable (because then +// `Any` declares itself with trivial ABI and optimizes moving to a plain memory +// copy of the representation). -// Properties of inline storage in an `AnyDepenency` instance are expressed as -// two numbers: `available_size` and `available_align`, while constraints of a +// Properties of inline storage in an `Any` instance are expressed as two +// numbers: `available_size` and `available_align`, while constraints of a // movable `Dependency` instance on its storage are expressed as two numbers: // `used_size` and `used_align`, such that // `used_size <= available_size && used_align <= available_align` implies that -// the movable `Dependency` can be stored inline in the `AnyDependency`. +// the movable `Dependency` can be stored inline in the `Any`. // // This formulation allows reevaluating the condition with different values of // `available_size` and `available_align` when considering adopting the storage -// for a different `AnyDependency` instance, at either compile time or runtime. +// for a different `Any` instance, at either compile time or runtime. // Returns `available_size`: `sizeof` the storage, except that 0 indicates // `inline_size == 0`, which means the minimal size of any inline storage with @@ -193,17 +193,16 @@ struct MethodsFor; template struct NullMethods; -// `IsAnyDependency` detects `AnyDependency` or `AnyDependencyRef` type with the -// given `Handle`. +// `IsAny` detects `Any` or `AnyRef` type with the given `Handle`. template -struct IsAnyDependency : std::false_type {}; +struct IsAny : std::false_type {}; template -struct IsAnyDependency> - : std::true_type {}; +struct IsAny> : std::true_type { +}; template -struct IsAnyDependency> : std::true_type {}; +struct IsAny> : std::true_type {}; // Implementation details follow. @@ -365,7 +364,7 @@ template constexpr Methods MethodsFor::kMethods; #endif -} // namespace any_dependency_internal +} // namespace any_internal } // namespace riegeli -#endif // RIEGELI_BASE_ANY_DEPENDENCY_INTERNAL_H_ +#endif // RIEGELI_BASE_ANY_INTERNAL_H_ diff --git a/riegeli/base/closing_ptr.h b/riegeli/base/closing_ptr.h index 0ad0c8af..b72a690d 100644 --- a/riegeli/base/closing_ptr.h +++ b/riegeli/base/closing_ptr.h @@ -31,7 +31,7 @@ struct NullDeleter { // object when done with the pointer, even though the object is not moved nor // destroyed. // -// In the context of `Dependency` and `AnyDependency`, passing `ClosingPtr(&m)` +// In the context of `Dependency` and `Any`, passing `ClosingPtr(&m)` // instead of `std::move(m)` avoids moving `m`, but the caller must ensure that // the dependent object is valid while the host object needs it. diff --git a/riegeli/base/dependency.h b/riegeli/base/dependency.h index 4e208e85..ca8ed365 100644 --- a/riegeli/base/dependency.h +++ b/riegeli/base/dependency.h @@ -41,7 +41,7 @@ namespace riegeli { // // Often `Handle` is some pointer `Base*`, and then `Manager` can be e.g. // `T` (owned), `T*` (not owned), `std::unique_ptr` (owned), -// or `AnyDependency` (maybe owned), with some `T` derived from `Base`. +// or `Any` (maybe owned), with some `T` derived from `Base`. // // Often `Dependency` is a member of a host class template // parameterized by `Manager`, with `Handle` fixed by the host class. The member @@ -196,9 +196,9 @@ namespace riegeli { // static constexpr bool kIsStable; // // // If the `Manager` has exactly this type or a reference to it, returns -// // a pointer to the `Manager`. If the `Manager` is an `AnyDependency` -// // (possibly wrapped in a reference or `std::unique_ptr`), propagates -// // `GetIf()` to it. Otherwise returns `nullptr`. +// // a pointer to the `Manager`. If the `Manager` is an `Any` (possibly +// // wrapped in a reference or `std::unique_ptr`), propagates `GetIf()` +// // to it. Otherwise returns `nullptr`. // // // // Provided by `DependencyManagerImpl`, `DependencyImpl`, or `Dependency`. // // In `Dependency` implemented in terms of `GetIf(TypeId)` if that is diff --git a/riegeli/base/dependency_base.h b/riegeli/base/dependency_base.h index 8f139b34..06ba10af 100644 --- a/riegeli/base/dependency_base.h +++ b/riegeli/base/dependency_base.h @@ -28,7 +28,7 @@ namespace riegeli { // `RiegeliDependencySentinel(T*)` specifies how to initialize a default -// `Manager` (for `Dependency`) or `Handle` (for `AnyDependency`) of type `T`. +// `Manager` (for `Dependency`) or `Handle` (for `Any`) of type `T`. // // To customize that for a class `T`, define a free function // `friend Result RiegeliDependencySentinel(T*)` as a friend of `T` inside class diff --git a/riegeli/base/dependency_manager.h b/riegeli/base/dependency_manager.h index f888b128..3f8228f2 100644 --- a/riegeli/base/dependency_manager.h +++ b/riegeli/base/dependency_manager.h @@ -40,7 +40,7 @@ namespace riegeli { // * `std::nullptr_t DependencyManager::ptr()` // * `T* DependencyManager>::ptr()` // * `T* DependencyManager>::ptr()` -// * `Handle DependencyManager>::ptr()` +// * `Handle DependencyManager>::ptr()` // // `DependencyManager` derives from // `DependencyManagerImpl` (where `ManagerStorage` is @@ -84,7 +84,7 @@ class DependencyManagerImpl : public DependencyBase { // Specialization of `DependencyManagerImpl`: // an unowned dependency stored by pointer, always missing. This is useful for -// `AnyDependency` and `AnyDependencyRef`. +// `Any` and `AnyRef`. template class DependencyManagerImpl : public DependencyBase { diff --git a/riegeli/brotli/brotli_reader.h b/riegeli/brotli/brotli_reader.h index 90b70185..92bd0aea 100644 --- a/riegeli/brotli/brotli_reader.h +++ b/riegeli/brotli/brotli_reader.h @@ -140,7 +140,7 @@ class BrotliReaderBase : public PullableReader { // possibly owning the compressed `Reader`. `Src` must support // `Dependency`, e.g. `Reader*` (not owned, default), // `ChainReader<>` (owned), `std::unique_ptr` (owned), -// `AnyDependency` (maybe owned). +// `Any` (maybe owned). // // By relying on CTAD the template argument can be deduced as // `InitializerTargetT` of the type of the first constructor argument. diff --git a/riegeli/brotli/brotli_writer.h b/riegeli/brotli/brotli_writer.h index 42582e8e..76817d8e 100644 --- a/riegeli/brotli/brotli_writer.h +++ b/riegeli/brotli/brotli_writer.h @@ -188,7 +188,7 @@ class BrotliWriterBase : public BufferedWriter { // possibly owning the compressed `Writer`. `Dest` must support // `Dependency`, e.g. `Writer*` (not owned, default), // `ChainWriter<>` (owned), `std::unique_ptr` (owned), -// `AnyDependency` (maybe owned). +// `Any` (maybe owned). // // By relying on CTAD the template argument can be deduced as // `InitializerTargetT` of the type of the first constructor argument. diff --git a/riegeli/bytes/BUILD b/riegeli/bytes/BUILD index 96975132..32547f3a 100644 --- a/riegeli/bytes/BUILD +++ b/riegeli/bytes/BUILD @@ -1007,7 +1007,7 @@ cc_library( srcs = ["fd_handle.cc"], hdrs = ["fd_handle.h"], deps = [ - "//riegeli/base:any_dependency", + "//riegeli/base:any", "//riegeli/base:compare", "//riegeli/base:status", "@com_google_absl//absl/base:core_headers", @@ -1274,7 +1274,7 @@ cc_library( # included files provide. features = ["-use_header_modules"], deps = [ - "//riegeli/base:any_dependency", + "//riegeli/base:any", "//riegeli/base:compare", "//riegeli/base:status", "@com_google_absl//absl/base:core_headers", diff --git a/riegeli/bytes/array_backward_writer.h b/riegeli/bytes/array_backward_writer.h index fc0a0998..2c68bd06 100644 --- a/riegeli/bytes/array_backward_writer.h +++ b/riegeli/bytes/array_backward_writer.h @@ -82,7 +82,7 @@ class ArrayBackwardWriterBase : public PushableBackwardWriter { // possibly owning the array being written to. `Dest` must support // `Dependency, Dest>`, e.g. // `absl::Span` (not owned, default), `std::string*` (not owned), -// `std::string` (owned), `AnyDependency>` (maybe owned). +// `std::string` (owned), `Any>` (maybe owned). // // By relying on CTAD the template argument can be deduced as // `InitializerTargetT` of the type of the first constructor argument, except diff --git a/riegeli/bytes/array_writer.h b/riegeli/bytes/array_writer.h index 271ca8b3..5073e8da 100644 --- a/riegeli/bytes/array_writer.h +++ b/riegeli/bytes/array_writer.h @@ -102,7 +102,7 @@ class ArrayWriterBase : public PushableWriter { // possibly owning the array being written to. `Dest` must support // `Dependency, Dest>`, e.g. // `absl::Span` (not owned, default), `std::string*` (not owned), -// `std::string` (owned), `AnyDependency>` (maybe owned). +// `std::string` (owned), `Any>` (maybe owned). // // By relying on CTAD the template argument can be deduced as // `InitializerTargetT` of the type of the first constructor argument, except diff --git a/riegeli/bytes/cfile_handle.h b/riegeli/bytes/cfile_handle.h index feb3dd63..c15a96c5 100644 --- a/riegeli/bytes/cfile_handle.h +++ b/riegeli/bytes/cfile_handle.h @@ -27,7 +27,7 @@ #include "absl/meta/type_traits.h" #include "absl/status/status.h" #include "absl/strings/string_view.h" -#include "riegeli/base/any_dependency.h" +#include "riegeli/base/any.h" #include "riegeli/base/compare.h" namespace riegeli { @@ -316,7 +316,7 @@ constexpr CFileHandle::Methods CFileHandle::kMethods; // Type-erased object like `OwnedCFile` or `UnownedCFile` which stores and // possibly owns a `FILE*`. -using AnyCFile = AnyDependency::Inlining; +using AnyCFile = Any::Inlining; } // namespace riegeli diff --git a/riegeli/bytes/chain_backward_writer.h b/riegeli/bytes/chain_backward_writer.h index f7307424..9d98c3b9 100644 --- a/riegeli/bytes/chain_backward_writer.h +++ b/riegeli/bytes/chain_backward_writer.h @@ -162,7 +162,7 @@ class ChainBackwardWriterBase : public BackwardWriter { // The `Dest` template parameter specifies the type of the object providing and // possibly owning the `Chain` being written to. `Dest` must support // `Dependency`, e.g. `Chain*` (not owned, default), -// `Chain` (owned), `AnyDependency` (maybe owned). +// `Chain` (owned), `Any` (maybe owned). // // By relying on CTAD the template argument can be deduced as `Chain` if there // are no constructor arguments or the only argument is `Options`, otherwise as diff --git a/riegeli/bytes/chain_reader.h b/riegeli/bytes/chain_reader.h index 15b93fa6..4614e735 100644 --- a/riegeli/bytes/chain_reader.h +++ b/riegeli/bytes/chain_reader.h @@ -91,7 +91,7 @@ class ChainReaderBase : public PullableReader { // The `Src` template parameter specifies the type of the object providing and // possibly owning the `Chain` being read from. `Src` must support // `Dependency`, e.g. `const Chain*` (not owned, default), -// `Chain` (owned), `AnyDependency` (maybe owned). +// `Chain` (owned), `Any` (maybe owned). // // By relying on CTAD the template argument can be deduced as // `InitializerTargetT` of the type of the first constructor argument. diff --git a/riegeli/bytes/chain_writer.h b/riegeli/bytes/chain_writer.h index 87e4efe6..126bbbaa 100644 --- a/riegeli/bytes/chain_writer.h +++ b/riegeli/bytes/chain_writer.h @@ -221,7 +221,7 @@ class ChainWriterBase : public Writer { // The `Dest` template parameter specifies the type of the object providing and // possibly owning the `Chain` being written to. `Dest` must support // `Dependency`, e.g. `Chain*` (not owned, default), -// `Chain` (owned), `AnyDependency` (maybe owned). +// `Chain` (owned), `Any` (maybe owned). // // By relying on CTAD the template argument can be deduced as `Chain` if there // are no constructor arguments or the only argument is `Options`, otherwise as diff --git a/riegeli/bytes/compact_string_writer.h b/riegeli/bytes/compact_string_writer.h index 4ce3ba32..e31f60bf 100644 --- a/riegeli/bytes/compact_string_writer.h +++ b/riegeli/bytes/compact_string_writer.h @@ -76,7 +76,7 @@ using CompactStringWriterBase = ResizableWriterBase; // possibly owning the `CompactString` being written to. `Dest` must support // `Dependency`, e.g. // `CompactString*` (not owned, default), `CompactString` (owned), -// `AnyDependency` (maybe owned). +// `Any` (maybe owned). // // By relying on CTAD the template argument can be deduced as `CompactString` // if there are no constructor arguments or the only argument is `Options`, diff --git a/riegeli/bytes/copy_all.h b/riegeli/bytes/copy_all.h index 149fd536..c28fb522 100644 --- a/riegeli/bytes/copy_all.h +++ b/riegeli/bytes/copy_all.h @@ -54,13 +54,13 @@ namespace riegeli { // possibly owning the `Reader`. `Src` must support // `Dependency`, e.g. `Reader&` (not owned), // `ChainReader<>` (owned), `std::unique_ptr` (owned), -// `AnyDependency` (maybe owned). +// `Any` (maybe owned). // // The `Dest` template parameter specifies the type of the object providing and // possibly owning the `Writer` / `BackwardWriter`. `Dest` must support // `Dependency`, e.g. `Writer&` (not owned), // `ChainWriter<>` (owned). `std::unique_ptr` (owned), -// `AnyDependency` (maybe owned). Analogously for `BackwardWriter`. +// `Any` (maybe owned). Analogously for `BackwardWriter`. template , diff --git a/riegeli/bytes/cord_backward_writer.h b/riegeli/bytes/cord_backward_writer.h index 222e0527..e85e6510 100644 --- a/riegeli/bytes/cord_backward_writer.h +++ b/riegeli/bytes/cord_backward_writer.h @@ -172,7 +172,7 @@ class CordBackwardWriterBase : public BackwardWriter { // The `Dest` template parameter specifies the type of the object providing and // possibly owning the `absl::Cord` being written to. `Dest` must support // `Dependency`, e.g. `absl::Cord*` (not owned, default), -// `absl::Cord` (owned), `AnyDependency` (maybe owned). +// `absl::Cord` (owned), `Any` (maybe owned). // // By relying on CTAD the template argument can be deduced as `absl::Cord` // if there are no constructor arguments or the only argument is `Options`, diff --git a/riegeli/bytes/cord_reader.h b/riegeli/bytes/cord_reader.h index db6afc44..26ab2f66 100644 --- a/riegeli/bytes/cord_reader.h +++ b/riegeli/bytes/cord_reader.h @@ -117,7 +117,7 @@ class CordReaderBase : public PullableReader { // possibly owning the `absl::Cord` being read from. `Src` must support // `Dependency`, e.g. // `const absl::Cord*` (not owned, default), `absl::Cord` (owned), -// `AnyDependency` (maybe owned). +// `Any` (maybe owned). // // By relying on CTAD the template argument can be deduced as // `InitializerTargetT` of the type of the first constructor argument. diff --git a/riegeli/bytes/cord_writer.h b/riegeli/bytes/cord_writer.h index 93d0afc9..41b4239c 100644 --- a/riegeli/bytes/cord_writer.h +++ b/riegeli/bytes/cord_writer.h @@ -231,7 +231,7 @@ class CordWriterBase : public Writer { // The `Dest` template parameter specifies the type of the object providing and // possibly owning the `absl::Cord` being written to. `Dest` must support // `Dependency`, e.g. `absl::Cord*` (not owned, default), -// `absl::Cord` (owned), `AnyDependency` (maybe owned). +// `absl::Cord` (owned), `Any` (maybe owned). // // By relying on CTAD the template argument can be deduced as `absl::Cord` // if there are no constructor arguments or the only argument is `Options`, diff --git a/riegeli/bytes/fd_handle.h b/riegeli/bytes/fd_handle.h index 20ad9bda..42dadbae 100644 --- a/riegeli/bytes/fd_handle.h +++ b/riegeli/bytes/fd_handle.h @@ -30,7 +30,7 @@ #include "absl/meta/type_traits.h" #include "absl/status/status.h" #include "absl/strings/string_view.h" -#include "riegeli/base/any_dependency.h" +#include "riegeli/base/any.h" #include "riegeli/base/compare.h" namespace riegeli { @@ -340,7 +340,7 @@ constexpr FdHandle::Methods FdHandle::kMethods; // Type-erased object like `OwnedFd` or `UnownedFd` which stores and possibly // owns a fd. -using AnyFd = AnyDependency::Inlining; +using AnyFd = Any::Inlining; } // namespace riegeli diff --git a/riegeli/bytes/istream_reader.h b/riegeli/bytes/istream_reader.h index a8b01209..ffb05f5f 100644 --- a/riegeli/bytes/istream_reader.h +++ b/riegeli/bytes/istream_reader.h @@ -131,7 +131,7 @@ class IStreamReaderBase : public BufferedReader { // possibly owning the stream being read from. `Src` must support // `Dependency`, e.g. `std::istream*` (not owned, default), // `std::ifstream` (owned), `std::unique_ptr` (owned), -// `AnyDependency` (maybe owned). +// `Any` (maybe owned). // // By relying on CTAD the template argument can be deduced as // `InitializerTargetT` of the type of the first constructor argument. diff --git a/riegeli/bytes/limiting_backward_writer.h b/riegeli/bytes/limiting_backward_writer.h index 71732739..ba244386 100644 --- a/riegeli/bytes/limiting_backward_writer.h +++ b/riegeli/bytes/limiting_backward_writer.h @@ -207,7 +207,7 @@ class LimitingBackwardWriterBase : public BackwardWriter { // `Dependency`, e.g. // `BackwardWriter*` (not owned, default), // `ChainBackwardWriter<>` (owned), `std::unique_ptr` (owned), -// `AnyDependency` (maybe owned). +// `Any` (maybe owned). // // By relying on CTAD the template argument can be deduced as // `InitializerTargetT` of the type of the first constructor argument. diff --git a/riegeli/bytes/limiting_reader.h b/riegeli/bytes/limiting_reader.h index cb817618..bd57c3da 100644 --- a/riegeli/bytes/limiting_reader.h +++ b/riegeli/bytes/limiting_reader.h @@ -282,7 +282,7 @@ class LimitingReaderBase : public Reader { // possibly owning the original `Reader`. `Src` must support // `Dependency`, e.g. `Reader*` (not owned, default), // `ChainReader<>` (owned), `std::unique_ptr` (owned), -// `AnyDependency` (maybe owned). +// `Any` (maybe owned). // // By relying on CTAD the template argument can be deduced as // `InitializerTargetT` of the type of the first constructor argument. diff --git a/riegeli/bytes/limiting_writer.h b/riegeli/bytes/limiting_writer.h index 9a90f54b..460d29ee 100644 --- a/riegeli/bytes/limiting_writer.h +++ b/riegeli/bytes/limiting_writer.h @@ -211,7 +211,7 @@ class LimitingWriterBase : public Writer { // possibly owning the original `Writer`. `Dest` must support // `Dependency`, e.g. `Writer*` (not owned, default), // `ChainWriter<>` (owned), `std::unique_ptr` (owned), -// `AnyDependency` (maybe owned). +// `Any` (maybe owned). // // By relying on CTAD the template argument can be deduced as // `InitializerTargetT` of the type of the first constructor argument. diff --git a/riegeli/bytes/ostream_writer.h b/riegeli/bytes/ostream_writer.h index 24c549f0..9fb0d700 100644 --- a/riegeli/bytes/ostream_writer.h +++ b/riegeli/bytes/ostream_writer.h @@ -157,7 +157,7 @@ class OStreamWriterBase : public BufferedWriter { // possibly owning the stream being written to. `Dest` must support // `Dependency`, e.g. `std::ostream*` (not owned, default), // `std::ofstream` (owned), `std::unique_ptr` (owned), -// `AnyDependency` (maybe owned). +// `Any` (maybe owned). // // By relying on CTAD the template argument can be deduced as // `InitializerTargetT` of the type of the first constructor argument. diff --git a/riegeli/bytes/position_shifting_reader.h b/riegeli/bytes/position_shifting_reader.h index 3632cbab..63fe8fd5 100644 --- a/riegeli/bytes/position_shifting_reader.h +++ b/riegeli/bytes/position_shifting_reader.h @@ -142,7 +142,7 @@ class PositionShiftingReaderBase : public Reader { // possibly owning the original `Reader`. `Src` must support // `Dependency`, e.g. `Reader*` (not owned, default), // `ChainReader<>` (owned), `std::unique_ptr` (owned), -// `AnyDependency` (maybe owned). +// `Any` (maybe owned). // // By relying on CTAD the template argument can be deduced as // `InitializerTargetT` of the type of the first constructor argument. diff --git a/riegeli/bytes/position_shifting_writer.h b/riegeli/bytes/position_shifting_writer.h index f1dcac3d..f16a8511 100644 --- a/riegeli/bytes/position_shifting_writer.h +++ b/riegeli/bytes/position_shifting_writer.h @@ -141,7 +141,7 @@ class PositionShiftingWriterBase : public Writer { // possibly owning the original `Writer`. `Dest` must support // `Dependency`, e.g. `Writer*` (not owned, default), // `ChainWriter<>` (owned), `std::unique_ptr` (owned), -// `AnyDependency` (maybe owned). +// `Any` (maybe owned). // // By relying on CTAD the template argument can be deduced as // `InitializerTargetT` of the type of the first constructor argument. diff --git a/riegeli/bytes/prefix_limiting_reader.h b/riegeli/bytes/prefix_limiting_reader.h index bb564822..a77b7e86 100644 --- a/riegeli/bytes/prefix_limiting_reader.h +++ b/riegeli/bytes/prefix_limiting_reader.h @@ -139,7 +139,7 @@ class PrefixLimitingReaderBase : public Reader { // possibly owning the original `Reader`. `Src` must support // `Dependency`, e.g. `Reader*` (not owned, default), // `ChainReader<>` (owned), `std::unique_ptr` (owned), -// `AnyDependency` (maybe owned). +// `Any` (maybe owned). // // By relying on CTAD the template argument can be deduced as // `InitializerTargetT` of the type of the first constructor argument. diff --git a/riegeli/bytes/prefix_limiting_writer.h b/riegeli/bytes/prefix_limiting_writer.h index 26c3afb6..e932c735 100644 --- a/riegeli/bytes/prefix_limiting_writer.h +++ b/riegeli/bytes/prefix_limiting_writer.h @@ -138,7 +138,7 @@ class PrefixLimitingWriterBase : public Writer { // possibly owning the original `Writer`. `Dest` must support // `Dependency`, e.g. `Writer*` (not owned, default), // `ChainWriter<>` (owned), `std::unique_ptr` (owned), -// `AnyDependency` (maybe owned). +// `Any` (maybe owned). // // By relying on CTAD the template argument can be deduced as // `InitializerTargetT` of the type of the first constructor argument. diff --git a/riegeli/bytes/read_all.h b/riegeli/bytes/read_all.h index 48db510c..56ca814e 100644 --- a/riegeli/bytes/read_all.h +++ b/riegeli/bytes/read_all.h @@ -53,7 +53,7 @@ using StringViewCallResult = // possibly owning the `Reader`. `Src` must support // `Dependency`, e.g. `Reader&` (not owned), // `ChainReader<>` (owned), `std::unique_ptr` (owned), -// `AnyDependency` (maybe owned). +// `Any` (maybe owned). // // Reading to `absl::string_view` is supported in two ways: // @@ -108,7 +108,7 @@ StatusOrMakerT> ReadAll( // possibly owning the `Reader`. `Src` must support // `Dependency`, e.g. `Reader&` (not owned), // `ChainReader<>` (owned), `std::unique_ptr` (owned), -// `AnyDependency` (maybe owned). +// `Any` (maybe owned). template ::value, int> = 0> absl::Status ReadAll(Src&& src, char* dest, size_t max_length, @@ -149,7 +149,7 @@ absl::Status ReadAll(Src&& src, absl::Cord& dest, size_t* length_read); // possibly owning the `Reader`. `Src` must support // `Dependency`, e.g. `Reader&` (not owned), // `ChainReader<>` (owned), `std::unique_ptr` (owned), -// `AnyDependency` (maybe owned). +// `Any` (maybe owned). template ::value, int> = 0> absl::Status ReadAndAppendAll( diff --git a/riegeli/bytes/reader_cfile.h b/riegeli/bytes/reader_cfile.h index e2940d41..800d55c4 100644 --- a/riegeli/bytes/reader_cfile.h +++ b/riegeli/bytes/reader_cfile.h @@ -48,7 +48,7 @@ class ReaderCFileOptions { // The `Src` template parameter specifies the type of the object providing and // possibly owning the `Reader`. `Src` must support `Dependency`, // e.g. `Reader*` (not owned), `ChainReader<>` (owned), -// `std::unique_ptr` (owned), `AnyDependency` (maybe owned). +// `std::unique_ptr` (owned), `Any` (maybe owned). // // `src` supports `riegeli::Maker(args...)` to construct `Src` in-place. // diff --git a/riegeli/bytes/reader_factory.h b/riegeli/bytes/reader_factory.h index ca5a2a55..ff1e3819 100644 --- a/riegeli/bytes/reader_factory.h +++ b/riegeli/bytes/reader_factory.h @@ -105,7 +105,7 @@ class ReaderFactoryBase : public Object { // possibly owning the original `Reader`. `Src` must support // `Dependency`, e.g. `Reader*` (not owned, default), // `ChainReader<>` (owned), `std::unique_ptr` (owned), -// `AnyDependency` (maybe owned). +// `Any` (maybe owned). // // By relying on CTAD the template argument can be deduced as // `InitializerTargetT` of the type of the first constructor argument. diff --git a/riegeli/bytes/reader_istream.h b/riegeli/bytes/reader_istream.h index 87f6fc06..08ff11a8 100644 --- a/riegeli/bytes/reader_istream.h +++ b/riegeli/bytes/reader_istream.h @@ -150,7 +150,7 @@ class ReaderIStreamBase : public std::istream { // The `Src` template parameter specifies the type of the object providing and // possibly owning the `Reader`. `Src` must support `Dependency`, // e.g. `Reader*` (not owned, default), `ChainReader<>` (owned), -// `std::unique_ptr` (owned), `AnyDependency` (maybe owned). +// `std::unique_ptr` (owned), `Any` (maybe owned). // // By relying on CTAD the template argument can be deduced as // `InitializerTargetT` of the type of the first constructor argument. diff --git a/riegeli/bytes/resizable_writer.h b/riegeli/bytes/resizable_writer.h index bf3e38fe..4696ac63 100644 --- a/riegeli/bytes/resizable_writer.h +++ b/riegeli/bytes/resizable_writer.h @@ -245,7 +245,7 @@ class ResizableWriterBase : public Writer { // `ResizableTraits::Resizable*` (not owned, default), // `ResizableTraits::Resizable` (owned), // `std::unique_ptr` (owned), -// `AnyDependency` (maybe owned). +// `Any` (maybe owned). // // The `ResizableTraits::Resizable` must not be accessed until the // `ResizableWriter` is closed or no longer used, except that it is allowed diff --git a/riegeli/bytes/string_reader.h b/riegeli/bytes/string_reader.h index 837c2da4..ace11ba7 100644 --- a/riegeli/bytes/string_reader.h +++ b/riegeli/bytes/string_reader.h @@ -72,7 +72,7 @@ class StringReaderBase : public Reader { // possibly owning the `std::string` or array being read from. `Src` must // support `Dependency`, e.g. // `absl::string_view` (not owned, default), `const std::string*` (not owned), -// `std::string` (owned), `AnyDependency` (maybe owned). +// `std::string` (owned), `Any` (maybe owned). // // By relying on CTAD the template argument can be deduced as // `absl::string_view` if there are no constructor arguments or if the first diff --git a/riegeli/bytes/string_writer.h b/riegeli/bytes/string_writer.h index 82fc3a0f..d0192378 100644 --- a/riegeli/bytes/string_writer.h +++ b/riegeli/bytes/string_writer.h @@ -184,7 +184,7 @@ class StringWriterBase : public Writer { // The `Dest` template parameter specifies the type of the object providing and // possibly owning the `std::string` being written to. `Dest` must support // `Dependency`, e.g. `std::string*` (not owned, default), -// `std::string` (owned), `AnyDependency` (maybe owned). +// `std::string` (owned), `Any` (maybe owned). // // By relying on CTAD the template argument can be deduced as `std::string` // if there are no constructor arguments or the only argument is `Options`, diff --git a/riegeli/bytes/wrapping_backward_writer.h b/riegeli/bytes/wrapping_backward_writer.h index f6245100..338443e3 100644 --- a/riegeli/bytes/wrapping_backward_writer.h +++ b/riegeli/bytes/wrapping_backward_writer.h @@ -92,7 +92,7 @@ class WrappingBackwardWriterBase : public BackwardWriter { // `Dependency`, e.g. // `BackwardWriter*` (not owned, default), // `ChainBackwardWriter<>` (owned), `std::unique_ptr` (owned), -// `AnyDependency` (maybe owned). +// `Any` (maybe owned). // // By relying on CTAD the template argument can be deduced as // `InitializerTargetT` of the type of the first constructor argument. diff --git a/riegeli/bytes/wrapping_reader.h b/riegeli/bytes/wrapping_reader.h index 126f964b..e8964960 100644 --- a/riegeli/bytes/wrapping_reader.h +++ b/riegeli/bytes/wrapping_reader.h @@ -103,7 +103,7 @@ class WrappingReaderBase : public Reader { // possibly owning the original `Reader`. `Src` must support // `Dependency`, e.g. `Reader*` (not owned, default), // `ChainReader<>` (owned), `std::unique_ptr` (owned), -// `AnyDependency` (maybe owned). +// `Any` (maybe owned). // // By relying on CTAD the template argument can be deduced as // `InitializerTargetT` of the type of the first constructor argument. diff --git a/riegeli/bytes/wrapping_writer.h b/riegeli/bytes/wrapping_writer.h index df8df74d..ee4d3cd6 100644 --- a/riegeli/bytes/wrapping_writer.h +++ b/riegeli/bytes/wrapping_writer.h @@ -97,7 +97,7 @@ class WrappingWriterBase : public Writer { // possibly owning the original `Writer`. `Dest` must support // `Dependency`, e.g. `Writer*` (not owned, default), // `ChainWriter<>` (owned), `std::unique_ptr` (owned), -// `AnyDependency` (maybe owned). +// `Any` (maybe owned). // // By relying on CTAD the template argument can be deduced as // `InitializerTargetT` of the type of the first constructor argument. diff --git a/riegeli/bytes/write.h b/riegeli/bytes/write.h index 0927c32f..9794b614 100644 --- a/riegeli/bytes/write.h +++ b/riegeli/bytes/write.h @@ -44,7 +44,7 @@ namespace riegeli { // `Writer` / `BackwardWriter`. `Dest` must support // `Dependency`, e.g. `Writer&` (not owned), // `ChainWriter<>` (owned). `std::unique_ptr` (owned), -// `AnyDependency` (maybe owned). Analogously for `BackwardWriter`. +// `Any` (maybe owned). Analogously for `BackwardWriter`. template `, e.g. `Writer*` (not owned), // `ChainWriter<>` (owned), `std::unique_ptr` (owned), -// `AnyDependency` (maybe owned). +// `Any` (maybe owned). // // `dest` supports `riegeli::Maker(args...)` to construct `Dest` in-place. // diff --git a/riegeli/bytes/writer_ostream.h b/riegeli/bytes/writer_ostream.h index 600ee574..534bb327 100644 --- a/riegeli/bytes/writer_ostream.h +++ b/riegeli/bytes/writer_ostream.h @@ -172,7 +172,7 @@ class WriterOStreamBase : public std::iostream { // possibly owning the `Writer`. `Dest` must support // `Dependency`, e.g. `Writer*` (not owned, default), // `ChainWriter<>` (owned), `std::unique_ptr` (owned), -// `AnyDependency` (maybe owned). +// `Any` (maybe owned). // // By relying on CTAD the template argument can be deduced as // `InitializerTargetT` of the type of the first constructor argument. diff --git a/riegeli/bzip2/bzip2_reader.h b/riegeli/bzip2/bzip2_reader.h index fd1046e5..47a4fbef 100644 --- a/riegeli/bzip2/bzip2_reader.h +++ b/riegeli/bzip2/bzip2_reader.h @@ -140,7 +140,7 @@ class Bzip2ReaderBase : public BufferedReader { // possibly owning the compressed `Reader`. `Src` must support // `Dependency`, e.g. `Reader*` (not owned, default), // `ChainReader<>` (owned), `std::unique_ptr` (owned), -// `AnyDependency` (maybe owned). +// `Any` (maybe owned). // // By relying on CTAD the template argument can be deduced as // `InitializerTargetT` of the type of the first constructor argument. diff --git a/riegeli/bzip2/bzip2_writer.h b/riegeli/bzip2/bzip2_writer.h index 992aef25..bf09bfcf 100644 --- a/riegeli/bzip2/bzip2_writer.h +++ b/riegeli/bzip2/bzip2_writer.h @@ -118,7 +118,7 @@ class Bzip2WriterBase : public BufferedWriter { // possibly owning the compressed `Writer`. `Dest` must support // `Dependency`, e.g. `Writer*` (not owned, default), // `ChainWriter<>` (owned), `std::unique_ptr` (owned), -// `AnyDependency` (maybe owned). +// `Any` (maybe owned). // // By relying on CTAD the template argument can be deduced as // `InitializerTargetT` of the type of the first constructor argument. diff --git a/riegeli/chunk_encoding/BUILD b/riegeli/chunk_encoding/BUILD index 6659d002..45a40e82 100644 --- a/riegeli/chunk_encoding/BUILD +++ b/riegeli/chunk_encoding/BUILD @@ -144,7 +144,7 @@ cc_library( hdrs = ["decompressor.h"], deps = [ ":constants", - "//riegeli/base:any_dependency", + "//riegeli/base:any", "//riegeli/base:assert", "//riegeli/base:chain", "//riegeli/base:dependency", diff --git a/riegeli/chunk_encoding/decompressor.h b/riegeli/chunk_encoding/decompressor.h index e8abd644..aa1c3c5c 100644 --- a/riegeli/chunk_encoding/decompressor.h +++ b/riegeli/chunk_encoding/decompressor.h @@ -24,7 +24,7 @@ #include "absl/status/status.h" #include "absl/strings/str_cat.h" #include "absl/types/optional.h" -#include "riegeli/base/any_dependency.h" +#include "riegeli/base/any.h" #include "riegeli/base/assert.h" #include "riegeli/base/chain.h" #include "riegeli/base/dependency.h" @@ -134,8 +134,8 @@ class Decompressor : public Object { void Initialize(Initializer src, CompressionType compression_type, const RecyclingPoolOptions& recycling_pool_options); - AnyDependency::Inlining, ZstdReader, - SnappyReader> + Any::Inlining, ZstdReader, + SnappyReader> decompressed_; }; diff --git a/riegeli/csv/csv_reader.h b/riegeli/csv/csv_reader.h index d1448031..277a163a 100644 --- a/riegeli/csv/csv_reader.h +++ b/riegeli/csv/csv_reader.h @@ -514,7 +514,7 @@ class CsvReaderBase : public Object { // possibly owning the byte `Reader`. `Src` must support // `Dependency`, e.g. `Reader*` (not owned, default), // `ChainReader<>` (owned), `std::unique_ptr` (owned), -// `AnyDependency` (maybe owned). +// `Any` (maybe owned). // // By relying on CTAD the template argument can be deduced as // `InitializerTargetT` of the type of the first constructor argument. diff --git a/riegeli/csv/csv_writer.h b/riegeli/csv/csv_writer.h index 217f1dd3..789bd5b7 100644 --- a/riegeli/csv/csv_writer.h +++ b/riegeli/csv/csv_writer.h @@ -377,7 +377,7 @@ class CsvWriterBase : public Object { // possibly owning the byte `Writer`. `Dest` must support // `Dependency`, e.g. `Writer*` (not owned, default), // `ChainWriter<>` (owned), `std::unique_ptr` (owned), -// `AnyDependency` (maybe owned). +// `Any` (maybe owned). // // By relying on CTAD the template argument can be deduced as // `InitializerTargetT` of the type of the first constructor argument. diff --git a/riegeli/digests/BUILD b/riegeli/digests/BUILD index 2ff9d0b2..87a2a0c6 100644 --- a/riegeli/digests/BUILD +++ b/riegeli/digests/BUILD @@ -21,7 +21,7 @@ cc_library( hdrs = ["digester_handle.h"], deps = [ ":digest_converter", - "//riegeli/base:any_dependency", + "//riegeli/base:any", "//riegeli/base:arithmetic", "//riegeli/base:chain", "//riegeli/base:dependency", diff --git a/riegeli/digests/digester_handle.h b/riegeli/digests/digester_handle.h index 0fe7d614..1518b28d 100644 --- a/riegeli/digests/digester_handle.h +++ b/riegeli/digests/digester_handle.h @@ -29,7 +29,7 @@ #include "absl/strings/cord.h" #include "absl/strings/string_view.h" #include "absl/types/span.h" -#include "riegeli/base/any_dependency.h" +#include "riegeli/base/any.h" #include "riegeli/base/chain.h" #include "riegeli/base/dependency.h" #include "riegeli/base/dependency_manager.h" @@ -578,7 +578,7 @@ using DigestOf = // Type-erased digester returning a digest of type `DigestType`. template -using AnyDigester = AnyDependency>; +using AnyDigester = Any>; // Implementation details follow. diff --git a/riegeli/digests/digesting_reader.h b/riegeli/digests/digesting_reader.h index e02a05ed..4625f993 100644 --- a/riegeli/digests/digesting_reader.h +++ b/riegeli/digests/digesting_reader.h @@ -110,7 +110,7 @@ class DigestingReaderBase : public Reader { // possibly owning the original `Reader`. `Src` must support // `Dependency`, e.g. `Reader*` (not owned, default), // `ChainReader<>` (owned), `std::unique_ptr` (owned), -// `AnyDependency` (maybe owned). +// `Any` (maybe owned). // // By relying on CTAD the `Digester` template argument can be deduced as // `InitializerTargetT` of the type of the `digester` constructor argument, and @@ -217,7 +217,7 @@ explicit DigestingReader(Src&& src, Digester&& digester = riegeli::Maker()) // possibly owning the `Reader`. `Src` must support // `Dependency`, e.g. `Reader&` (not owned), // `ChainReader<>` (owned), `std::unique_ptr` (owned), -// `AnyDependency` (maybe owned). +// `Any` (maybe owned). // // The digest is converted to `DesiredDigestType` using `DigestConverter`. template `, e.g. `Writer*` (not owned, default), // `ChainWriter<>` (owned), `std::unique_ptr` (owned), -// `AnyDependency` (maybe owned). +// `Any` (maybe owned). // // By relying on CTAD the `Digester` template argument can be deduced as // `InitializerTargetT` of the type of the `digester` constructor argument, and diff --git a/riegeli/lines/BUILD b/riegeli/lines/BUILD index 9752fb32..3b2f2b55 100644 --- a/riegeli/lines/BUILD +++ b/riegeli/lines/BUILD @@ -50,7 +50,7 @@ cc_library( hdrs = ["text_reader.h"], deps = [ ":newline", - "//riegeli/base:any_dependency", + "//riegeli/base:any", "//riegeli/base:arithmetic", "//riegeli/base:assert", "//riegeli/base:dependency", @@ -75,7 +75,7 @@ cc_library( deps = [ ":line_writing", ":newline", - "//riegeli/base:any_dependency", + "//riegeli/base:any", "//riegeli/base:arithmetic", "//riegeli/base:assert", "//riegeli/base:dependency", diff --git a/riegeli/lines/text_reader.h b/riegeli/lines/text_reader.h index 644c92b9..b173cbf0 100644 --- a/riegeli/lines/text_reader.h +++ b/riegeli/lines/text_reader.h @@ -23,7 +23,7 @@ #include "absl/base/attributes.h" #include "absl/base/optimization.h" #include "absl/status/status.h" -#include "riegeli/base/any_dependency.h" +#include "riegeli/base/any.h" #include "riegeli/base/assert.h" #include "riegeli/base/dependency.h" #include "riegeli/base/initializer.h" @@ -121,7 +121,7 @@ class TextReaderImpl : public TextReaderBase { // possibly owning the original `Reader`. `Src` must support // `Dependency`, e.g. `Reader*` (not owned, default), // `ChainReader<>` (owned), `std::unique_ptr` (owned), -// `AnyDependency` (maybe owned). +// `Any` (maybe owned). // // By relying on CTAD the second template argument can be deduced as // `InitializerTargetT` of the type of the first constructor argument. @@ -210,9 +210,9 @@ explicit TextReader(Src&& src, // Wraps a `TextReader` for a line terminator specified at runtime. template using AnyTextReader = - AnyDependency::Inlining, - TextReader, - TextReader>; + Any::Inlining, + TextReader, + TextReader>; // Options for `MakeAnyTextReader()`. class AnyTextReaderOptions : public BufferOptionsBase { diff --git a/riegeli/lines/text_writer.h b/riegeli/lines/text_writer.h index 728f80c6..4fdc3adf 100644 --- a/riegeli/lines/text_writer.h +++ b/riegeli/lines/text_writer.h @@ -22,7 +22,7 @@ #include "absl/base/optimization.h" #include "absl/status/status.h" #include "absl/strings/string_view.h" -#include "riegeli/base/any_dependency.h" +#include "riegeli/base/any.h" #include "riegeli/base/assert.h" #include "riegeli/base/dependency.h" #include "riegeli/base/initializer.h" @@ -155,9 +155,9 @@ explicit TextWriter(Dest&& dest, // Wraps a `TextWriter` for a line terminator specified at runtime. template using AnyTextWriter = - AnyDependency::Inlining, - TextWriter, - TextWriter>; + Any::Inlining, + TextWriter, + TextWriter>; // Options for `MakeAnyTextWriter()`. class AnyTextWriterOptions : public BufferOptionsBase { diff --git a/riegeli/lz4/lz4_reader.h b/riegeli/lz4/lz4_reader.h index ff0122ec..556245d1 100644 --- a/riegeli/lz4/lz4_reader.h +++ b/riegeli/lz4/lz4_reader.h @@ -193,7 +193,7 @@ class Lz4ReaderBase : public BufferedReader { // possibly owning the compressed `Reader`. `Src` must support // `Dependency`, e.g. `Reader*` (not owned, default), // `ChainReader<>` (owned), `std::unique_ptr` (owned), -// `AnyDependency` (maybe owned). +// `Any` (maybe owned). // // By relying on CTAD the template argument can be deduced as // `InitializerTargetT` of the type of the first constructor argument. diff --git a/riegeli/lz4/lz4_writer.h b/riegeli/lz4/lz4_writer.h index faf884ec..32fee76f 100644 --- a/riegeli/lz4/lz4_writer.h +++ b/riegeli/lz4/lz4_writer.h @@ -297,7 +297,7 @@ class Lz4WriterBase : public BufferedWriter { // possibly owning the compressed `Writer`. `Dest` must support // `Dependency`, e.g. `Writer*` (not owned, default), // `ChainWriter<>` (owned), `std::unique_ptr` (owned), -// `AnyDependency` (maybe owned). +// `Any` (maybe owned). // // By relying on CTAD the template argument can be deduced as // `InitializerTargetT` of the type of the first constructor argument. diff --git a/riegeli/messages/message_parse.h b/riegeli/messages/message_parse.h index 591fd685..0e8caf14 100644 --- a/riegeli/messages/message_parse.h +++ b/riegeli/messages/message_parse.h @@ -102,7 +102,7 @@ class ParseOptions { // possibly owning the `Reader`. `Src` must support // `Dependency`, e.g. `Reader&` (not owned), // `ChainReader<>` (owned), `std::unique_ptr` (owned), -// `AnyDependency` (maybe owned). +// `Any` (maybe owned). // // Returns status: // * `status.ok()` - success (`dest` is filled) diff --git a/riegeli/messages/message_serialize.h b/riegeli/messages/message_serialize.h index ae691e22..197c1cb0 100644 --- a/riegeli/messages/message_serialize.h +++ b/riegeli/messages/message_serialize.h @@ -119,7 +119,7 @@ class SerializeOptions { // possibly owning the `Writer`. `Dest` must support // `Dependency`, e.g. `Writer&` (not owned), // `ChainWriter<>` (owned), `std::unique_ptr` (owned), -// `AnyDependency` (maybe owned). +// `Any` (maybe owned). // // Returns status: // * `status.ok()` - success (`dest` is written to) diff --git a/riegeli/messages/text_parse.h b/riegeli/messages/text_parse.h index ee234ec8..5e8eb6ad 100644 --- a/riegeli/messages/text_parse.h +++ b/riegeli/messages/text_parse.h @@ -98,7 +98,7 @@ class TextParseOptions { // possibly owning the `Reader`. `Src` must support // `Dependency`, e.g. `Reader&` (not owned), // `ChainReader<>` (owned), `std::unique_ptr` (owned), -// `AnyDependency` (maybe owned). +// `Any` (maybe owned). // // Returns status: // * `status.ok()` - success (`dest` is filled) diff --git a/riegeli/messages/text_print.h b/riegeli/messages/text_print.h index cd836085..ef7c7938 100644 --- a/riegeli/messages/text_print.h +++ b/riegeli/messages/text_print.h @@ -92,7 +92,7 @@ class TextPrintOptions { // possibly owning the `Writer`. `Dest` must support // `Dependency`, e.g. `Writer&` (not owned), // `ChainWriter<>` (owned), `std::unique_ptr` (owned), -// `AnyDependency` (maybe owned). +// `Any` (maybe owned). // // Returns status: // * `status.ok()` - success (`dest` is written to) diff --git a/riegeli/records/chunk_reader.h b/riegeli/records/chunk_reader.h index 943607a2..7d0f8b4d 100644 --- a/riegeli/records/chunk_reader.h +++ b/riegeli/records/chunk_reader.h @@ -248,7 +248,7 @@ using ChunkReader = DefaultChunkReaderBase; // possibly owning the byte `Reader`. `Src` must support // `Dependency`, e.g. `Reader*` (not owned, default), // `ChainReader<>` (owned), `std::unique_ptr` (owned), -// `AnyDependency` (maybe owned). +// `Any` (maybe owned). // // By relying on CTAD the template argument can be deduced as // `InitializerTargetT` of the type of the first constructor argument. diff --git a/riegeli/records/chunk_writer.h b/riegeli/records/chunk_writer.h index 4e3e65c5..49c18b1e 100644 --- a/riegeli/records/chunk_writer.h +++ b/riegeli/records/chunk_writer.h @@ -173,7 +173,7 @@ class DefaultChunkWriterBase : public ChunkWriter { // possibly owning the byte `Writer`. `Dest` must support // `Dependency`, e.g. `Writer*` (not owned, default), // `ChainWriter<>` (owned), `std::unique_ptr` (owned), -// `AnyDependency` (maybe owned). +// `Any` (maybe owned). // // By relying on CTAD the template argument can be deduced as // `InitializerTargetT` of the type of the first constructor argument. diff --git a/riegeli/records/record_reader.h b/riegeli/records/record_reader.h index 7b7499f1..3e533751 100644 --- a/riegeli/records/record_reader.h +++ b/riegeli/records/record_reader.h @@ -573,13 +573,12 @@ class RecordReaderBase : public Object { // possibly owning the byte `Reader`. `Src` must support // `Dependency`, e.g. `Reader*` (not owned, default), // `ChainReader<>` (owned), `std::unique_ptr` (owned), -// `AnyDependency` (maybe owned). +// `Any` (maybe owned). // // `Src` may also specify a `ChunkReader` instead of a byte `Reader`. In this // case `Src` must support `Dependency`, e.g. // `ChunkReader*` (not owned), `DefaultChunkReader<>` (owned), -// `std::unique_ptr` (owned), -// `AnyDependency` (maybe owned). +// `std::unique_ptr` (owned), `Any` (maybe owned). // // By relying on CTAD the template argument can be deduced as // `InitializerTargetT` of the type of the first constructor argument. diff --git a/riegeli/records/record_writer.h b/riegeli/records/record_writer.h index dc371aba..a04b54de 100644 --- a/riegeli/records/record_writer.h +++ b/riegeli/records/record_writer.h @@ -611,13 +611,12 @@ class RecordWriterBase : public Object { // possibly owning the byte `Writer`. `Dest` must support // `Dependency`, e.g. `Writer*` (not owned, default), // `ChainWriter<>` (owned), `std::unique_ptr` (owned), -// `AnyDependency` (maybe owned). +// `Any` (maybe owned). // // `Dest` can also specify a `ChunkWriter` instead of a byte `Writer`. In this // case `Dest` must support `Dependency`, e.g. // `ChunkWriter*` (not owned), `DefaultChunkWriter<>` (owned), -// `std::unique_ptr` (owned), -// `AnyDependency` (maybe owned). +// `std::unique_ptr` (owned), `Any` (maybe owned). // // By relying on CTAD the template argument can be deduced as // `InitializerTargetT` of the type of the first constructor argument. diff --git a/riegeli/records/tools/BUILD b/riegeli/records/tools/BUILD index 9833f341..d5f53872 100644 --- a/riegeli/records/tools/BUILD +++ b/riegeli/records/tools/BUILD @@ -12,7 +12,7 @@ cc_binary( srcs = ["describe_riegeli_file.cc"], deps = [ ":riegeli_summary_cc_proto", - "//riegeli/base:any_dependency", + "//riegeli/base:any", "//riegeli/base:arithmetic", "//riegeli/base:assert", "//riegeli/base:chain", @@ -103,7 +103,7 @@ cc_library( srcs = ["tfrecord_recognizer.cc"], hdrs = ["tfrecord_recognizer.h"], deps = [ - "//riegeli/base:any_dependency", + "//riegeli/base:any", "//riegeli/base:assert", "//riegeli/base:initializer", "//riegeli/base:object", diff --git a/riegeli/records/tools/describe_riegeli_file.cc b/riegeli/records/tools/describe_riegeli_file.cc index 599ceead..fbdebebe 100644 --- a/riegeli/records/tools/describe_riegeli_file.cc +++ b/riegeli/records/tools/describe_riegeli_file.cc @@ -29,7 +29,7 @@ #include "absl/strings/string_view.h" #include "absl/types/optional.h" #include "google/protobuf/repeated_ptr_field.h" -#include "riegeli/base/any_dependency.h" +#include "riegeli/base/any.h" #include "riegeli/base/arithmetic.h" #include "riegeli/base/assert.h" #include "riegeli/base/chain.h" @@ -227,8 +227,7 @@ absl::Status DescribeTransposedChunk( src.Seek(0); TransposeDecoder transpose_decoder; Chain dest; - AnyDependency::Inlining, - NullBackwardWriter> + Any::Inlining, NullBackwardWriter> dest_writer; if (show_records) { dest_writer = riegeli::Maker>(&dest); diff --git a/riegeli/records/tools/tfrecord_recognizer.cc b/riegeli/records/tools/tfrecord_recognizer.cc index 6da797b6..9646f48f 100644 --- a/riegeli/records/tools/tfrecord_recognizer.cc +++ b/riegeli/records/tools/tfrecord_recognizer.cc @@ -18,7 +18,7 @@ #include "absl/base/optimization.h" #include "absl/status/status.h" -#include "riegeli/base/any_dependency.h" +#include "riegeli/base/any.h" #include "riegeli/base/maker.h" #include "riegeli/bytes/reader.h" #include "riegeli/endian/endian_reading.h" @@ -40,7 +40,7 @@ bool TFRecordRecognizer::CheckFileFormat( return false; } - AnyDependency::Inlining> reader; + Any::Inlining> reader; if (RecognizeZlib(*byte_reader_)) { record_reader_options.compression_type = tensorflow::io::RecordReaderOptions::ZLIB_COMPRESSION; diff --git a/riegeli/snappy/framed/framed_snappy_reader.h b/riegeli/snappy/framed/framed_snappy_reader.h index 64d1fd8b..764f1de0 100644 --- a/riegeli/snappy/framed/framed_snappy_reader.h +++ b/riegeli/snappy/framed/framed_snappy_reader.h @@ -89,7 +89,7 @@ class FramedSnappyReaderBase : public PullableReader { // possibly owning the compressed `Reader`. `Src` must support // `Dependency`, e.g. `Reader*` (not owned, default), // `ChainReader<>` (owned), `std::unique_ptr` (owned), -// `AnyDependency` (maybe owned). +// `Any` (maybe owned). // // By relying on CTAD the template argument can be deduced as // `InitializerTargetT` of the type of the first constructor argument. diff --git a/riegeli/snappy/framed/framed_snappy_writer.h b/riegeli/snappy/framed/framed_snappy_writer.h index acfc6c33..1a21bb9f 100644 --- a/riegeli/snappy/framed/framed_snappy_writer.h +++ b/riegeli/snappy/framed/framed_snappy_writer.h @@ -134,7 +134,7 @@ class FramedSnappyWriterBase : public PushableWriter { // possibly owning the compressed `Writer`. `Dest` must support // `Dependency`, e.g. `Writer*` (not owned, default), // `ChainWriter<>` (owned), `std::unique_ptr` (owned), -// `AnyDependency` (maybe owned). +// `Any` (maybe owned). // // By relying on CTAD the template argument can be deduced as // `InitializerTargetT` of the type of the first constructor argument. diff --git a/riegeli/snappy/hadoop/hadoop_snappy_reader.h b/riegeli/snappy/hadoop/hadoop_snappy_reader.h index 59fe3afe..2986795b 100644 --- a/riegeli/snappy/hadoop/hadoop_snappy_reader.h +++ b/riegeli/snappy/hadoop/hadoop_snappy_reader.h @@ -90,7 +90,7 @@ class HadoopSnappyReaderBase : public PullableReader { // possibly owning the compressed `Reader`. `Src` must support // `Dependency`, e.g. `Reader*` (not owned, default), // `ChainReader<>` (owned), `std::unique_ptr` (owned), -// `AnyDependency` (maybe owned). +// `Any` (maybe owned). // // By relying on CTAD the template argument can be deduced as // `InitializerTargetT` of the type of the first constructor argument. diff --git a/riegeli/snappy/hadoop/hadoop_snappy_writer.h b/riegeli/snappy/hadoop/hadoop_snappy_writer.h index bc156f69..2a701057 100644 --- a/riegeli/snappy/hadoop/hadoop_snappy_writer.h +++ b/riegeli/snappy/hadoop/hadoop_snappy_writer.h @@ -134,7 +134,7 @@ class HadoopSnappyWriterBase : public PushableWriter { // possibly owning the compressed `Writer`. `Dest` must support // `Dependency`, e.g. `Writer*` (not owned, default), // `ChainWriter<>` (owned), `std::unique_ptr` (owned), -// `AnyDependency` (maybe owned). +// `Any` (maybe owned). // // By relying on CTAD the template argument can be deduced as // `InitializerTargetT` of the type of the first constructor argument. diff --git a/riegeli/snappy/snappy_reader.h b/riegeli/snappy/snappy_reader.h index 9585d9e6..450c9dce 100644 --- a/riegeli/snappy/snappy_reader.h +++ b/riegeli/snappy/snappy_reader.h @@ -70,7 +70,7 @@ class SnappyReaderBase : public ChainReader { // possibly owning the compressed `Reader`. `Src` must support // `Dependency`, e.g. `Reader*` (not owned, default), // `std::unique_ptr` (owned), `ChainReader<>` (owned), -// `AnyDependency` (maybe owned). +// `Any` (maybe owned). // // By relying on CTAD the template argument can be deduced as // `InitializerTargetT` of the type of the first constructor argument. @@ -138,13 +138,13 @@ explicit SnappyReader( // possibly owning the compressed `Reader`. `Src` must support // `Dependency`, e.g. `Reader&` (not owned), // `ChainReader<>` (owned), `std::unique_ptr` (owned), -// `AnyDependency` (maybe owned). +// `Any` (maybe owned). // // The `Dest` template parameter specifies the type of the object providing and // possibly owning the uncompressed `Writer`. `Dest` must support // `Dependency`, e.g. `Writer&` (not owned), // `ChainWriter<>` (owned), `std::unique_ptr` (owned), -// `AnyDependency` (maybe owned). +// `Any` (maybe owned). // // The compressed `Reader` must support `Size()`. To supply or override this // size, the `Reader` can be wrapped in a `LimitingReader` with diff --git a/riegeli/snappy/snappy_writer.h b/riegeli/snappy/snappy_writer.h index 01753438..e93aaa53 100644 --- a/riegeli/snappy/snappy_writer.h +++ b/riegeli/snappy/snappy_writer.h @@ -150,7 +150,7 @@ class SnappyWriterBase : public Writer { // possibly owning the compressed `Writer`. `Dest` must support // `Dependency`, e.g. `Writer*` (not owned, default), // `ChainWriter<>` (owned), `std::unique_ptr` (owned), -// `AnyDependency` (maybe owned). +// `Any` (maybe owned). // // By relying on CTAD the template argument can be deduced as // `InitializerTargetT` of the type of the first constructor argument. @@ -212,13 +212,13 @@ explicit SnappyWriter(Dest&& dest, SnappyWriterBase::Options options = // possibly owning the uncompressed `Reader`. `Src` must support // `Dependency`, e.g. `Reader&` (not owned), // `ChainReader<>` (owned), `std::unique_ptr` (owned), -// `AnyDependency` (maybe owned). +// `Any` (maybe owned). // // The `Dest` template parameter specifies the type of the object providing and // possibly owning the compressed `Writer`. `Dest` must support // `Dependency`, e.g. `Writer&` (not owned), // `ChainWriter<>` (owned), `std::unique_ptr` (owned), -// `AnyDependency` (maybe owned). +// `Any` (maybe owned). // // The uncompressed `Reader` must support `Size()`. To supply or override this // size, the `Reader` can be wrapped in a `LimitingReader` with diff --git a/riegeli/tensorflow/io/file_reader.h b/riegeli/tensorflow/io/file_reader.h index ba43482f..19740c1f 100644 --- a/riegeli/tensorflow/io/file_reader.h +++ b/riegeli/tensorflow/io/file_reader.h @@ -235,7 +235,7 @@ class FileReaderBase : public Reader { // must support `Dependency<::tensorflow::RandomAccessFile*, Src>`, e.g. // `std::unique_ptr<::tensorflow::RandomAccessFile>` (owned, default), // `::tensorflow::RandomAccessFile*` (not owned), -// `AnyDependency<::tensorflow::RandomAccessFile*>` (maybe owned). +// `Any<::tensorflow::RandomAccessFile*>` (maybe owned). // // By relying on CTAD the template argument can be deduced as // `InitializerTargetT` of the type of the first constructor argument. diff --git a/riegeli/tensorflow/io/file_writer.h b/riegeli/tensorflow/io/file_writer.h index bcf91fbe..d8801469 100644 --- a/riegeli/tensorflow/io/file_writer.h +++ b/riegeli/tensorflow/io/file_writer.h @@ -180,7 +180,7 @@ class FileWriterBase : public Writer { // must support `Dependency<::tensorflow::WritableFile*, Dest>`, e.g. // `std::unique_ptr<::tensorflow::WritableFile>` (owned, default), // `::tensorflow::WritableFile*` (not owned), -// `AnyDependency<::tensorflow::WritableFile*>` (maybe owned). +// `Any<::tensorflow::WritableFile*>` (maybe owned). // // By relying on CTAD the template argument can be deduced as // `InitializerTargetT` of the type of the first constructor argument. diff --git a/riegeli/xz/xz_reader.h b/riegeli/xz/xz_reader.h index 62474523..d1be4ceb 100644 --- a/riegeli/xz/xz_reader.h +++ b/riegeli/xz/xz_reader.h @@ -203,7 +203,7 @@ class XzReaderBase : public BufferedReader { // possibly owning the compressed `Reader`. `Src` must support // `Dependency`, e.g. `Reader*` (not owned, default), // `ChainReader<>` (owned), `std::unique_ptr` (owned), -// `AnyDependency` (maybe owned). +// `Any` (maybe owned). // // By relying on CTAD the template argument can be deduced as // `InitializerTargetT` of the type of the first constructor argument. diff --git a/riegeli/xz/xz_writer.h b/riegeli/xz/xz_writer.h index 98cb89b1..ddd6a130 100644 --- a/riegeli/xz/xz_writer.h +++ b/riegeli/xz/xz_writer.h @@ -267,7 +267,7 @@ class XzWriterBase : public BufferedWriter { // possibly owning the compressed `Writer`. `Dest` must support // `Dependency`, e.g. `Writer*` (not owned, default), // `ChainWriter<>` (owned), `std::unique_ptr` (owned), -// `AnyDependency` (maybe owned). +// `Any` (maybe owned). // // By relying on CTAD the template argument can be deduced as // `InitializerTargetT` of the type of the first constructor argument. diff --git a/riegeli/zlib/zlib_reader.h b/riegeli/zlib/zlib_reader.h index 4aa006a5..7746db3f 100644 --- a/riegeli/zlib/zlib_reader.h +++ b/riegeli/zlib/zlib_reader.h @@ -235,7 +235,7 @@ class ZlibReaderBase : public BufferedReader { // possibly owning the compressed `Reader`. `Src` must support // `Dependency`, e.g. `Reader*` (not owned, default), // `ChainReader<>` (owned), `std::unique_ptr` (owned), -// `AnyDependency` (maybe owned). +// `Any` (maybe owned). // // By relying on CTAD the template argument can be deduced as // `InitializerTargetT` of the type of the first constructor argument. diff --git a/riegeli/zlib/zlib_writer.h b/riegeli/zlib/zlib_writer.h index fd65d269..79dc51ff 100644 --- a/riegeli/zlib/zlib_writer.h +++ b/riegeli/zlib/zlib_writer.h @@ -235,7 +235,7 @@ class ZlibWriterBase : public BufferedWriter { // possibly owning the compressed `Writer`. `Dest` must support // `Dependency`, e.g. `Writer*` (not owned, default), // `ChainWriter<>` (owned), `std::unique_ptr` (owned), -// `AnyDependency` (maybe owned). +// `Any` (maybe owned). // // By relying on CTAD the template argument can be deduced as // `InitializerTargetT` of the type of the first constructor argument. diff --git a/riegeli/zstd/zstd_reader.h b/riegeli/zstd/zstd_reader.h index c45eeeba..5796077b 100644 --- a/riegeli/zstd/zstd_reader.h +++ b/riegeli/zstd/zstd_reader.h @@ -168,7 +168,7 @@ class ZstdReaderBase : public BufferedReader { // possibly owning the compressed `Reader`. `Src` must support // `Dependency`, e.g. `Reader*` (not owned, default), // `ChainReader<>` (owned), `std::unique_ptr` (owned), -// `AnyDependency` (maybe owned). +// `Any` (maybe owned). // // By relying on CTAD the template argument can be deduced as // `InitializerTargetT` of the type of the first constructor argument. diff --git a/riegeli/zstd/zstd_writer.h b/riegeli/zstd/zstd_writer.h index 16bb8ce2..8034d701 100644 --- a/riegeli/zstd/zstd_writer.h +++ b/riegeli/zstd/zstd_writer.h @@ -276,7 +276,7 @@ class ZstdWriterBase : public BufferedWriter { // possibly owning the compressed `Writer`. `Dest` must support // `Dependency`, e.g. `Writer*` (not owned, default), // `ChainWriter<>` (owned), `std::unique_ptr` (owned), -// `AnyDependency` (maybe owned). +// `Any` (maybe owned). // // By relying on CTAD the template argument can be deduced as // `InitializerTargetT` of the type of the first constructor argument.