YSTest  PreAlpha_b500_20140530
The YSLib Test Project
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
cstdint.hpp
浏览该文件的文档.
1 /*
2  Copyright by FrankHB 2013.
3 
4  This file is part of the YSLib project, and may only be used,
5  modified, and distributed under the terms of the YSLib project
6  license, LICENSE.TXT. By continuing to use, modify, or distribute
7  this file you indicate that you have read the license and
8  understand and accept it fully.
9 */
10 
28 #ifndef YB_INC_ystdex_cstdint_hpp_
29 #define YB_INC_ystdex_cstdint_hpp_ 1
30 
31 #include "type_op.hpp"
32 #include <limits>
33 
34 namespace ystdex
35 {
36 
42 template<typename _tInt>
43 struct integer_width : integral_constant<size_t, sizeof(_tInt) * CHAR_BIT>
44 {};
45 
46 
53 template<typename _type, bool>
55 {
57 };
58 
59 template<typename _type>
60 struct make_signed_c<_type, false>
61 {
63 };
65 
66 
74 template<size_t _vWidth>
76 {
77  static_assert(_vWidth <= 64, "Width too large found.");
78 
79  using fast_type = typename make_width_int<(_vWidth <= 8U ? 8U
80  : (_vWidth <= 16U ? 16U : (_vWidth <= 32U ? 32U : 64U)))>::fast_type;
81  using unsigned_fast_type = typename make_width_int<(_vWidth <= 8U ? 8U
82  : (_vWidth <= 16U ? 16U : (_vWidth <= 32U ? 32U : 64U)))>
84  using least_type = typename make_width_int<(_vWidth <= 8U ? 8U
85  : (_vWidth <= 16U ? 16U : (_vWidth <= 32U ? 32U : 64U)))>::least_type;
86  using unsigned_least_type = typename make_width_int<(_vWidth <= 8U ? 8U
87  : (_vWidth <= 16U ? 16U : (_vWidth <= 32U ? 32U : 64U)))>
89 };
90 
91 template<>
92 struct make_width_int<8U>
93 {
94  using type = std::int8_t;
95  using unsigned_type = std::uint8_t;
96  using fast_type = std::int_fast8_t;
97  using unsigned_fast_type = std::uint_fast8_t;
98  using least_type = std::int_least8_t;
99  using unsigned_least_type = std::uint_least8_t;
100 };
101 
102 template<>
103 struct make_width_int<16U>
104 {
105  using type = std::int16_t;
106  using unsigned_type = std::uint16_t;
107  using fast_type = std::int_fast16_t;
108  using unsigned_fast_type = std::uint_fast16_t;
109  using least_type = std::int_least16_t;
110  using unsigned_least_type = std::uint_least16_t;
111 };
112 
113 template<>
114 struct make_width_int<32U>
115 {
116  using type = std::int32_t;
117  using unsigned_type = std::uint32_t;
118  using fast_type = std::int_fast32_t;
119  using unsigned_fast_type = std::uint_fast32_t;
120  using least_type = std::int_least32_t;
121  using unsigned_least_type = std::uint_least32_t;
122 };
123 
124 template<>
125 struct make_width_int<64U>
126 {
127  using type = std::int64_t;
128  using unsigned_type = std::uint64_t;
129  using fast_type = std::int_fast64_t;
130  using unsigned_fast_type = std::uint_fast64_t;
131  using least_type = std::int_least64_t;
132  using unsigned_least_type = std::uint_least64_t;
133 };
135 
136 
145 template<typename _type>
147 {
148  static yconstexpr _type value = is_unsigned<_type>::value
149  ? std::numeric_limits<_type>::max() : _type(0);
150 };
151 
152 
158 template<typename _type1, typename _type2>
159 struct have_same_modulo : integral_constant<bool, uintmax_t(modular_arithmetic<
160  _type1>::value) != 0 && uintmax_t(modular_arithmetic<_type1>::value)
161  == uintmax_t(modular_arithmetic<_type2>::value)>
162 {};
163 
164 } // namespace ystdex;
165 
166 #endif
167 
typename make_unsigned< _type >::type make_unsigned_t
Definition: type_op.hpp:246
std::uint_fast64_t unsigned_fast_type
Definition: cstdint.hpp:130
std::uint_least8_t unsigned_least_type
Definition: cstdint.hpp:99
std::uint8_t unsigned_type
Definition: cstdint.hpp:95
取指定整数类型的位宽度。
Definition: cstdint.hpp:43
判断两个类型是否具有相同的模值。
Definition: cstdint.hpp:159
std::uint_fast32_t unsigned_fast_type
Definition: cstdint.hpp:119
static const _type value
Definition: cstdint.hpp:148
typename make_width_int<(_vWidth<=8U?8U:(_vWidth<=16U?16U:(_vWidth<=32U?32U:64U)))>::unsigned_fast_type unsigned_fast_type
Definition: cstdint.hpp:83
std::int_fast64_t fast_type
Definition: cstdint.hpp:129
std::int_least16_t least_type
Definition: cstdint.hpp:109
取按指定宽度的整数类型。
Definition: cstdint.hpp:75
std::int_fast8_t fast_type
Definition: cstdint.hpp:96
std::int_fast16_t fast_type
Definition: cstdint.hpp:107
std::int_least64_t least_type
Definition: cstdint.hpp:131
typename make_width_int<(_vWidth<=8U?8U:(_vWidth<=16U?16U:(_vWidth<=32U?32U:64U)))>::least_type least_type
Definition: cstdint.hpp:85
std::uint_least64_t unsigned_least_type
Definition: cstdint.hpp:132
typename make_signed< _type >::type make_signed_t
Definition: type_op.hpp:243
取指定整数类型和条件表达式对应的有符号或无符号整数类型。
Definition: cstdint.hpp:54
std::int_fast32_t fast_type
Definition: cstdint.hpp:118
std::uint_least32_t unsigned_least_type
Definition: cstdint.hpp:121
make_signed_t< _type > type
Definition: cstdint.hpp:56
std::int_least8_t least_type
Definition: cstdint.hpp:98
std::int_least32_t least_type
Definition: cstdint.hpp:120
typename make_width_int<(_vWidth<=8U?8U:(_vWidth<=16U?16U:(_vWidth<=32U?32U:64U)))>::unsigned_least_type unsigned_least_type
Definition: cstdint.hpp:88
std::uint_fast16_t unsigned_fast_type
Definition: cstdint.hpp:108
std::uint_least16_t unsigned_least_type
Definition: cstdint.hpp:110
std::uint_fast8_t unsigned_fast_type
Definition: cstdint.hpp:97
#define yconstexpr
指定编译时常量表达式。
Definition: ydef.h:462
C++ 类型操作。
typename make_width_int<(_vWidth<=8U?8U:(_vWidth<=16U?16U:(_vWidth<=32U?32U:64U)))>::fast_type fast_type
Definition: cstdint.hpp:80
make_unsigned_t< _type > type
Definition: cstdint.hpp:62
模算术特性:取得不超过模值的最大值。
Definition: cstdint.hpp:146