Bug 1867190 - Initialise the PHC allocate delay later r=glandium
[gecko.git] / mfbt / IntegerTypeTraits.h
blob33b51b9901d660f572e5f08ae5005ad2281db89c
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 #ifndef mozilla_IntegerTypeTraits_h
8 #define mozilla_IntegerTypeTraits_h
10 #include <stddef.h>
11 #include <stdint.h>
12 #include <type_traits>
14 namespace mozilla {
16 namespace detail {
18 /**
19 * StdintTypeForSizeAndSignedness returns the stdint integer type
20 * of given size (can be 1, 2, 4 or 8) and given signedness
21 * (false means unsigned, true means signed).
23 template <size_t Size, bool Signedness>
24 struct StdintTypeForSizeAndSignedness;
26 template <>
27 struct StdintTypeForSizeAndSignedness<1, true> {
28 typedef int8_t Type;
31 template <>
32 struct StdintTypeForSizeAndSignedness<1, false> {
33 typedef uint8_t Type;
36 template <>
37 struct StdintTypeForSizeAndSignedness<2, true> {
38 typedef int16_t Type;
41 template <>
42 struct StdintTypeForSizeAndSignedness<2, false> {
43 typedef uint16_t Type;
46 template <>
47 struct StdintTypeForSizeAndSignedness<4, true> {
48 typedef int32_t Type;
51 template <>
52 struct StdintTypeForSizeAndSignedness<4, false> {
53 typedef uint32_t Type;
56 template <>
57 struct StdintTypeForSizeAndSignedness<8, true> {
58 typedef int64_t Type;
61 template <>
62 struct StdintTypeForSizeAndSignedness<8, false> {
63 typedef uint64_t Type;
66 } // namespace detail
68 template <size_t Size>
69 struct UnsignedStdintTypeForSize
70 : detail::StdintTypeForSizeAndSignedness<Size, false> {};
72 template <size_t Size>
73 struct SignedStdintTypeForSize
74 : detail::StdintTypeForSizeAndSignedness<Size, true> {};
76 template <typename IntegerType>
77 struct PositionOfSignBit {
78 static_assert(std::is_integral_v<IntegerType>,
79 "PositionOfSignBit is only for integral types");
80 // 8 here should be CHAR_BIT from limits.h, but the world has moved on.
81 static const size_t value = 8 * sizeof(IntegerType) - 1;
84 } // namespace mozilla
86 #endif // mozilla_IntegerTypeTraits_h