1 // 2 // Copyright 2020 The ANGLE Project Authors. All rights reserved. 3 // Use of this source code is governed by a BSD-style license that can be 4 // found in the LICENSE file. 5 // 6 7 #ifndef COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_REFERENCE_H_ 8 #define COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_REFERENCE_H_ 9 10 namespace sh 11 { 12 13 // Similar to std::reference_wrapper, but also lifts comparison operators. 14 template <typename T> 15 class Ref 16 { 17 public: 18 Ref(const Ref &) = default; 19 Ref(Ref &&) = default; Ref(T & ref)20 Ref(T &ref) : mPtr(&ref) {} 21 22 Ref &operator=(const Ref &) = default; 23 Ref &operator=(Ref &&) = default; 24 25 bool operator==(const Ref &other) const { return *mPtr == *other.mPtr; } 26 bool operator!=(const Ref &other) const { return *mPtr != *other.mPtr; } 27 bool operator<=(const Ref &other) const { return *mPtr <= *other.mPtr; } 28 bool operator>=(const Ref &other) const { return *mPtr >= *other.mPtr; } 29 bool operator<(const Ref &other) const { return *mPtr < *other.mPtr; } 30 bool operator>(const Ref &other) const { return *mPtr > *other.mPtr; } 31 get()32 T &get() { return *mPtr; } get()33 T const &get() const { return *mPtr; } 34 35 operator T &() { return *mPtr; } 36 operator T const &() const { return *mPtr; } 37 38 operator T *() { return *mPtr; } 39 operator T const *() const { return *mPtr; } 40 41 private: 42 T *mPtr; 43 }; 44 45 template <typename T> 46 using CRef = Ref<T const>; 47 48 } // namespace sh 49 50 #endif // COMPILER_TRANSLATOR_TRANSLATORMETALDIRECT_REFERENCE_H_ 51