2021-01-26 19:52:30 -05:00
|
|
|
//
|
|
|
|
// Sizes.hpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 26/01/2021.
|
|
|
|
// Copyright © 2021 Thomas Harte. All rights reserved.
|
|
|
|
//
|
|
|
|
|
2024-01-16 23:34:46 -05:00
|
|
|
#pragma once
|
2021-01-26 19:52:30 -05:00
|
|
|
|
2025-02-04 22:54:39 -05:00
|
|
|
#include <cstdint>
|
2021-03-13 01:27:29 +06:00
|
|
|
#include <limits>
|
2021-06-22 21:31:46 -04:00
|
|
|
#include <type_traits>
|
2021-03-13 01:27:29 +06:00
|
|
|
|
2025-02-04 22:54:39 -05:00
|
|
|
template <int size> struct uint_t_impl;
|
|
|
|
template <> struct uint_t_impl<8> { using type = uint8_t; };
|
|
|
|
template <> struct uint_t_impl<16> { using type = uint16_t; };
|
|
|
|
template <> struct uint_t_impl<32> { using type = uint32_t; };
|
|
|
|
template <> struct uint_t_impl<64> { using type = uint64_t; };
|
|
|
|
|
|
|
|
/// Unsigned integer types templated on size; `uint_t<8> = uint8_t`; `uint_t<16> = uint16_t`, etc.
|
|
|
|
template <int size> using uint_t = typename uint_t_impl<size>::type;
|
|
|
|
|
2021-01-26 19:52:30 -05:00
|
|
|
/*!
|
2021-03-18 12:47:48 -04:00
|
|
|
Maps to the smallest integral type that can contain max_value, from the following options:
|
2021-01-26 19:52:30 -05:00
|
|
|
|
|
|
|
* uint8_t;
|
|
|
|
* uint16_t;
|
|
|
|
* uint32_t; or
|
|
|
|
* uint64_t.
|
|
|
|
*/
|
|
|
|
template <uint64_t max_value> struct MinIntTypeValue {
|
|
|
|
using type =
|
|
|
|
std::conditional_t<
|
|
|
|
max_value <= std::numeric_limits<uint8_t>::max(), uint8_t,
|
|
|
|
std::conditional_t<
|
|
|
|
max_value <= std::numeric_limits<uint16_t>::max(), uint16_t,
|
|
|
|
std::conditional_t<
|
|
|
|
max_value <= std::numeric_limits<uint32_t>::max(), uint32_t,
|
|
|
|
uint64_t
|
|
|
|
>
|
|
|
|
>
|
|
|
|
>;
|
|
|
|
};
|