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
22e98a5b
Commit
22e98a5b
authored
Sep 01, 2019
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make compile work with user-defined types
parent
f18a3f36
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
8 deletions
+18
-8
include/fmt/compile.h
include/fmt/compile.h
+4
-8
test/compile-test.cc
test/compile-test.cc
+14
-0
No files found.
include/fmt/compile.h
View file @
22e98a5b
...
@@ -173,8 +173,6 @@ class compiled_format {
...
@@ -173,8 +173,6 @@ class compiled_format {
compiled_format
()
=
delete
;
compiled_format
()
=
delete
;
using
context
=
buffer_context
<
char_type
>
;
template
<
typename
Range
,
typename
Context
>
template
<
typename
Range
,
typename
Context
>
auto
vformat_to
(
Range
out
,
basic_format_args
<
Context
>
args
)
const
->
auto
vformat_to
(
Range
out
,
basic_format_args
<
Context
>
args
)
const
->
typename
Context
::
iterator
{
typename
Context
::
iterator
{
...
@@ -203,8 +201,7 @@ class compiled_format {
...
@@ -203,8 +201,7 @@ class compiled_format {
case
format_part_t
:
:
kind
::
arg_name
:
{
case
format_part_t
:
:
kind
::
arg_name
:
{
advance_parse_context_to_specification
(
parse_ctx
,
part
);
advance_parse_context_to_specification
(
parse_ctx
,
part
);
const
auto
named_arg_id
=
value
.
str
;
format_arg
<
Range
>
(
parse_ctx
,
ctx
,
value
.
str
);
format_arg
<
Range
>
(
parse_ctx
,
ctx
,
named_arg_id
);
}
break
;
}
break
;
case
format_part_t
:
:
kind
::
replacement
:
{
case
format_part_t
:
:
kind
::
replacement
:
{
const
auto
&
arg_id_value
=
value
.
repl
.
arg_id
.
val
;
const
auto
&
arg_id_value
=
value
.
repl
.
arg_id
.
val
;
...
@@ -242,10 +239,8 @@ class compiled_format {
...
@@ -242,10 +239,8 @@ class compiled_format {
template
<
typename
Range
,
typename
Context
,
typename
Id
>
template
<
typename
Range
,
typename
Context
,
typename
Id
>
void
format_arg
(
basic_parse_context
<
char_type
>&
parse_ctx
,
Context
&
ctx
,
void
format_arg
(
basic_parse_context
<
char_type
>&
parse_ctx
,
Context
&
ctx
,
Id
arg_id
)
const
{
Id
arg_id
)
const
{
parse_ctx
.
check_arg_id
(
arg_id
);
ctx
.
advance_to
(
visit_format_arg
(
arg_formatter
<
Range
>
(
ctx
,
&
parse_ctx
),
const
auto
stopped_at
=
ctx
.
arg
(
arg_id
)));
visit_format_arg
(
arg_formatter
<
Range
>
(
ctx
),
ctx
.
arg
(
arg_id
));
ctx
.
advance_to
(
stopped_at
);
}
}
template
<
typename
Char
>
template
<
typename
Char
>
...
@@ -359,6 +354,7 @@ FMT_CONSTEXPR auto compile(S format_str)
...
@@ -359,6 +354,7 @@ FMT_CONSTEXPR auto compile(S format_str)
}
}
#endif
#endif
// Compiles the format string which must be a string literal.
template
<
typename
...
Args
,
typename
Char
,
size_t
N
>
template
<
typename
...
Args
,
typename
Char
,
size_t
N
>
auto
compile
(
const
Char
(
&
format_str
)[
N
])
->
internal
::
compiled_format
<
auto
compile
(
const
Char
(
&
format_str
)[
N
])
->
internal
::
compiled_format
<
std
::
basic_string
<
Char
>
,
internal
::
runtime_parts_provider
<
Char
>
,
Args
...
>
{
std
::
basic_string
<
Char
>
,
internal
::
runtime_parts_provider
<
Char
>
,
Args
...
>
{
...
...
test/compile-test.cc
View file @
22e98a5b
...
@@ -152,3 +152,17 @@ TEST(CompileTest, FormattedSize) {
...
@@ -152,3 +152,17 @@ TEST(CompileTest, FormattedSize) {
auto
f
=
fmt
::
compile
<
int
>
(
"{:10}"
);
auto
f
=
fmt
::
compile
<
int
>
(
"{:10}"
);
EXPECT_EQ
(
fmt
::
formatted_size
(
f
,
42
),
10
);
EXPECT_EQ
(
fmt
::
formatted_size
(
f
,
42
),
10
);
}
}
struct
formattable
{};
template
<
>
struct
fmt
::
formatter
<
formattable
>
:
formatter
<
const
char
*>
{
auto
format
(
formattable
,
format_context
&
ctx
)
->
decltype
(
ctx
.
out
())
{
return
formatter
<
const
char
*>::
format
(
"foo"
,
ctx
);
}
};
TEST
(
CompileTest
,
FormatUserDefinedType
)
{
auto
f
=
fmt
::
compile
<
formattable
>
(
"{}"
);
EXPECT_EQ
(
fmt
::
format
(
f
,
formattable
()),
"foo"
);
}
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