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
78166ccd
Commit
78166ccd
authored
Feb 11, 2018
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Get rid of generic lambdas
parent
d8ef8a9e
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
60 additions
and
22 deletions
+60
-22
include/fmt/format.h
include/fmt/format.h
+60
-22
No files found.
include/fmt/format.h
View file @
78166ccd
...
@@ -2216,6 +2216,22 @@ class basic_writer {
...
@@ -2216,6 +2216,22 @@ class basic_writer {
template
<
typename
F
>
template
<
typename
F
>
void
write_padded
(
std
::
size_t
size
,
const
align_spec
&
spec
,
F
f
);
void
write_padded
(
std
::
size_t
size
,
const
align_spec
&
spec
,
F
f
);
template
<
typename
F
>
struct
padded_int_writer
{
string_view
prefix
;
wchar_t
fill
;
unsigned
padding
;
F
f
;
template
<
typename
It
>
void
operator
()(
It
&&
it
)
const
{
if
(
prefix
.
size
()
!=
0
)
it
=
std
::
copy_n
(
prefix
.
data
(),
prefix
.
size
(),
it
);
it
=
std
::
fill_n
(
it
,
padding
,
fill
);
f
(
it
);
}
};
// Writes an integer in the format
// Writes an integer in the format
// <left-padding><prefix><numeric-padding><digits><right-padding>
// <left-padding><prefix><numeric-padding><digits><right-padding>
// where <digits> are written by f(it).
// where <digits> are written by f(it).
...
@@ -2238,12 +2254,7 @@ class basic_writer {
...
@@ -2238,12 +2254,7 @@ class basic_writer {
align_spec
as
=
spec
;
align_spec
as
=
spec
;
if
(
spec
.
align
()
==
ALIGN_DEFAULT
)
if
(
spec
.
align
()
==
ALIGN_DEFAULT
)
as
.
align_
=
ALIGN_RIGHT
;
as
.
align_
=
ALIGN_RIGHT
;
write_padded
(
size
,
as
,
[
prefix
,
fill
,
padding
,
f
](
auto
&&
it
)
{
write_padded
(
size
,
as
,
padded_int_writer
<
F
>
{
prefix
,
fill
,
padding
,
f
});
if
(
prefix
.
size
()
!=
0
)
it
=
std
::
copy_n
(
prefix
.
data
(),
prefix
.
size
(),
it
);
it
=
std
::
fill_n
(
it
,
padding
,
fill
);
f
(
it
);
});
}
}
// Writes a decimal integer.
// Writes a decimal integer.
...
@@ -2368,16 +2379,54 @@ class basic_writer {
...
@@ -2368,16 +2379,54 @@ class basic_writer {
int_writer
<
T
,
Spec
>
(
*
this
,
value
,
spec
));
int_writer
<
T
,
Spec
>
(
*
this
,
value
,
spec
));
}
}
enum
{
INF_SIZE
=
3
};
// This is an enum to workaround a bug in MSVC.
struct
inf_or_nan_writer
{
char
sign
;
const
char
*
str
;
template
<
typename
It
>
void
operator
()(
It
&&
it
)
const
{
if
(
sign
)
*
it
++
=
sign
;
it
=
std
::
copy_n
(
str
,
static_cast
<
std
::
size_t
>
(
INF_SIZE
),
it
);
}
};
struct
double_writer
{
unsigned
n
;
char
sign
;
basic_memory_buffer
<
char_type
>
&
buffer
;
template
<
typename
It
>
void
operator
()(
It
&&
it
)
{
if
(
sign
)
{
*
it
++
=
sign
;
--
n
;
}
it
=
std
::
copy_n
(
buffer
.
begin
(),
n
,
it
);
}
};
// Formats a floating-point number (double or long double).
// Formats a floating-point number (double or long double).
template
<
typename
T
>
template
<
typename
T
>
void
write_double
(
T
value
,
const
format_specs
&
spec
);
void
write_double
(
T
value
,
const
format_specs
&
spec
);
template
<
typename
Char
>
struct
str_writer
{
const
Char
*
s
;
std
::
size_t
size
;
template
<
typename
It
>
void
operator
()(
It
&&
it
)
const
{
it
=
std
::
copy_n
(
s
,
size
,
it
);
}
};
// Writes a formatted string.
// Writes a formatted string.
template
<
typename
Char
>
template
<
typename
Char
>
void
write_str
(
const
Char
*
s
,
std
::
size_t
size
,
const
align_spec
&
spec
)
{
void
write_str
(
const
Char
*
s
,
std
::
size_t
size
,
const
align_spec
&
spec
)
{
write_padded
(
size
,
spec
,
[
s
,
size
](
auto
&&
it
)
{
write_padded
(
size
,
spec
,
str_writer
<
Char
>
{
s
,
size
});
it
=
std
::
copy_n
(
s
,
size
,
it
);
});
}
}
template
<
typename
Char
>
template
<
typename
Char
>
...
@@ -2562,12 +2611,7 @@ void basic_writer<Range>::write_double(T value, const format_specs &spec) {
...
@@ -2562,12 +2611,7 @@ void basic_writer<Range>::write_double(T value, const format_specs &spec) {
}
}
auto
write_inf_or_nan
=
[
this
,
&
spec
,
sign
](
const
char
*
str
)
{
auto
write_inf_or_nan
=
[
this
,
&
spec
,
sign
](
const
char
*
str
)
{
enum
{
SIZE
=
3
};
// This is an enum to workaround a bug in MSVC.
write_padded
(
INF_SIZE
+
(
sign
?
1
:
0
),
spec
,
inf_or_nan_writer
{
sign
,
str
});
write_padded
(
SIZE
+
(
sign
?
1
:
0
),
spec
,
[
sign
,
str
](
auto
&&
it
)
{
if
(
sign
)
*
it
++
=
sign
;
it
=
std
::
copy_n
(
str
,
static_cast
<
std
::
size_t
>
(
SIZE
),
it
);
});
};
};
// Format NaN and ininity ourselves because sprintf's output is not consistent
// Format NaN and ininity ourselves because sprintf's output is not consistent
...
@@ -2646,13 +2690,7 @@ void basic_writer<Range>::write_double(T value, const format_specs &spec) {
...
@@ -2646,13 +2690,7 @@ void basic_writer<Range>::write_double(T value, const format_specs &spec) {
if
(
sign
)
if
(
sign
)
++
n
;
++
n
;
}
}
write_padded
(
n
,
as
,
[
n
,
sign
,
&
buffer
](
auto
&&
it
)
mutable
{
write_padded
(
n
,
as
,
double_writer
{
n
,
sign
,
buffer
});
if
(
sign
)
{
*
it
++
=
sign
;
--
n
;
}
it
=
std
::
copy_n
(
buffer
.
begin
(),
n
,
it
);
});
}
}
// A range where begin() returns back_insert_iterator.
// A range where begin() returns back_insert_iterator.
...
...
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