YSTest: cstdint.hpp 源文件

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>
54 struct make_signed_c
55 {
56 using type = make_signed_t<_type>;
57 };
58
59 template<typename _type>
60 struct make_signed_c<_type, false>
61 {
62 using type = make_unsigned_t<_type>;
63 };
65
66
74 template<size_t _vWidth>
75 struct make_width_int
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)))>
83 ::unsigned_fast_type;
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)))>
88 ::unsigned_least_type;
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>
146 struct modular_arithmetic
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
ystdex::make_unsigned_t
typename make_unsigned< _type >::type make_unsigned_t
Definition: type_op.hpp:246
ystdex::make_width_int< 64U >::unsigned_fast_type
std::uint_fast64_t unsigned_fast_type
Definition: cstdint.hpp:130
ystdex::make_width_int< 8U >::unsigned_least_type
std::uint_least8_t unsigned_least_type
Definition: cstdint.hpp:99
ystdex::make_width_int< 8U >::unsigned_type
std::uint8_t unsigned_type
Definition: cstdint.hpp:95
ystdex::integer_width
取指定整数类型的位宽度。
Definition: cstdint.hpp:43
ystdex::have_same_modulo
判断两个类型是否具有相同的模值。
Definition: cstdint.hpp:159
ystdex::make_width_int< 32U >::unsigned_fast_type
std::uint_fast32_t unsigned_fast_type
Definition: cstdint.hpp:119
ystdex::modular_arithmetic::value
static const _type value
Definition: cstdint.hpp:148
ystdex::make_width_int::unsigned_fast_type
typename make_width_int<(_vWidth<=8U?8U:(_vWidth<=16U?16U:(_vWidth<=32U?32U:64U)))>::unsigned_fast_type unsigned_fast_type
Definition: cstdint.hpp:83
ystdex::make_width_int< 64U >::unsigned_type
std::uint64_t unsigned_type
Definition: cstdint.hpp:128
ystdex::make_width_int< 64U >::fast_type
std::int_fast64_t fast_type
Definition: cstdint.hpp:129
ystdex::make_width_int< 16U >::least_type
std::int_least16_t least_type
Definition: cstdint.hpp:109
ystdex::make_width_int
取按指定宽度的整数类型。
Definition: cstdint.hpp:75
ystdex::make_width_int< 8U >::fast_type
std::int_fast8_t fast_type
Definition: cstdint.hpp:96
ystdex::make_width_int< 16U >::fast_type
std::int_fast16_t fast_type
Definition: cstdint.hpp:107
ystdex::make_width_int< 64U >::least_type
std::int_least64_t least_type
Definition: cstdint.hpp:131
ystdex::make_width_int< 16U >::unsigned_type
std::uint16_t unsigned_type
Definition: cstdint.hpp:106
ystdex::make_width_int::least_type
typename make_width_int<(_vWidth<=8U?8U:(_vWidth<=16U?16U:(_vWidth<=32U?32U:64U)))>::least_type least_type
Definition: cstdint.hpp:85
ystdex::make_width_int< 64U >::unsigned_least_type
std::uint_least64_t unsigned_least_type
Definition: cstdint.hpp:132
ystdex::make_signed_t
typename make_signed< _type >::type make_signed_t
Definition: type_op.hpp:243
ystdex::make_signed_c
取指定整数类型和条件表达式对应的有符号或无符号整数类型。
Definition: cstdint.hpp:54
ystdex::make_width_int< 16U >::type
std::int16_t type
Definition: cstdint.hpp:105
ystdex::make_width_int< 32U >::fast_type
std::int_fast32_t fast_type
Definition: cstdint.hpp:118
ystdex::make_width_int< 32U >::unsigned_least_type
std::uint_least32_t unsigned_least_type
Definition: cstdint.hpp:121
ystdex::make_signed_c::type
make_signed_t< _type > type
Definition: cstdint.hpp:56
ystdex::make_width_int< 8U >::least_type
std::int_least8_t least_type
Definition: cstdint.hpp:98
ystdex::make_width_int< 32U >::type
std::int32_t type
Definition: cstdint.hpp:116
ystdex::make_width_int< 32U >::least_type
std::int_least32_t least_type
Definition: cstdint.hpp:120
ystdex::make_width_int::unsigned_least_type
typename make_width_int<(_vWidth<=8U?8U:(_vWidth<=16U?16U:(_vWidth<=32U?32U:64U)))>::unsigned_least_type unsigned_least_type
Definition: cstdint.hpp:88
ystdex::make_width_int< 16U >::unsigned_fast_type
std::uint_fast16_t unsigned_fast_type
Definition: cstdint.hpp:108
ystdex::make_width_int< 16U >::unsigned_least_type
std::uint_least16_t unsigned_least_type
Definition: cstdint.hpp:110
ystdex::make_width_int< 64U >::type
std::int64_t type
Definition: cstdint.hpp:127
ystdex::make_width_int< 8U >::unsigned_fast_type
std::uint_fast8_t unsigned_fast_type
Definition: cstdint.hpp:97
yconstexpr
#define yconstexpr
指定编译时常量表达式。
Definition: ydef.h:462
ystdex::make_width_int< 8U >::type
std::int8_t type
Definition: cstdint.hpp:94
type_op.hpp
C++ 类型操作。
ystdex::make_width_int::fast_type
typename make_width_int<(_vWidth<=8U?8U:(_vWidth<=16U?16U:(_vWidth<=32U?32U:64U)))>::fast_type fast_type
Definition: cstdint.hpp:80
ystdex::make_signed_c< _type, false >::type
make_unsigned_t< _type > type
Definition: cstdint.hpp:62
ystdex::make_width_int< 32U >::unsigned_type
std::uint32_t unsigned_type
Definition: cstdint.hpp:117
ystdex::modular_arithmetic
模算术特性：取得不超过模值的最大值。
Definition: cstdint.hpp:146