no bug - Import translations from android-l10n r=release a=l10n CLOSED TREE
[gecko.git] / mfbt / Opaque.h
blobe5dc84f1598f2d5b83e1b1cb611d5ab08450ce08
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 /* An opaque integral type supporting only comparison operators. */
9 #ifndef mozilla_Opaque_h
10 #define mozilla_Opaque_h
12 #include <type_traits>
14 namespace mozilla {
16 /**
17 * Opaque<T> is a replacement for integral T in cases where only comparisons
18 * must be supported, and it's desirable to prevent accidental dependency on
19 * exact values.
21 template <typename T>
22 class Opaque final {
23 static_assert(std::is_integral_v<T>,
24 "mozilla::Opaque only supports integral types");
26 T mValue;
28 public:
29 Opaque() = default;
30 explicit Opaque(T aValue) : mValue(aValue) {}
32 bool operator==(const Opaque& aOther) const {
33 return mValue == aOther.mValue;
36 bool operator!=(const Opaque& aOther) const { return !(*this == aOther); }
39 } // namespace mozilla
41 #endif /* mozilla_Opaque_h */