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>
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
23 static_assert(std::is_integral_v
<T
>,
24 "mozilla::Opaque only supports integral types");
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 */