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
1882b968
Commit
1882b968
authored
Sep 05, 2019
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reduce the numer of ifdefs with an empty (u)int128_t fallback
parent
6de0454b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
63 deletions
+48
-63
include/fmt/core.h
include/fmt/core.h
+26
-24
include/fmt/format.h
include/fmt/format.h
+10
-27
test/format-test.cc
test/format-test.cc
+12
-12
No files found.
include/fmt/core.h
View file @
1882b968
...
...
@@ -195,14 +195,6 @@
# define FMT_USE_EXPERIMENTAL_STRING_VIEW
#endif
#ifdef FMT_USE_INT128
// Do nothing.
#elif defined(__SIZEOF_INT128__)
# define FMT_USE_INT128 1
#else
# define FMT_USE_INT128 0
#endif
FMT_BEGIN_NAMESPACE
// Implementations of enable_if_t and other types for pre-C++14 systems.
...
...
@@ -239,6 +231,20 @@ using std_string_view = std::experimental::basic_string_view<Char>;
template
<
typename
T
>
struct
std_string_view
{};
#endif
#ifdef FMT_USE_INT128
// Do nothing.
#elif defined(__SIZEOF_INT128__)
# define FMT_USE_INT128 1
using
int128_t
=
__int128_t
;
using
uint128_t
=
__uint128_t
;
#else
# define FMT_USE_INT128 0
#endif
#if !FMT_USE_INT128
struct
int128_t
{};
struct
uint128_t
{};
#endif
// Casts nonnegative integer to unsigned.
template
<
typename
Int
>
FMT_CONSTEXPR
typename
std
::
make_unsigned
<
Int
>::
type
to_unsigned
(
Int
value
)
{
...
...
@@ -673,10 +679,8 @@ FMT_TYPE_CONSTANT(int, int_type);
FMT_TYPE_CONSTANT
(
unsigned
,
uint_type
);
FMT_TYPE_CONSTANT
(
long
long
,
long_long_type
);
FMT_TYPE_CONSTANT
(
unsigned
long
long
,
ulong_long_type
);
#if FMT_USE_INT128
FMT_TYPE_CONSTANT
(
__int128_t
,
int128_type
);
FMT_TYPE_CONSTANT
(
__uint128_t
,
uint128_type
);
#endif
FMT_TYPE_CONSTANT
(
int128_t
,
int128_type
);
FMT_TYPE_CONSTANT
(
uint128_t
,
uint128_type
);
FMT_TYPE_CONSTANT
(
bool
,
bool_type
);
FMT_TYPE_CONSTANT
(
Char
,
char_type
);
FMT_TYPE_CONSTANT
(
double
,
double_type
);
...
...
@@ -716,10 +720,8 @@ template <typename Context> class value {
unsigned
uint_value
;
long
long
long_long_value
;
unsigned
long
long
ulong_long_value
;
#if FMT_USE_INT128
__int128_t
int128_value
;
__uint128_t
uint128_value
;
#endif
int128_t
int128_value
;
uint128_t
uint128_value
;
bool
bool_value
;
char_type
char_value
;
double
double_value
;
...
...
@@ -734,10 +736,8 @@ template <typename Context> class value {
FMT_CONSTEXPR
value
(
unsigned
val
)
:
uint_value
(
val
)
{}
value
(
long
long
val
)
:
long_long_value
(
val
)
{}
value
(
unsigned
long
long
val
)
:
ulong_long_value
(
val
)
{}
#if FMT_USE_INT128
value
(
__int128_t
val
)
:
int128_value
(
val
)
{}
value
(
__uint128_t
val
)
:
uint128_value
(
val
)
{}
#endif
value
(
int128_t
val
)
:
int128_value
(
val
)
{}
value
(
uint128_t
val
)
:
uint128_value
(
val
)
{}
value
(
double
val
)
:
double_value
(
val
)
{}
value
(
long
double
val
)
:
long_double_value
(
val
)
{}
value
(
bool
val
)
:
bool_value
(
val
)
{}
...
...
@@ -797,10 +797,8 @@ template <typename Context> struct arg_mapper {
FMT_CONSTEXPR
ulong_type
map
(
unsigned
long
val
)
{
return
val
;
}
FMT_CONSTEXPR
long
long
map
(
long
long
val
)
{
return
val
;
}
FMT_CONSTEXPR
unsigned
long
long
map
(
unsigned
long
long
val
)
{
return
val
;
}
#if FMT_USE_INT128
FMT_CONSTEXPR
__int128_t
map
(
__int128_t
val
)
{
return
val
;
}
FMT_CONSTEXPR
__uint128_t
map
(
__uint128_t
val
)
{
return
val
;
}
#endif
FMT_CONSTEXPR
int128_t
map
(
int128_t
val
)
{
return
val
;
}
FMT_CONSTEXPR
uint128_t
map
(
uint128_t
val
)
{
return
val
;
}
FMT_CONSTEXPR
bool
map
(
bool
val
)
{
return
val
;
}
template
<
typename
T
,
FMT_ENABLE_IF
(
is_char
<
T
>
::
value
)
>
...
...
@@ -966,6 +964,10 @@ FMT_CONSTEXPR auto visit_format_arg(Visitor&& vis,
return
vis
(
arg
.
value_
.
int128_value
);
case
internal
:
:
uint128_type
:
return
vis
(
arg
.
value_
.
uint128_value
);
#else
case
internal
:
:
int128_type
:
case
internal
:
:
uint128_type
:
break
;
#endif
case
internal
:
:
bool_type
:
return
vis
(
arg
.
value_
.
bool_value
);
...
...
include/fmt/format.h
View file @
1882b968
...
...
@@ -636,20 +636,12 @@ FMT_CONSTEXPR bool is_negative(T) {
return
false
;
}
#if FMT_USE_INT128
// Smallest of uint32_t, uint64_t, unsigned __int128 that is large enough to
// Smallest of uint32_t, uint64_t, uint128_t that is large enough to
// represent all values of T.
template
<
typename
T
>
using
uint32_or_64_or_128_t
=
conditional_t
<
std
::
numeric_limits
<
T
>::
digits
<=
32
,
uint32_t
,
conditional_t
<
std
::
numeric_limits
<
T
>::
digits
<=
64
,
uint64_t
,
__uint128_t
>>
;
#else
// Smallest of uint32_t and uint64_t that is large enough to represent all
// values of T.
template
<
typename
T
>
using
uint32_or_64_or_128_t
=
conditional_t
<
std
::
numeric_limits
<
T
>::
digits
<=
32
,
uint32_t
,
uint64_t
>
;
#endif
conditional_t
<
std
::
numeric_limits
<
T
>::
digits
<=
64
,
uint64_t
,
uint128_t
>>
;
// Static data is placed in this class template for the header-only config.
template
<
typename
T
=
void
>
struct
FMT_EXTERN_TEMPLATE_API
basic_data
{
...
...
@@ -699,7 +691,7 @@ inline int count_digits(uint64_t n) {
#endif
#if FMT_USE_INT128
inline
int
count_digits
(
__
uint128_t
n
)
{
inline
int
count_digits
(
uint128_t
n
)
{
int
count
=
1
;
for
(;;)
{
// Integer division is slow so do it for a group of four digits instead
...
...
@@ -847,12 +839,8 @@ inline Char* format_decimal(Char* buffer, UInt value, int num_digits,
template
<
typename
Int
>
constexpr
int
digits10
()
noexcept
{
return
std
::
numeric_limits
<
Int
>::
digits10
;
}
#if FMT_USE_INT128
template
<
>
constexpr
int
digits10
<
__int128_t
>
()
noexcept
{
return
38
;
}
template
<
>
constexpr
int
digits10
<
__uint128_t
>
()
noexcept
{
return
38
;
}
#endif
template
<
>
constexpr
int
digits10
<
int128_t
>
()
noexcept
{
return
38
;
}
template
<
>
constexpr
int
digits10
<
uint128_t
>
()
noexcept
{
return
38
;
}
template
<
typename
Char
,
typename
UInt
,
typename
Iterator
,
typename
F
>
inline
Iterator
format_decimal
(
Iterator
out
,
UInt
value
,
int
num_digits
,
...
...
@@ -1644,15 +1632,14 @@ template <typename Range> class basic_writer {
void
write
(
int
value
)
{
write_decimal
(
value
);
}
void
write
(
long
value
)
{
write_decimal
(
value
);
}
void
write
(
long
long
value
)
{
write_decimal
(
value
);
}
#if FMT_USE_INT128
void
write
(
__int128_t
value
)
{
write_decimal
(
value
);
}
#endif
void
write
(
unsigned
value
)
{
write_decimal
(
value
);
}
void
write
(
unsigned
long
value
)
{
write_decimal
(
value
);
}
void
write
(
unsigned
long
long
value
)
{
write_decimal
(
value
);
}
#if FMT_USE_INT128
void
write
(
__uint128_t
value
)
{
write_decimal
(
value
);
}
void
write
(
int128_t
value
)
{
write_decimal
(
value
);
}
void
write
(
uint128_t
value
)
{
write_decimal
(
value
);
}
#endif
// Writes a formatted integer.
...
...
@@ -1737,12 +1724,8 @@ template <typename Range> class basic_writer {
using
writer
=
basic_writer
<
buffer_range
<
char
>>
;
template
<
typename
T
>
struct
is_integral
:
std
::
is_integral
<
T
>
{};
#if FMT_USE_INT128
template
<
>
struct
is_integral
<
__int128_t
>
:
std
::
true_type
{};
template
<
>
struct
is_integral
<
__uint128_t
>
:
std
::
true_type
{};
#endif
template
<
>
struct
is_integral
<
int128_t
>
:
std
::
true_type
{};
template
<
>
struct
is_integral
<
uint128_t
>
:
std
::
true_type
{};
template
<
typename
Range
,
typename
ErrorHandler
=
internal
::
error_handler
>
class
arg_formatter_base
{
...
...
test/format-test.cc
View file @
1882b968
...
...
@@ -1334,11 +1334,11 @@ TEST(FormatterTest, FormatBin) {
}
#if FMT_USE_INT128
constexpr
auto
INT128_MAX
=
static_cast
<
__int128_t
>
(
constexpr
auto
int128_max
=
static_cast
<
__int128_t
>
(
(
static_cast
<
__uint128_t
>
(
1
)
<<
((
__SIZEOF_INT128__
*
CHAR_BIT
)
-
1
))
-
1
);
constexpr
auto
INT128_MIN
=
-
INT128_MAX
-
1
;
constexpr
auto
int128_min
=
-
int128_max
-
1
;
constexpr
auto
UINT128_MAX
=
~
static_cast
<
__uint128_t
>
(
0
);
constexpr
auto
uint128_max
=
~
static_cast
<
__uint128_t
>
(
0
);
#endif
TEST
(
FormatterTest
,
FormatDec
)
{
...
...
@@ -1359,11 +1359,11 @@ TEST(FormatterTest, FormatDec) {
EXPECT_EQ
(
"18446744073709551616"
,
format
(
"{0}"
,
static_cast
<
__int128_t
>
(
UINT64_MAX
)
+
1
));
EXPECT_EQ
(
"170141183460469231731687303715884105727"
,
format
(
"{0}"
,
INT128_MAX
));
format
(
"{0}"
,
int128_max
));
EXPECT_EQ
(
"-170141183460469231731687303715884105728"
,
format
(
"{0}"
,
INT128_MIN
));
format
(
"{0}"
,
int128_min
));
EXPECT_EQ
(
"340282366920938463463374607431768211455"
,
format
(
"{0}"
,
UINT128_MAX
));
format
(
"{0}"
,
uint128_max
));
#endif
char
buffer
[
BUFFER_SIZE
];
...
...
@@ -1399,9 +1399,9 @@ TEST(FormatterTest, FormatHex) {
format
(
"{0:x}"
,
static_cast
<
__int128_t
>
(
INT64_MIN
)
-
1
));
EXPECT_EQ
(
"10000000000000000"
,
format
(
"{0:x}"
,
static_cast
<
__int128_t
>
(
UINT64_MAX
)
+
1
));
EXPECT_EQ
(
"7fffffffffffffffffffffffffffffff"
,
format
(
"{0:x}"
,
INT128_MAX
));
EXPECT_EQ
(
"-80000000000000000000000000000000"
,
format
(
"{0:x}"
,
INT128_MIN
));
EXPECT_EQ
(
"ffffffffffffffffffffffffffffffff"
,
format
(
"{0:x}"
,
UINT128_MAX
));
EXPECT_EQ
(
"7fffffffffffffffffffffffffffffff"
,
format
(
"{0:x}"
,
int128_max
));
EXPECT_EQ
(
"-80000000000000000000000000000000"
,
format
(
"{0:x}"
,
int128_min
));
EXPECT_EQ
(
"ffffffffffffffffffffffffffffffff"
,
format
(
"{0:x}"
,
uint128_max
));
#endif
char
buffer
[
BUFFER_SIZE
];
...
...
@@ -1435,11 +1435,11 @@ TEST(FormatterTest, FormatOct) {
EXPECT_EQ
(
"2000000000000000000000"
,
format
(
"{0:o}"
,
static_cast
<
__int128_t
>
(
UINT64_MAX
)
+
1
));
EXPECT_EQ
(
"1777777777777777777777777777777777777777777"
,
format
(
"{0:o}"
,
INT128_MAX
));
format
(
"{0:o}"
,
int128_max
));
EXPECT_EQ
(
"-2000000000000000000000000000000000000000000"
,
format
(
"{0:o}"
,
INT128_MIN
));
format
(
"{0:o}"
,
int128_min
));
EXPECT_EQ
(
"3777777777777777777777777777777777777777777"
,
format
(
"{0:o}"
,
UINT128_MAX
));
format
(
"{0:o}"
,
uint128_max
));
#endif
char
buffer
[
BUFFER_SIZE
];
...
...
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