argpar: sync with upstream
[babeltrace.git] / src / cpp-common / bt2c / std-int.hpp
... / ...
CommitLineData
1/*
2 * Copyright (c) 2022 Philippe Proulx <pproulx@efficios.com>
3 *
4 * SPDX-License-Identifier: MIT
5 */
6
7#ifndef BABELTRACE_CPP_COMMON_BT2C_STD_INT_HPP
8#define BABELTRACE_CPP_COMMON_BT2C_STD_INT_HPP
9
10#include <cstdint>
11
12namespace bt2c {
13
14/*
15 * Whether or not an integer is signed.
16 */
17enum class Signedness
18{
19 Unsigned,
20 Signed,
21};
22
23namespace internal {
24
25template <std::size_t LenBitsV, Signedness SignednessV>
26struct StdIntTBase;
27
28template <>
29struct StdIntTBase<8, Signedness::Signed>
30{
31 using Type = std::int8_t;
32};
33
34template <>
35struct StdIntTBase<8, Signedness::Unsigned>
36{
37 using Type = std::uint8_t;
38};
39
40template <>
41struct StdIntTBase<16, Signedness::Signed>
42{
43 using Type = std::int16_t;
44};
45
46template <>
47struct StdIntTBase<16, Signedness::Unsigned>
48{
49 using Type = std::uint16_t;
50};
51
52template <>
53struct StdIntTBase<32, Signedness::Signed>
54{
55 using Type = std::int32_t;
56};
57
58template <>
59struct StdIntTBase<32, Signedness::Unsigned>
60{
61 using Type = std::uint32_t;
62};
63
64template <>
65struct StdIntTBase<64, Signedness::Signed>
66{
67 using Type = std::int64_t;
68};
69
70template <>
71struct StdIntTBase<64, Signedness::Unsigned>
72{
73 using Type = std::uint64_t;
74};
75
76} /* namespace internal */
77
78/*
79 * Standard fixed-length integer type `Type` of length `LenBitsV` bits
80 * and signedness `SignednessV`.
81 *
82 * `LenBitsV` must be one of 8, 16, 32, or 64.
83 *
84 * For example, `StdIntT<32, Signedness::Signed>` is `std::int32_t`.
85 */
86template <std::size_t LenBitsV, Signedness SignednessV>
87using StdIntT = typename internal::StdIntTBase<LenBitsV, SignednessV>::Type;
88
89} /* namespace bt2c */
90
91#endif /* BABELTRACE_CPP_COMMON_BT2C_STD_INT_HPP */
This page took 0.024295 seconds and 5 git commands to generate.