// Copyright 2026 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef UTIL_RAW_REF_H_ #define UTIL_RAW_REF_H_ #if defined(BUILD_WITH_CHROMIUM) #include "partition_alloc/pointers/raw_ref.h" // nogncheck namespace openscreen { template using raw_ref = ::base::raw_ref; } // namespace openscreen #else // !defined(BUILD_WITH_CHROMIUM) #include #include #include "util/raw_ptr.h" namespace openscreen { template class raw_ref; namespace internal { template struct is_raw_ref : std::false_type {}; template struct is_raw_ref > : std::true_type {}; } // namespace internal template class OPENSCREEN_TRIVIAL_ABI raw_ref { public: OPENSCREEN_ALWAYS_INLINE constexpr explicit raw_ref(T& ref) noexcept : ptr_(&ref) {} template >::value && std::is_convertible_v > > OPENSCREEN_ALWAYS_INLINE constexpr explicit raw_ref(U& ref) noexcept : ptr_(&ref) {} OPENSCREEN_ALWAYS_INLINE constexpr raw_ref(const raw_ref& other) noexcept = default; OPENSCREEN_ALWAYS_INLINE constexpr raw_ref(raw_ref&& other) noexcept = default; template > > OPENSCREEN_ALWAYS_INLINE constexpr raw_ref(const raw_ref& other) noexcept : ptr_(other.ptr_) {} template > > OPENSCREEN_ALWAYS_INLINE constexpr raw_ref(raw_ref&& other) noexcept : ptr_(std::move(other.ptr_)) {} ~raw_ref() = default; OPENSCREEN_ALWAYS_INLINE constexpr raw_ref& operator=( const raw_ref& other) noexcept = default; OPENSCREEN_ALWAYS_INLINE constexpr raw_ref& operator=( raw_ref&& other) noexcept = default; template > > OPENSCREEN_ALWAYS_INLINE constexpr raw_ref& operator=( const raw_ref& other) noexcept { ptr_ = other.ptr_; return *this; } template > > OPENSCREEN_ALWAYS_INLINE constexpr raw_ref& operator=( raw_ref&& other) noexcept { ptr_ = std::move(other.ptr_); return *this; } OPENSCREEN_ALWAYS_INLINE constexpr T& get() const noexcept { return *ptr_; } OPENSCREEN_ALWAYS_INLINE constexpr T* operator->() const noexcept { return ptr_.get(); } OPENSCREEN_ALWAYS_INLINE constexpr T& operator*() const noexcept { return *ptr_; } template OPENSCREEN_ALWAYS_INLINE friend constexpr bool operator==( const raw_ref& lhs, const raw_ref& rhs) noexcept { return lhs.ptr_ == rhs.ptr_; } template OPENSCREEN_ALWAYS_INLINE friend constexpr bool operator!=( const raw_ref& lhs, const raw_ref& rhs) noexcept { return lhs.ptr_ != rhs.ptr_; } private: template friend class raw_ref; raw_ptr ptr_; }; } // namespace openscreen #endif // !defined(BUILD_WITH_CHROMIUM) #endif // UTIL_RAW_REF_H_