tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
smallest_size_t.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2// SPDX-FileCopyrightText: Copyright (C) 2024 Tobias Hienzsch
3
4#ifndef TETL_TYPE_TRAITS_SMALLEST_SIZE_T_HPP
5#define TETL_TYPE_TRAITS_SMALLEST_SIZE_T_HPP
6
7namespace etl {
8
9namespace detail {
10
11template <unsigned long long N>
12consteval auto determine_smallest_size_t()
13{
14 if constexpr (N <= static_cast<unsigned char>(-1)) {
15 return static_cast<unsigned char>(0);
16 } else if constexpr (N <= static_cast<unsigned short>(-1)) {
17 return static_cast<unsigned short>(0);
18 } else if constexpr (N <= static_cast<unsigned int>(-1)) {
19 return static_cast<unsigned int>(0);
20 } else if constexpr (N <= static_cast<unsigned long>(-1)) {
21 return static_cast<unsigned long>(0);
22 } else {
23 return static_cast<unsigned long long>(0);
24 }
25}
26
27} // namespace detail
28
29/// Smallest unsigned integer type that can represent values in the range [0, N].
30/// \ingroup type_traits
31template <unsigned long long N>
33 using type = decltype(detail::determine_smallest_size_t<N>());
34};
35
36/// \ingroup type_traits
37template <unsigned long long N>
38using smallest_size_t = typename smallest_size<N>::type;
39
40} // namespace etl
41
42#endif // TETL_TYPE_TRAITS_SMALLEST_SIZE_T_HPP
Definition adjacent_find.hpp:9
Smallest unsigned integer type that can represent values in the range [0, N].
Definition smallest_size_t.hpp:32