Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
F
fmt
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
fmt
Commits
0fbd8465
Commit
0fbd8465
authored
Sep 04, 2017
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replace fmt::internal::make_unsigned with std::make_unsigned
parent
8a2bc0ab
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
17 additions
and
25 deletions
+17
-25
fmt/format.h
fmt/format.h
+2
-18
fmt/ostream.cc
fmt/ostream.cc
+1
-1
fmt/printf.h
fmt/printf.h
+10
-2
test/ostream-test.cc
test/ostream-test.cc
+1
-1
test/printf-test.cc
test/printf-test.cc
+3
-3
No files found.
fmt/format.h
View file @
0fbd8465
...
...
@@ -488,27 +488,11 @@ struct formatter;
namespace
internal
{
// make_unsigned<T>::type gives an unsigned type corresponding to integer
// type T.
template
<
typename
T
>
struct
make_unsigned
{
typedef
T
type
;
};
#define FMT_SPECIALIZE_MAKE_UNSIGNED(T, U) \
template <> \
struct make_unsigned<T> { typedef U type; }
FMT_SPECIALIZE_MAKE_UNSIGNED
(
char
,
unsigned
char
);
FMT_SPECIALIZE_MAKE_UNSIGNED
(
signed
char
,
unsigned
char
);
FMT_SPECIALIZE_MAKE_UNSIGNED
(
short
,
unsigned
short
);
FMT_SPECIALIZE_MAKE_UNSIGNED
(
int
,
unsigned
);
FMT_SPECIALIZE_MAKE_UNSIGNED
(
long
,
unsigned
long
);
FMT_SPECIALIZE_MAKE_UNSIGNED
(
long
long
,
unsigned
long
long
);
// Casts nonnegative integer to unsigned.
template
<
typename
Int
>
inline
typename
make_unsigned
<
Int
>::
type
to_unsigned
(
Int
value
)
{
inline
typename
std
::
make_unsigned
<
Int
>::
type
to_unsigned
(
Int
value
)
{
FMT_ASSERT
(
value
>=
0
,
"negative value"
);
return
static_cast
<
typename
make_unsigned
<
Int
>::
type
>
(
value
);
return
static_cast
<
typename
std
::
make_unsigned
<
Int
>::
type
>
(
value
);
}
// The number of characters to store in the basic_memory_buffer object itself
...
...
fmt/ostream.cc
View file @
0fbd8465
...
...
@@ -14,7 +14,7 @@ namespace fmt {
namespace
internal
{
FMT_FUNC
void
write
(
std
::
ostream
&
os
,
buffer
&
buf
)
{
const
char
*
data
=
buf
.
data
();
typedef
internal
::
make_unsigned
<
std
::
streamsize
>::
type
UnsignedStreamSize
;
typedef
std
::
make_unsigned
<
std
::
streamsize
>::
type
UnsignedStreamSize
;
UnsignedStreamSize
size
=
buf
.
size
();
UnsignedStreamSize
max_size
=
internal
::
to_unsigned
((
std
::
numeric_limits
<
std
::
streamsize
>::
max
)());
...
...
fmt/printf.h
View file @
0fbd8465
...
...
@@ -70,6 +70,14 @@ class IsZeroInt {
operator
()(
T
)
{
return
false
;
}
};
template
<
typename
T
>
struct
make_unsigned_or_bool
:
std
::
make_unsigned
<
T
>
{};
template
<
>
struct
make_unsigned_or_bool
<
bool
>
{
using
type
=
bool
;
};
template
<
typename
T
,
typename
Context
>
class
ArgConverter
{
private:
...
...
@@ -99,7 +107,7 @@ class ArgConverter {
arg_
=
internal
::
make_arg
<
Context
>
(
static_cast
<
int
>
(
static_cast
<
TargetType
>
(
value
)));
}
else
{
typedef
typename
internal
::
make_unsigned
<
TargetType
>::
type
Unsigned
;
typedef
typename
make_unsigned_or_bool
<
TargetType
>::
type
Unsigned
;
arg_
=
internal
::
make_arg
<
Context
>
(
static_cast
<
unsigned
>
(
static_cast
<
Unsigned
>
(
value
)));
}
...
...
@@ -111,7 +119,7 @@ class ArgConverter {
arg_
=
internal
::
make_arg
<
Context
>
(
static_cast
<
long
long
>
(
value
));
}
else
{
arg_
=
internal
::
make_arg
<
Context
>
(
static_cast
<
typename
internal
::
make_unsigned
<
U
>::
type
>
(
value
));
static_cast
<
typename
make_unsigned_or_bool
<
U
>::
type
>
(
value
));
}
}
}
...
...
test/ostream-test.cc
View file @
0fbd8465
...
...
@@ -155,7 +155,7 @@ TEST(OStreamTest, WriteToOStreamMaxSize) {
const
char
*
data
=
0
;
std
::
size_t
size
=
max_size
;
do
{
typedef
fmt
::
internal
::
make_unsigned
<
std
::
streamsize
>::
type
UStreamSize
;
typedef
std
::
make_unsigned
<
std
::
streamsize
>::
type
UStreamSize
;
UStreamSize
n
=
std
::
min
<
UStreamSize
>
(
size
,
fmt
::
internal
::
to_unsigned
(
max_streamsize
));
EXPECT_CALL
(
streambuf
,
xsputn
(
data
,
static_cast
<
std
::
streamsize
>
(
n
)))
...
...
test/printf-test.cc
View file @
0fbd8465
...
...
@@ -306,13 +306,13 @@ void TestLength(const char *length_spec, U value) {
signed_value
=
static_cast
<
unsigned
>
(
value
);
unsigned_value
=
static_cast
<
unsigned
>
(
value
);
}
using
fmt
::
internal
::
make_unsigned
;
if
(
sizeof
(
U
)
<=
sizeof
(
int
)
&&
sizeof
(
int
)
<
sizeof
(
T
))
{
signed_value
=
static_cast
<
long
long
>
(
value
);
unsigned_value
=
static_cast
<
typename
make_unsigned
<
unsigned
>::
type
>
(
value
);
unsigned_value
=
static_cast
<
typename
std
::
make_unsigned
<
unsigned
>::
type
>
(
value
);
}
else
{
signed_value
=
static_cast
<
typename
make_signed
<
T
>::
type
>
(
value
);
unsigned_value
=
static_cast
<
typename
make_unsigned
<
T
>::
type
>
(
value
);
unsigned_value
=
static_cast
<
typename
std
::
make_unsigned
<
T
>::
type
>
(
value
);
}
std
::
ostringstream
os
;
os
<<
signed_value
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment