Skip to content

Commit 835f10d

Browse files
AZero13StephanTLavavej
authored andcommitted
Use std::size over sizeof/sizeof (microsoft#3090)
Co-authored-by: Stephan T. Lavavej <[email protected]>
1 parent a7e660d commit 835f10d

File tree

9 files changed

+17
-13
lines changed

9 files changed

+17
-13
lines changed

stl/inc/cvt/wbuffer

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ namespace stdext {
189189
}
190190

191191
int_type pbackfail(int_type _Meta = _Traits::eof()) override { // put an element back to stream
192-
if (sizeof(_Myback) / sizeof(_Myback[0]) <= _Nback || _Status == _Wrote) {
192+
if (_STD size(_Myback) <= _Nback || _Status == _Wrote) {
193193
return _Traits::eof(); // nowhere to put back
194194
} else { // enough room, put it back
195195
if (!_Traits::eq_int_type(_Traits::eof(), _Meta)) {

stl/inc/cvt/xjis

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ namespace stdext {
4545
}
4646
} else { // search for a valid mapping
4747
unsigned long _Lo = 0;
48-
unsigned long _Hi = sizeof(_Table::_Dbvalid) / sizeof(_Table::_Dbvalid[0]);
48+
unsigned long _Hi = static_cast<unsigned long>(_STD size(_Table::_Dbvalid));
4949

5050
while (_Lo < _Hi) { // test midpoint of remaining interval
5151
unsigned long _Mid = (_Hi + _Lo) / 2;
@@ -72,7 +72,7 @@ namespace stdext {
7272

7373
// search for a valid mapping
7474
unsigned long _Lo = 0;
75-
unsigned long _Hi = sizeof(_Table::_Wvalid) / sizeof(_Table::_Wvalid[0]);
75+
unsigned long _Hi = static_cast<unsigned long>(_STD size(_Table::_Wvalid));
7676

7777
while (_Lo < _Hi) { // test midpoint of remaining interval
7878
unsigned long _Mid = (_Hi + _Lo) / 2;

stl/inc/cvt/xone_byte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ namespace stdext {
7575
&& (_Widecode >= 0x100
7676
|| _Table::_Btw[_Widecode - _Table::_Nlow] != _Widecode)) { // search for a valid mapping
7777
unsigned long _Lo = 0;
78-
unsigned long _Hi = sizeof(_Table::_Wvalid) / sizeof(_Table::_Wvalid[0]);
78+
unsigned long _Hi = static_cast<unsigned long>(_STD size(_Table::_Wvalid));
7979

8080
while (_Lo < _Hi) { // test midpoint of remaining interval
8181
unsigned long _Mid = (_Hi + _Lo) / 2;

stl/inc/cvt/xtwo_byte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ namespace stdext {
6262
_Widecode =
6363
static_cast<unsigned short>(_Bytecode << 8 | static_cast<unsigned char>(*++_Mid1));
6464
unsigned long _Lo = 0;
65-
unsigned long _Hi = sizeof(_Table::_Dbvalid) / sizeof(_Table::_Dbvalid[0]);
65+
unsigned long _Hi = static_cast<unsigned long>(_STD size(_Table::_Dbvalid));
6666

6767
while (_Lo < _Hi) { // test midpoint of remaining interval
6868
unsigned long _Mid = (_Hi + _Lo) / 2;
@@ -110,7 +110,7 @@ namespace stdext {
110110
&& (_Widecode >= 0x100
111111
|| _Table::_Btw[_Widecode - _Table::_Nlow] != _Widecode)) { // search for a valid mapping
112112
unsigned long _Lo = 0;
113-
unsigned long _Hi = sizeof(_Table::_Wvalid) / sizeof(_Table::_Wvalid[0]);
113+
unsigned long _Hi = static_cast<unsigned long>(_STD size(_Table::_Wvalid));
114114

115115
while (_Lo < _Hi) { // test midpoint of remaining interval
116116
unsigned long _Mid = (_Hi + _Lo) / 2;

stl/inc/regex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ public:
300300
char_class_type lookup_classname(_Iter _First, _Iter _Last, bool _Icase = false) const {
301301
// map [_First, _Last) to character class mask value
302302
#define _REGEX_CHAR_CLASS_NAME(n, c) \
303-
{ n, L##n, sizeof(n) / sizeof(n[0]) - 1, c }
303+
{ n, L##n, static_cast<unsigned int>(_STD size(n) - 1), c }
304304
static constexpr _Cl_names _Names[] = {
305305
// map class names to numeric constants
306306
_REGEX_CHAR_CLASS_NAME("alnum", _Ch_alnum),

stl/inc/xlocbuf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ protected:
174174
}
175175

176176
int_type pbackfail(int_type _Meta = _Traits::eof()) override { // put an element back to stream
177-
if (sizeof(_Myback) / sizeof(_Myback[0]) <= _Nback || _Status == _Wrote) {
177+
if (_STD size(_Myback) <= _Nback || _Status == _Wrote) {
178178
return _Traits::eof(); // nowhere to put back
179179
} else { // enough room, put it back
180180
if (!_Traits::eq_int_type(_Traits::eof(), _Meta)) {

stl/src/xdateord.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ _EXTERN_C_UNLESS_PURE
1111

1212
_CRTIMP2_PURE int __CLRCALL_PURE_OR_CDECL _Getdateorder() { // return date order for current locale
1313
wchar_t buf[2] = {0};
14-
GetLocaleInfoEx(___lc_locale_name_func()[LC_TIME], LOCALE_ILDATE, buf, sizeof(buf) / sizeof(buf[0]));
14+
GetLocaleInfoEx(___lc_locale_name_func()[LC_TIME], LOCALE_ILDATE, buf, static_cast<int>(std::size(buf)));
1515

1616
switch (buf[0]) {
1717
case L'0':

stl/src/xlsinh.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,18 @@
33

44
// _LSinh function
55

6+
#include <xutility>
7+
68
#include "xmath.hpp"
79

810
_EXTERN_C_UNLESS_PURE
911

1012
// coefficients
11-
static const long double p[] = {0.0000000000000028486835L, 0.0000000000007646464279L, 0.0000000001605905091647L,
13+
static constexpr long double p[] = {0.0000000000000028486835L, 0.0000000000007646464279L, 0.0000000001605905091647L,
1214
0.0000000250521083436962L, 0.0000027557319224130455L, 0.0001984126984126956009L, 0.0083333333333333336073L,
1315
0.1666666666666666666564L, 1.0000000000000000000001L};
1416

15-
static constexpr size_t NP = sizeof(p) / sizeof(p[0]) - 1;
17+
static constexpr size_t NP = std::size(p) - 1;
1618

1719
_CRTIMP2_PURE long double __CLRCALL_PURE_OR_CDECL _LSinh(long double x, long double y) {
1820
// compute y * sinh(x), |y| <= 1
@@ -40,7 +42,7 @@ _CRTIMP2_PURE long double __CLRCALL_PURE_OR_CDECL _LSinh(long double x, long dou
4042
if (x < _LRteps._Long_double) {
4143
x *= y; // x tiny
4244
} else if (x < 1.0L) {
43-
long double w = x * x;
45+
const long double w = x * x;
4446

4547
x += x * w * _LPoly(w, p, NP - 1);
4648
x *= y;

stl/src/xsinh.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
// _Sinh function
55

6+
#include <xutility>
7+
68
#include "xmath.hpp"
79

810
_EXTERN_C_UNLESS_PURE
@@ -11,7 +13,7 @@ _EXTERN_C_UNLESS_PURE
1113
static constexpr double p[] = {0.0000000001632881, 0.0000000250483893, 0.0000027557344615, 0.0001984126975233,
1214
0.0083333333334816, 0.1666666666666574, 1.0000000000000001};
1315

14-
static constexpr size_t NP = sizeof(p) / sizeof(p[0]) - 1;
16+
static constexpr size_t NP = std::size(p) - 1;
1517

1618
_CRTIMP2_PURE double __CLRCALL_PURE_OR_CDECL _Sinh(double x, double y) { // compute y * sinh(x), |y| <= 1
1719
short neg;

0 commit comments

Comments
 (0)