Bug 1731994: part 4) Declare more methods around `ContentPermissionRequestBase` ...
[gecko.git] / mfbt / IntegerTypeTraits.h
blob57c5c4103c6c1a7bad5ce425ed3e05eba5830984
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 /* Helpers to manipulate integer types that don't fit in TypeTraits.h */
9 #ifndef mozilla_IntegerTypeTraits_h
10 #define mozilla_IntegerTypeTraits_h
12 #include <stddef.h>
13 #include <stdint.h>
14 #include <type_traits>
16 namespace mozilla {
18 namespace detail {
20 /**
21 * StdintTypeForSizeAndSignedness returns the stdint integer type
22 * of given size (can be 1, 2, 4 or 8) and given signedness
23 * (false means unsigned, true means signed).
25 template <size_t Size, bool Signedness>
26 struct StdintTypeForSizeAndSignedness;
28 template <>
29 struct StdintTypeForSizeAndSignedness<1, true> {
30 typedef int8_t Type;
33 template <>
34 struct StdintTypeForSizeAndSignedness<1, false> {
35 typedef uint8_t Type;
38 template <>
39 struct StdintTypeForSizeAndSignedness<2, true> {
40 typedef int16_t Type;
43 template <>
44 struct StdintTypeForSizeAndSignedness<2, false> {
45 typedef uint16_t Type;
48 template <>
49 struct StdintTypeForSizeAndSignedness<4, true> {
50 typedef int32_t Type;
53 template <>
54 struct StdintTypeForSizeAndSignedness<4, false> {
55 typedef uint32_t Type;
58 template <>
59 struct StdintTypeForSizeAndSignedness<8, true> {
60 typedef int64_t Type;
63 template <>
64 struct StdintTypeForSizeAndSignedness<8, false> {
65 typedef uint64_t Type;
68 } // namespace detail
70 template <size_t Size>
71 struct UnsignedStdintTypeForSize
72 : detail::StdintTypeForSizeAndSignedness<Size, false> {};
74 template <size_t Size>
75 struct SignedStdintTypeForSize
76 : detail::StdintTypeForSizeAndSignedness<Size, true> {};
78 template <typename IntegerType>
79 struct PositionOfSignBit {
80 static_assert(std::is_integral_v<IntegerType>,
81 "PositionOfSignBit is only for integral types");
82 // 8 here should be CHAR_BIT from limits.h, but the world has moved on.
83 static const size_t value = 8 * sizeof(IntegerType) - 1;
86 } // namespace mozilla
88 #endif // mozilla_IntegerTypeTraits_h