units
Use physical dimensions at compile-time or run-time.
int-types.hpp
Go to the documentation of this file.
1 /// @file vnix/int-types.hpp
2 /// @brief Definition of vnix::int_types.
3 /// @copyright 2019 Thomas E. Vaughan; all rights reserved.
4 /// @license BSD Three-Clause; see LICENSE.
5 
6 #ifndef VNIX_INT_TYPES_HPP
7 #define VNIX_INT_TYPES_HPP
8 
9 #include <cstdint> // for uint_least8_t etc.
10 
11 namespace vnix {
12 
13 
14 /// Smallest integer types for holding certain number of bits.
15 ///
16 /// Generic int_types refers to the int_types with the next-larger number of
17 /// bits. The recursion ends with a terminal specialization: int_types<8>,
18 /// int_types<16>, int_types<32>, or int_types<64>.
19 ///
20 /// @tparam NB Number of bits.
21 template <unsigned NB> struct int_types {
22  static_assert(NB <= 64, "Word must not require more than 64 bits.");
23  using US = typename int_types<NB + 1>::US; ///< Smallest unsigned integer.
24  using SS = typename int_types<NB + 1>::SS; ///< Smallest signed integer.
25  using UF = typename int_types<NB + 1>::UF; ///< Fastest unsigned integer.
26  using SF = typename int_types<NB + 1>::SF; ///< Fastest signed integer.
27 };
28 
29 /// Terminal specialization of int_types for eight-bit integer.
30 template <> struct int_types<8> {
31  using US = uint_least8_t; ///< Smallest unsigned integer.
32  using SS = int_least8_t; ///< Smallest signed integer.
33  using UF = uint_fast8_t; ///< Fastest unsigned integer.
34  using SF = int_fast8_t; ///< Fastest signed integer.
35 };
36 
37 /// Terminal specialization of int_types for 16-bit integer.
38 template <> struct int_types<16> {
39  using US = uint_least16_t; ///< Smallest unsigned integer.
40  using SS = int_least16_t; ///< Smallest signed integer.
41  using UF = uint_fast16_t; ///< Fastest unsigned integer.
42  using SF = int_fast16_t; ///< Fastest signed integer.
43 };
44 
45 /// Terminal specialization of int_types for 32-bit integer.
46 template <> struct int_types<32> {
47  using US = uint_least32_t; ///< Smallest unsigned integer.
48  using SS = int_least32_t; ///< Smallest signed integer.
49  using UF = uint_fast32_t; ///< Fastest unsigned integer.
50  using SF = int_fast32_t; ///< Fastest signed integer.
51 };
52 
53 /// Terminal specialization of int_types for 64-bit integer.
54 template <> struct int_types<64> {
55  using US = uint_least64_t; ///< Smallest unsigned integer.
56  using SS = int_least64_t; ///< Smallest signed integer.
57  using UF = uint_fast64_t; ///< Fastest unsigned integer.
58  using SF = int_fast64_t; ///< Fastest signed integer.
59 };
60 
61 
62 } // namespace vnix
63 
64 #endif // ndef VNIX_INT_TYPES_HPP
Smallest integer types for holding certain number of bits.
Definition: int-types.hpp:21
friend std::ostream & operator<<(std::ostream &s, basic_dim d)
Print to to output stream.
Definition: dim.hpp:251
Thomas E. Vaughan&#39;s public software.
Definition: rational.hpp:13