Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
smallest_integer_for.hpp
Go to the documentation of this file.
1// Copyright 2024, Toyota Motor Corporation
2//
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4
5#ifndef INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_TYPE_MANIPULATION_SMALLEST_INTEGER_FOR_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_TYPE_MANIPULATION_SMALLEST_INTEGER_FOR_HPP_
7
8// parasoft-begin-suppress AUTOSAR-A16_2_2-a-2 "Arene Base aggregate headers permitted by A16-2-2 Permit #1"
9#include "arene/base/constraints/constraints.hpp"
10#include "arene/base/stdlib_choice/cstdint.hpp"
11#include "arene/base/stdlib_choice/enable_if.hpp"
12#include "arene/base/stdlib_choice/numeric_limits.hpp"
13#include "arene/base/type_traits/conditional.hpp"
14
15namespace arene {
16namespace base {
17
18// Note: limits are extracted into constexpr variables to work around a GCC 9 bug where nested
19// conditional_t aliases produce incorrect results when conditions contain parenthesized function
20// calls like (std::numeric_limits<T>::max)().
21namespace smallest_integer_for_detail {
22constexpr std::uint64_t max_uint8{(std::numeric_limits<std::uint8_t>::max)()};
23constexpr std::uint64_t max_uint16{(std::numeric_limits<std::uint16_t>::max)()};
24constexpr std::uint64_t max_uint32{(std::numeric_limits<std::uint32_t>::max)()};
25constexpr std::int64_t max_int8{(std::numeric_limits<std::int8_t>::max)()};
26constexpr std::int64_t min_int8{(std::numeric_limits<std::int8_t>::min)()};
27constexpr std::int64_t max_int16{(std::numeric_limits<std::int16_t>::max)()};
28constexpr std::int64_t min_int16{(std::numeric_limits<std::int16_t>::min)()};
29constexpr std::int64_t max_int32{(std::numeric_limits<std::int32_t>::max)()};
30constexpr std::int64_t min_int32{(std::numeric_limits<std::int32_t>::min)()};
31} // namespace smallest_integer_for_detail
32
33/// @brief Calculates the smallest unsigned integer type that can be used to hold
34/// values up to and including @c MaxValue.
35/// @tparam MaxValue The maximum value to store
36template <std::uint64_t MaxValue>
39 std::uint8_t,
44
45/// @brief Calculates the smallest unsigned integer type that can be used to hold
46/// values from MinValue up to and including MaxValue.
47/// @tparam MinValue The minimum value to store
48/// @tparam MaxValue The maximum value to store, must be greater than or equal to @c MinValue
52 std::int8_t,
55 std::int16_t,
59 std::int32_t,
60 std::int64_t>>>;
61
62} // namespace base
63} // namespace arene
64
65#endif // INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_TYPE_MANIPULATION_SMALLEST_INTEGER_FOR_HPP_
Definition array_exceptions_disabled.cpp:11
Copyright 2026, Toyota Motor Corporation.
Definition array_exceptions_disabled.cpp:10