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
04b34322
Commit
04b34322
authored
Feb 20, 2014
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify IntTraits.
parent
90d0c50e
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
30 deletions
+24
-30
format.h
format.h
+24
-30
No files found.
format.h
View file @
04b34322
...
...
@@ -220,38 +220,33 @@ struct TypeSelector { typedef uint32_t Type; };
template
<
>
struct
TypeSelector
<
false
>
{
typedef
uint64_t
Type
;
};
template
<
typename
T
>
struct
IntTraitsBase
{
// Smallest of uint32_t and uint64_t that is large enough to represent
// all values of T.
typedef
typename
TypeSelector
<
std
::
numeric_limits
<
T
>::
digits
<=
32
>::
Type
MainType
;
};
// Information about an integer type.
template
<
typename
T
>
struct
IntTraits
:
IntTraitsBase
<
T
>
{
typedef
T
UnsignedType
;
static
bool
IsNegative
(
T
)
{
return
false
;
}
// Checks if a number is negative - used to avoid warnings.
template
<
bool
IsSigned
>
struct
SignChecker
{
template
<
typename
T
>
static
bool
IsNegative
(
T
value
)
{
return
false
;
}
};
template
<
typename
T
,
typename
UnsignedT
>
struct
Sign
edIntTraits
:
IntTraitsBase
<
T
>
{
t
ypedef
UnsignedT
UnsignedType
;
template
<
>
struct
Sign
Checker
<
true
>
{
t
emplate
<
typename
T
>
static
bool
IsNegative
(
T
value
)
{
return
value
<
0
;
}
};
#define FMT_INT_TRAIT(Type) \
template <> \
struct IntTraits<Type> : SignedIntTraits<Type, unsigned Type> {};
FMT_INT_TRAIT
(
char
)
FMT_INT_TRAIT
(
short
)
FMT_INT_TRAIT
(
int
)
FMT_INT_TRAIT
(
long
)
// Returns true if value is negative, false otherwise.
// Same as (value < 0) but doesn't produce warnings if T is an unsigned type.
template
<
typename
T
>
inline
bool
IsNegative
(
T
value
)
{
return
SignChecker
<
std
::
numeric_limits
<
T
>::
is_signed
>::
IsNegative
(
value
);
}
template
<
>
struct
IntTraits
<
LongLong
>
:
SignedIntTraits
<
LongLong
,
ULongLong
>
{};
template
<
typename
T
>
struct
IntTraits
{
// Smallest of uint32_t and uint64_t that is large enough to represent
// all values of T.
typedef
typename
TypeSelector
<
std
::
numeric_limits
<
T
>::
digits
<=
32
>::
Type
MainType
;
};
template
<
typename
T
>
struct
IsLongDouble
{
enum
{
VALUE
=
0
};
};
...
...
@@ -867,7 +862,7 @@ void BasicWriter<Char>::FormatInt(T value, const Spec &spec) {
char
sign
=
0
;
typedef
typename
internal
::
IntTraits
<
T
>::
MainType
UnsignedType
;
UnsignedType
abs_value
=
value
;
if
(
internal
::
IntTraits
<
T
>::
IsNegative
(
value
)
)
{
if
(
value
<
0
)
{
sign
=
'-'
;
++
size
;
abs_value
=
0
-
abs_value
;
...
...
@@ -877,8 +872,7 @@ void BasicWriter<Char>::FormatInt(T value, const Spec &spec) {
}
switch
(
spec
.
type
())
{
case
0
:
case
'd'
:
{
typename
internal
::
IntTraits
<
T
>::
MainType
normalized_value
=
abs_value
;
unsigned
num_digits
=
internal
::
CountDigits
(
normalized_value
);
unsigned
num_digits
=
internal
::
CountDigits
(
abs_value
);
CharPtr
p
=
PrepareFilledBuffer
(
size
+
num_digits
,
spec
,
sign
)
+
1
-
num_digits
;
internal
::
FormatDecimal
(
GetBase
(
p
),
abs_value
,
num_digits
);
...
...
@@ -1409,7 +1403,7 @@ class FormatInt {
template
<
typename
T
>
inline
void
FormatDec
(
char
*&
buffer
,
T
value
)
{
typename
internal
::
IntTraits
<
T
>::
MainType
abs_value
=
value
;
if
(
internal
::
I
ntTraits
<
T
>::
I
sNegative
(
value
))
{
if
(
internal
::
IsNegative
(
value
))
{
*
buffer
++
=
'-'
;
abs_value
=
0
-
abs_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