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
a5bd3ddb
Commit
a5bd3ddb
authored
Aug 03, 2019
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make format_to a non-member
parent
3df0ea34
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
24 additions
and
24 deletions
+24
-24
include/fmt/compile.h
include/fmt/compile.h
+11
-8
include/fmt/format.h
include/fmt/format.h
+3
-4
include/fmt/safe-duration-cast.h
include/fmt/safe-duration-cast.h
+4
-6
test/compile-test.cc
test/compile-test.cc
+6
-6
No files found.
include/fmt/compile.h
View file @
a5bd3ddb
...
...
@@ -185,14 +185,6 @@ class prepared_format {
prepared_format
()
=
delete
;
template
<
typename
OutputIt
>
inline
OutputIt
format_to
(
OutputIt
out
,
const
Args
&
...
args
)
const
{
typedef
format_context_t
<
OutputIt
,
char_type
>
context
;
typedef
output_range
<
OutputIt
,
char_type
>
range
;
format_arg_store
<
context
,
Args
...
>
as
(
args
...);
return
this
->
vformat_to
(
range
(
out
),
basic_format_args
<
context
>
(
as
));
}
typedef
buffer_context
<
char_type
>
context
;
template
<
typename
Range
,
typename
Context
>
...
...
@@ -682,6 +674,17 @@ std::basic_string<Char> format(const CompiledFormat& cf, const Args&... args) {
return
to_string
(
buffer
);
}
template
<
typename
OutputIt
,
typename
CompiledFormat
,
typename
...
Args
>
OutputIt
format_to
(
OutputIt
out
,
const
CompiledFormat
&
cf
,
const
Args
&
...
args
)
{
using
char_type
=
typename
CompiledFormat
::
char_type
;
using
range
=
internal
::
output_range
<
OutputIt
,
char_type
>
;
using
context
=
format_context_t
<
OutputIt
,
char_type
>
;
format_arg_store
<
context
,
Args
...
>
as
(
args
...);
return
cf
.
template
vformat_to
<
range
,
context
>(
range
(
out
),
{
make_format_args
<
context
>
(
args
...)});
}
template
<
typename
OutputIt
,
typename
CompiledFormat
,
typename
...
Args
,
FMT_ENABLE_IF
(
internal
::
is_output_iterator
<
OutputIt
>
::
value
)
>
format_to_n_result
<
OutputIt
>
format_to_n
(
OutputIt
out
,
unsigned
n
,
...
...
include/fmt/format.h
View file @
a5bd3ddb
...
...
@@ -3368,11 +3368,10 @@ inline OutputIt vformat_to(OutputIt out, const S& format_str,
fmt::format_to(std::back_inserter(out), "{}", 42);
\endrst
*/
template
<
typename
OutputIt
,
typename
S
,
typename
...
Args
>
template
<
typename
OutputIt
,
typename
S
,
typename
...
Args
,
FMT_ENABLE_IF
(
internal
::
is_output_iterator
<
OutputIt
>
::
value
&&
internal
::
is_string
<
S
>::
value
)
>
inline
OutputIt
format_to
(
OutputIt
out
,
const
S
&
format_str
,
Args
&&
...
args
)
{
static_assert
(
internal
::
is_output_iterator
<
OutputIt
>::
value
&&
internal
::
is_string
<
S
>::
value
,
""
);
internal
::
check_format_string
<
Args
...
>
(
format_str
);
using
context
=
format_context_t
<
OutputIt
,
char_t
<
S
>>
;
return
vformat_to
(
out
,
to_string_view
(
format_str
),
...
...
include/fmt/safe-duration-cast.h
View file @
a5bd3ddb
...
...
@@ -257,16 +257,14 @@ To safe_duration_cast(std::chrono::duration<FromRep, FromPeriod> from,
// multiply with Factor::num without overflow or underflow
if
(
Factor
::
num
!=
1
)
{
constexpr
auto
max1
=
std
::
numeric_limits
<
IntermediateRep
>::
max
()
/
static_cast
<
IntermediateRep
>
(
Factor
::
num
);
constexpr
auto
max1
=
std
::
numeric_limits
<
IntermediateRep
>::
max
()
/
static_cast
<
IntermediateRep
>
(
Factor
::
num
);
if
(
count
>
max1
)
{
ec
=
1
;
return
{};
}
constexpr
auto
min1
=
std
::
numeric_limits
<
IntermediateRep
>::
lowest
()
/
static_cast
<
IntermediateRep
>
(
Factor
::
num
);
constexpr
auto
min1
=
std
::
numeric_limits
<
IntermediateRep
>::
lowest
()
/
static_cast
<
IntermediateRep
>
(
Factor
::
num
);
if
(
count
<
min1
)
{
ec
=
1
;
return
{};
...
...
test/compile-test.cc
View file @
a5bd3ddb
...
...
@@ -643,32 +643,32 @@ TEST(PrepareTest, PassUserTypeFormat) {
TEST
(
PrepareTest
,
FormatToArrayOfChars
)
{
char
buffer
[
32
]
=
{
0
};
const
auto
prepared
=
fmt
::
compile
<
int
>
(
"4{}"
);
prepared
.
format_to
(
buffer
,
2
);
fmt
::
format_to
(
buffer
,
prepared
,
2
);
EXPECT_EQ
(
std
::
string
(
"42"
),
buffer
);
wchar_t
wbuffer
[
32
]
=
{
0
};
const
auto
wprepared
=
fmt
::
compile
<
int
>
(
L"4{}"
);
wprepared
.
format_to
(
wbuffer
,
2
);
fmt
::
format_to
(
wbuffer
,
wprepared
,
2
);
EXPECT_EQ
(
std
::
wstring
(
L"42"
),
wbuffer
);
}
TEST
(
PrepareTest
,
FormatToIterator
)
{
std
::
string
s
(
2
,
' '
);
const
auto
prepared
=
fmt
::
compile
<
int
>
(
"4{}"
);
prepared
.
format_to
(
s
.
begin
()
,
2
);
fmt
::
format_to
(
s
.
begin
(),
prepared
,
2
);
EXPECT_EQ
(
"42"
,
s
);
std
::
wstring
ws
(
2
,
L' '
);
const
auto
wprepared
=
fmt
::
compile
<
int
>
(
L"4{}"
);
wprepared
.
format_to
(
ws
.
begin
()
,
2
);
fmt
::
format_to
(
ws
.
begin
(),
wprepared
,
2
);
EXPECT_EQ
(
L"42"
,
ws
);
}
TEST
(
PrepareTest
,
FormatToBackInserter
)
{
std
::
string
s
;
const
auto
prepared
=
fmt
::
compile
<
int
>
(
"4{}"
);
prepared
.
format_to
(
std
::
back_inserter
(
s
)
,
2
);
fmt
::
format_to
(
std
::
back_inserter
(
s
),
prepared
,
2
);
EXPECT_EQ
(
"42"
,
s
);
std
::
wstring
ws
;
const
auto
wprepared
=
fmt
::
compile
<
int
>
(
L"4{}"
);
wprepared
.
format_to
(
std
::
back_inserter
(
ws
)
,
2
);
fmt
::
format_to
(
std
::
back_inserter
(
ws
),
wprepared
,
2
);
EXPECT_EQ
(
L"42"
,
ws
);
}
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