chromium/third_party/webrtc/rtc_base/memory/always_valid_pointer.h

/*
 *  Copyright 2022 The WebRTC project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */
#ifndef RTC_BASE_MEMORY_ALWAYS_VALID_POINTER_H_
#define RTC_BASE_MEMORY_ALWAYS_VALID_POINTER_H_

#include <memory>
#include <utility>

#include "rtc_base/checks.h"

namespace webrtc {

// This template allows the instantiation of a pointer to Interface in such a
// way that if it is passed a null pointer, an object of class Default will be
// created, which will be deallocated when the pointer is deleted.
template <typename Interface, typename Default = Interface>
class AlwaysValidPointer {};

// This class is similar to AlwaysValidPointer, but it does not create
// a default object and crashes if none of the input pointers are non-null.
template <typename Interface>
class AlwaysValidPointerNoDefault {};

template <typename T, typename U, typename V, typename W>
bool operator==(const AlwaysValidPointer<T, U>& a,
                const AlwaysValidPointer<V, W>& b) {}

template <typename T, typename U, typename V, typename W>
bool operator!=(const AlwaysValidPointer<T, U>& a,
                const AlwaysValidPointer<V, W>& b) {}

template <typename T, typename U>
bool operator==(const AlwaysValidPointer<T, U>& a, std::nullptr_t) {}

template <typename T, typename U>
bool operator!=(const AlwaysValidPointer<T, U>& a, std::nullptr_t) {}

template <typename T, typename U>
bool operator==(std::nullptr_t, const AlwaysValidPointer<T, U>& a) {}

template <typename T, typename U>
bool operator!=(std::nullptr_t, const AlwaysValidPointer<T, U>& a) {}

template <typename T, typename U>
bool operator==(const AlwaysValidPointerNoDefault<T>& a,
                const AlwaysValidPointerNoDefault<U>& b) {}

template <typename T, typename U>
bool operator!=(const AlwaysValidPointerNoDefault<T>& a,
                const AlwaysValidPointerNoDefault<U>& b) {}

template <typename T>
bool operator==(const AlwaysValidPointerNoDefault<T>& a, std::nullptr_t) {}

template <typename T>
bool operator!=(const AlwaysValidPointerNoDefault<T>& a, std::nullptr_t) {}

template <typename T>
bool operator==(std::nullptr_t, const AlwaysValidPointerNoDefault<T>& a) {}

template <typename T>
bool operator!=(std::nullptr_t, const AlwaysValidPointerNoDefault<T>& a) {}

// Comparison with raw pointer.
template <typename T, typename U, typename V>
bool operator==(const AlwaysValidPointer<T, U>& a, const V* b) {}

template <typename T, typename U, typename V>
bool operator!=(const AlwaysValidPointer<T, U>& a, const V* b) {}

template <typename T, typename U, typename V>
bool operator==(const T* a, const AlwaysValidPointer<U, V>& b) {}

template <typename T, typename U, typename V>
bool operator!=(const T* a, const AlwaysValidPointer<U, V>& b) {}

template <typename T, typename U>
bool operator==(const AlwaysValidPointerNoDefault<T>& a, const U* b) {}

template <typename T, typename U>
bool operator!=(const AlwaysValidPointerNoDefault<T>& a, const U* b) {}

template <typename T, typename U>
bool operator==(const T* a, const AlwaysValidPointerNoDefault<U>& b) {}

template <typename T, typename U>
bool operator!=(const T* a, const AlwaysValidPointerNoDefault<U>& b) {}

}  // namespace webrtc

#endif  // RTC_BASE_MEMORY_ALWAYS_VALID_POINTER_H_