| 993 | |
| 994 | template <typename T, typename... Args> |
| 995 | Owned<T> AllocateShared(Allocator<> allocator, Args&&... args) { |
| 996 | using U = std::remove_cv_t<T>; |
| 997 | static_assert(!std::is_reference_v<U>, "T must not be a reference"); |
| 998 | static_assert(!std::is_array_v<U>, "T must not be an array"); |
| 999 | |
| 1000 | U* object; |
| 1001 | Owner owner; |
| 1002 | if (google::protobuf::Arena* absl_nullable arena = allocator.arena(); |
| 1003 | arena != nullptr) { |
| 1004 | object = ArenaAllocator(arena).template new_object<U>( |
| 1005 | std::forward<Args>(args)...); |
| 1006 | owner.ptr_ = reinterpret_cast<uintptr_t>(arena) | |
| 1007 | common_internal::kMetadataOwnerArenaBit; |
| 1008 | } else { |
| 1009 | const common_internal::ReferenceCount* refcount; |
| 1010 | std::tie(object, refcount) = common_internal::MakeEmplacedReferenceCount<U>( |
| 1011 | std::forward<Args>(args)...); |
| 1012 | owner.ptr_ = reinterpret_cast<uintptr_t>(refcount) | |
| 1013 | common_internal::kMetadataOwnerReferenceCountBit; |
| 1014 | } |
| 1015 | return Owned<U>(object, std::move(owner)); |
| 1016 | } |
| 1017 | |
| 1018 | template <typename T> |
| 1019 | Owned<T> WrapShared(T* object, Allocator<> allocator) { |
nothing calls this directly
no test coverage detected