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
466128de
Commit
466128de
authored
Sep 01, 2019
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove unused code and refactor
parent
22e98a5b
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
109 additions
and
155 deletions
+109
-155
include/fmt/chrono.h
include/fmt/chrono.h
+3
-3
include/fmt/compile.h
include/fmt/compile.h
+95
-106
include/fmt/format.h
include/fmt/format.h
+6
-9
test/compile-test.cc
test/compile-test.cc
+3
-35
test/format
test/format
+2
-2
No files found.
include/fmt/chrono.h
View file @
466128de
...
@@ -805,10 +805,10 @@ struct formatter<std::chrono::duration<Rep, Period>, Char> {
...
@@ -805,10 +805,10 @@ struct formatter<std::chrono::duration<Rep, Period>, Char> {
auto
out
=
std
::
back_inserter
(
buf
);
auto
out
=
std
::
back_inserter
(
buf
);
using
range
=
internal
::
output_range
<
decltype
(
ctx
.
out
()),
Char
>
;
using
range
=
internal
::
output_range
<
decltype
(
ctx
.
out
()),
Char
>
;
internal
::
basic_writer
<
range
>
w
(
range
(
ctx
.
out
()));
internal
::
basic_writer
<
range
>
w
(
range
(
ctx
.
out
()));
internal
::
handle_dynamic_spec
<
internal
::
width_checker
>
(
internal
::
handle_dynamic_spec
<
internal
::
width_checker
>
(
specs
.
width
,
specs
.
width
,
width_ref
,
ctx
,
format_str
.
begin
()
);
width_ref
,
ctx
);
internal
::
handle_dynamic_spec
<
internal
::
precision_checker
>
(
internal
::
handle_dynamic_spec
<
internal
::
precision_checker
>
(
precision
,
precision_ref
,
ctx
,
format_str
.
begin
()
);
precision
,
precision_ref
,
ctx
);
if
(
begin
==
end
||
*
begin
==
'}'
)
{
if
(
begin
==
end
||
*
begin
==
'}'
)
{
out
=
internal
::
format_chrono_duration_value
(
out
,
d
.
count
(),
precision
);
out
=
internal
::
format_chrono_duration_value
(
out
,
d
.
count
(),
precision
);
internal
::
format_chrono_duration_unit
<
Period
>
(
out
);
internal
::
format_chrono_duration_unit
<
Period
>
(
out
);
...
...
include/fmt/compile.h
View file @
466128de
...
@@ -34,7 +34,8 @@ template <typename Char> struct format_part {
...
@@ -34,7 +34,8 @@ template <typename Char> struct format_part {
FMT_CONSTEXPR
value
(
basic_string_view
<
Char
>
s
)
:
str
(
s
)
{}
FMT_CONSTEXPR
value
(
basic_string_view
<
Char
>
s
)
:
str
(
s
)
{}
FMT_CONSTEXPR
value
(
replacement
r
)
:
repl
(
r
)
{}
FMT_CONSTEXPR
value
(
replacement
r
)
:
repl
(
r
)
{}
}
val
;
}
val
;
std
::
size_t
arg_id_end
=
0
;
// Position past the end of the argument id.
// Position past the end of the argument id.
const
Char
*
arg_id_end
=
nullptr
;
FMT_CONSTEXPR
format_part
(
kind
k
=
kind
::
arg_index
,
value
v
=
{})
FMT_CONSTEXPR
format_part
(
kind
k
=
kind
::
arg_index
,
value
v
=
{})
:
part_kind
(
k
),
val
(
v
)
{}
:
part_kind
(
k
),
val
(
v
)
{}
...
@@ -97,6 +98,11 @@ class format_string_compiler : public error_handler {
...
@@ -97,6 +98,11 @@ class format_string_compiler : public error_handler {
private:
private:
using
part
=
format_part
<
Char
>
;
using
part
=
format_part
<
Char
>
;
PartHandler
handler_
;
part
part_
;
basic_string_view
<
Char
>
format_str_
;
basic_parse_context
<
Char
>
parse_context_
;
public:
public:
FMT_CONSTEXPR
format_string_compiler
(
basic_string_view
<
Char
>
format_str
,
FMT_CONSTEXPR
format_string_compiler
(
basic_string_view
<
Char
>
format_str
,
PartHandler
handler
)
PartHandler
handler
)
...
@@ -123,34 +129,25 @@ class format_string_compiler : public error_handler {
...
@@ -123,34 +129,25 @@ class format_string_compiler : public error_handler {
}
}
FMT_CONSTEXPR
void
on_replacement_field
(
const
Char
*
ptr
)
{
FMT_CONSTEXPR
void
on_replacement_field
(
const
Char
*
ptr
)
{
part_
.
arg_id_end
=
ptr
-
format_str_
.
begin
()
;
part_
.
arg_id_end
=
ptr
;
handler_
(
part_
);
handler_
(
part_
);
}
}
FMT_CONSTEXPR
const
Char
*
on_format_specs
(
const
Char
*
begin
,
FMT_CONSTEXPR
const
Char
*
on_format_specs
(
const
Char
*
begin
,
const
Char
*
end
)
{
const
Char
*
end
)
{
const
auto
specs_offset
=
to_unsigned
(
begin
-
format_str_
.
begin
());
auto
repl
=
typename
part
::
replacement
();
auto
repl
=
typename
part
::
replacement
();
dynamic_specs_handler
<
basic_parse_context
<
Char
>>
handler
(
repl
.
specs
,
dynamic_specs_handler
<
basic_parse_context
<
Char
>>
handler
(
repl
.
specs
,
parse_context_
);
parse_context_
);
begin
=
parse_format_specs
(
begin
,
end
,
handler
);
auto
it
=
parse_format_specs
(
begin
,
end
,
handler
);
if
(
*
begin
!=
'}'
)
on_error
(
"missing '}' in format string"
);
if
(
*
it
!=
'}'
)
on_error
(
"missing '}' in format string"
);
repl
.
arg_id
=
part_
.
part_kind
==
part
::
kind
::
arg_index
repl
.
arg_id
=
part_
.
part_kind
==
part
::
kind
::
arg_index
?
arg_ref
<
Char
>
(
part_
.
val
.
arg_index
)
?
arg_ref
<
Char
>
(
part_
.
val
.
arg_index
)
:
arg_ref
<
Char
>
(
part_
.
val
.
str
);
:
arg_ref
<
Char
>
(
part_
.
val
.
str
);
auto
part
=
part
::
make_replacement
(
repl
);
auto
part
=
part
::
make_replacement
(
repl
);
part
.
arg_id_end
=
specs_offset
;
part
.
arg_id_end
=
begin
;
handler_
(
part
);
handler_
(
part
);
return
begin
;
return
it
;
}
}
private:
PartHandler
handler_
;
part
part_
;
basic_string_view
<
Char
>
format_str_
;
basic_parse_context
<
Char
>
parse_context_
;
};
};
// Compiles a format string and invokes handler(part) for each parsed part.
// Compiles a format string and invokes handler(part) for each parsed part.
...
@@ -162,47 +159,47 @@ FMT_CONSTEXPR void compile_format_string(basic_string_view<Char> format_str,
...
@@ -162,47 +159,47 @@ FMT_CONSTEXPR void compile_format_string(basic_string_view<Char> format_str,
format_string_compiler
<
Char
,
PartHandler
>
(
format_str
,
handler
));
format_string_compiler
<
Char
,
PartHandler
>
(
format_str
,
handler
));
}
}
template
<
typename
Format
,
typename
PreparedPartsProvider
,
typename
...
Args
>
template
<
typename
Range
,
typename
Context
,
typename
Id
>
class
compiled_format
{
void
format_arg
(
basic_parse_context
<
typename
Range
::
value_type
>&
parse_ctx
,
public:
Context
&
ctx
,
Id
arg_id
)
{
using
char_type
=
char_t
<
Format
>
;
ctx
.
advance_to
(
using
format_part_t
=
format_part
<
char_type
>
;
visit_format_arg
(
arg_formatter
<
Range
>
(
ctx
,
&
parse_ctx
),
ctx
.
arg
(
arg_id
)));
}
constexpr
compiled_format
(
Format
f
)
:
format_
(
std
::
move
(
f
)),
parts_provider_
(
to_string_view
(
format_
))
{}
compiled_format
()
=
delete
;
template
<
typename
Range
,
typename
Context
>
// vformat_to is defined in a subnamespace to prevent ADL.
auto
vformat_to
(
Range
out
,
basic_format_args
<
Context
>
args
)
const
->
namespace
cf
{
typename
Context
::
iterator
{
template
<
typename
Context
,
typename
Range
,
typename
CompiledFormat
>
const
auto
format_view
=
internal
::
to_string_view
(
format_
);
auto
vformat_to
(
Range
out
,
CompiledFormat
&
cf
,
basic_format_args
<
Context
>
args
)
basic_parse_context
<
char_type
>
parse_ctx
(
format_view
);
->
typename
Context
::
iterator
{
using
char_type
=
typename
Context
::
char_type
;
basic_parse_context
<
char_type
>
parse_ctx
(
to_string_view
(
cf
.
format_
));
Context
ctx
(
out
.
begin
(),
args
);
Context
ctx
(
out
.
begin
(),
args
);
const
auto
&
parts
=
parts_provider_
.
parts
();
const
auto
&
parts
=
cf
.
parts_provider_
.
parts
();
for
(
auto
part_it
=
parts
.
begin
();
part_it
!=
parts
.
end
();
++
part_it
)
{
for
(
auto
part_it
=
parts
.
begin
();
part_it
!=
parts
.
end
();
++
part_it
)
{
const
auto
&
part
=
*
part_it
;
const
auto
&
part
=
*
part_it
;
const
auto
&
value
=
part
.
val
;
const
auto
&
value
=
part
.
val
;
using
format_part_t
=
format_part
<
char_type
>
;
switch
(
part
.
part_kind
)
{
switch
(
part
.
part_kind
)
{
case
format_part_t
:
:
kind
::
text
:
{
case
format_part_t
:
:
kind
::
text
:
{
const
auto
text
=
value
.
str
;
const
auto
text
=
value
.
str
;
auto
output
=
ctx
.
out
();
auto
output
=
ctx
.
out
();
auto
&&
it
=
internal
::
reserve
(
output
,
text
.
size
());
auto
&&
it
=
reserve
(
output
,
text
.
size
());
it
=
std
::
copy_n
(
text
.
begin
(),
text
.
size
(),
it
);
it
=
std
::
copy_n
(
text
.
begin
(),
text
.
size
(),
it
);
ctx
.
advance_to
(
output
);
ctx
.
advance_to
(
output
);
}
break
;
}
break
;
case
format_part_t
:
:
kind
::
arg_index
:
{
case
format_part_t
:
:
kind
::
arg_index
:
advance_parse_context_to_specification
(
parse_ctx
,
part
);
advance_to
(
parse_ctx
,
part
.
arg_id_end
);
format_arg
<
Range
>
(
parse_ctx
,
ctx
,
value
.
arg_index
);
internal
::
format_arg
<
Range
>
(
parse_ctx
,
ctx
,
value
.
arg_index
);
}
break
;
break
;
case
format_part_t
:
:
kind
::
arg_name
:
advance_to
(
parse_ctx
,
part
.
arg_id_end
);
internal
::
format_arg
<
Range
>
(
parse_ctx
,
ctx
,
value
.
str
);
break
;
case
format_part_t
:
:
kind
::
arg_name
:
{
advance_parse_context_to_specification
(
parse_ctx
,
part
);
format_arg
<
Range
>
(
parse_ctx
,
ctx
,
value
.
str
);
}
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
;
const
auto
arg
=
value
.
repl
.
arg_id
.
kind
==
arg_id_kind
::
index
const
auto
arg
=
value
.
repl
.
arg_id
.
kind
==
arg_id_kind
::
index
...
@@ -211,52 +208,44 @@ class compiled_format {
...
@@ -211,52 +208,44 @@ class compiled_format {
auto
specs
=
value
.
repl
.
specs
;
auto
specs
=
value
.
repl
.
specs
;
handle_dynamic_spec
<
internal
::
width_checker
>
(
handle_dynamic_spec
<
width_checker
>
(
specs
.
width
,
specs
.
width_ref
,
ctx
);
specs
.
width
,
specs
.
width_ref
,
ctx
,
format_view
.
begin
());
handle_dynamic_spec
<
precision_checker
>
(
specs
.
precision
,
handle_dynamic_spec
<
internal
::
precision_checker
>
(
specs
.
precision_ref
,
ctx
);
specs
.
precision
,
specs
.
precision_ref
,
ctx
,
format_view
.
begin
());
error_handler
h
;
numeric_specs_checker
<
error_handler
>
checker
(
h
,
arg
.
type
());
if
(
specs
.
align
==
align
::
numeric
)
checker
.
require_numeric_argument
();
if
(
specs
.
sign
!=
sign
::
none
)
checker
.
check_sign
();
if
(
specs
.
alt
)
checker
.
require_numeric_argument
();
if
(
specs
.
precision
>=
0
)
checker
.
check_precision
();
check_prepared_specs
(
specs
,
arg
.
type
());
advance_to
(
parse_ctx
,
part
.
arg_id_end
);
advance_parse_context_to_specification
(
parse_ctx
,
part
);
ctx
.
advance_to
(
ctx
.
advance_to
(
visit_format_arg
(
arg_formatter
<
Range
>
(
ctx
,
nullptr
,
&
specs
),
arg
));
visit_format_arg
(
arg_formatter
<
Range
>
(
ctx
,
nullptr
,
&
specs
),
arg
));
}
break
;
}
break
;
}
}
}
}
return
ctx
.
out
();
return
ctx
.
out
();
}
}
}
// namespace cf
template
<
typename
S
,
typename
PreparedPartsProvider
,
typename
...
Args
>
class
compiled_format
{
private:
private:
void
advance_parse_context_to_specification
(
S
format_
;
basic_parse_context
<
char_type
>&
parse_ctx
,
PreparedPartsProvider
parts_provider_
;
const
format_part_t
&
part
)
const
{
const
auto
view
=
to_string_view
(
format_
);
const
auto
specification_begin
=
view
.
data
()
+
part
.
arg_id_end
;
advance_to
(
parse_ctx
,
specification_begin
);
}
template
<
typename
Range
,
typename
Context
,
typename
Id
>
template
<
typename
Context
,
typename
Range
,
typename
CompiledFormat
>
void
format_arg
(
basic_parse_context
<
char_type
>&
parse_ctx
,
Context
&
ctx
,
friend
auto
cf
::
vformat_to
(
Range
out
,
CompiledFormat
&
cf
,
Id
arg_id
)
const
{
basic_format_args
<
Context
>
args
)
->
ctx
.
advance_to
(
visit_format_arg
(
arg_formatter
<
Range
>
(
ctx
,
&
parse_ctx
),
typename
Context
::
iterator
;
ctx
.
arg
(
arg_id
)));
}
template
<
typename
Char
>
public:
void
check_prepared_specs
(
const
basic_format_specs
<
Char
>&
specs
,
using
char_type
=
char_t
<
S
>
;
internal
::
type
arg_type
)
const
{
internal
::
error_handler
h
;
numeric_specs_checker
<
internal
::
error_handler
>
checker
(
h
,
arg_type
);
if
(
specs
.
align
==
align
::
numeric
)
checker
.
require_numeric_argument
();
if
(
specs
.
sign
!=
sign
::
none
)
checker
.
check_sign
();
if
(
specs
.
alt
)
checker
.
require_numeric_argument
();
if
(
specs
.
precision
>=
0
)
checker
.
check_precision
();
}
private:
compiled_format
()
=
delete
;
Format
format_
;
constexpr
compiled_format
(
S
f
)
PreparedPartsProvider
parts_provider_
;
:
format_
(
std
::
move
(
f
)),
parts_provider_
(
to_string_view
(
format_
))
{}
};
};
template
<
typename
Format
>
class
compiletime_prepared_parts_type_provider
{
template
<
typename
Format
>
class
compiletime_prepared_parts_type_provider
{
...
@@ -367,7 +356,7 @@ std::basic_string<Char> format(const CompiledFormat& cf, const Args&... args) {
...
@@ -367,7 +356,7 @@ std::basic_string<Char> format(const CompiledFormat& cf, const Args&... args) {
basic_memory_buffer
<
Char
>
buffer
;
basic_memory_buffer
<
Char
>
buffer
;
using
range
=
buffer_range
<
Char
>
;
using
range
=
buffer_range
<
Char
>
;
using
context
=
buffer_context
<
Char
>
;
using
context
=
buffer_context
<
Char
>
;
cf
.
template
vformat_to
<
range
,
context
>(
range
(
buffer
)
,
internal
::
cf
::
vformat_to
<
context
>
(
range
(
buffer
),
cf
,
{
make_format_args
<
context
>
(
args
...)});
{
make_format_args
<
context
>
(
args
...)});
return
to_string
(
buffer
);
return
to_string
(
buffer
);
}
}
...
@@ -378,8 +367,8 @@ OutputIt format_to(OutputIt out, const CompiledFormat& cf,
...
@@ -378,8 +367,8 @@ OutputIt format_to(OutputIt out, const CompiledFormat& cf,
using
char_type
=
typename
CompiledFormat
::
char_type
;
using
char_type
=
typename
CompiledFormat
::
char_type
;
using
range
=
internal
::
output_range
<
OutputIt
,
char_type
>
;
using
range
=
internal
::
output_range
<
OutputIt
,
char_type
>
;
using
context
=
format_context_t
<
OutputIt
,
char_type
>
;
using
context
=
format_context_t
<
OutputIt
,
char_type
>
;
return
cf
.
template
vformat_to
<
range
,
context
>(
return
internal
::
cf
::
vformat_to
<
context
>
(
range
(
out
),
{
make_format_args
<
context
>
(
args
...)});
range
(
out
),
cf
,
{
make_format_args
<
context
>
(
args
...)});
}
}
template
<
typename
OutputIt
,
typename
CompiledFormat
,
typename
...
Args
,
template
<
typename
OutputIt
,
typename
CompiledFormat
,
typename
...
Args
,
...
...
include/fmt/format.h
View file @
466128de
...
@@ -2556,8 +2556,7 @@ void check_format_string(S format_str) {
...
@@ -2556,8 +2556,7 @@ void check_format_string(S format_str) {
template
<
template
<
typename
>
class
Handler
,
typename
Spec
,
typename
Context
>
template
<
template
<
typename
>
class
Handler
,
typename
Spec
,
typename
Context
>
void
handle_dynamic_spec
(
Spec
&
value
,
arg_ref
<
typename
Context
::
char_type
>
ref
,
void
handle_dynamic_spec
(
Spec
&
value
,
arg_ref
<
typename
Context
::
char_type
>
ref
,
Context
&
ctx
,
Context
&
ctx
)
{
const
typename
Context
::
char_type
*
format_str
)
{
switch
(
ref
.
kind
)
{
switch
(
ref
.
kind
)
{
case
arg_id_kind
:
:
none
:
case
arg_id_kind
:
:
none
:
break
;
break
;
...
@@ -2935,13 +2934,12 @@ template <typename T, typename Char>
...
@@ -2935,13 +2934,12 @@ template <typename T, typename Char>
struct
formatter
<
T
,
Char
,
struct
formatter
<
T
,
Char
,
enable_if_t
<
internal
::
type_constant
<
T
,
Char
>::
value
!=
enable_if_t
<
internal
::
type_constant
<
T
,
Char
>::
value
!=
internal
::
custom_type
>>
{
internal
::
custom_type
>>
{
FMT_CONSTEXPR
formatter
()
:
format_str_
(
nullptr
)
{}
FMT_CONSTEXPR
formatter
()
{}
// Parses format specifiers stopping either at the end of the range or at the
// Parses format specifiers stopping either at the end of the range or at the
// terminating '}'.
// terminating '}'.
template
<
typename
ParseContext
>
template
<
typename
ParseContext
>
FMT_CONSTEXPR
auto
parse
(
ParseContext
&
ctx
)
->
decltype
(
ctx
.
begin
())
{
FMT_CONSTEXPR
auto
parse
(
ParseContext
&
ctx
)
->
decltype
(
ctx
.
begin
())
{
format_str_
=
ctx
.
begin
();
using
handler_type
=
internal
::
dynamic_specs_handler
<
ParseContext
>
;
using
handler_type
=
internal
::
dynamic_specs_handler
<
ParseContext
>
;
auto
type
=
internal
::
type_constant
<
T
,
Char
>::
value
;
auto
type
=
internal
::
type_constant
<
T
,
Char
>::
value
;
internal
::
specs_checker
<
handler_type
>
handler
(
handler_type
(
specs_
,
ctx
),
internal
::
specs_checker
<
handler_type
>
handler
(
handler_type
(
specs_
,
ctx
),
...
@@ -2991,9 +2989,9 @@ struct formatter<T, Char,
...
@@ -2991,9 +2989,9 @@ struct formatter<T, Char,
template
<
typename
FormatContext
>
template
<
typename
FormatContext
>
auto
format
(
const
T
&
val
,
FormatContext
&
ctx
)
->
decltype
(
ctx
.
out
())
{
auto
format
(
const
T
&
val
,
FormatContext
&
ctx
)
->
decltype
(
ctx
.
out
())
{
internal
::
handle_dynamic_spec
<
internal
::
width_checker
>
(
internal
::
handle_dynamic_spec
<
internal
::
width_checker
>
(
specs_
.
width
,
specs_
.
width_ref
,
ctx
,
format_str_
);
specs_
.
width
,
specs_
.
width_ref
,
ctx
);
internal
::
handle_dynamic_spec
<
internal
::
precision_checker
>
(
internal
::
handle_dynamic_spec
<
internal
::
precision_checker
>
(
specs_
.
precision
,
specs_
.
precision_ref
,
ctx
,
format_str_
);
specs_
.
precision
,
specs_
.
precision_ref
,
ctx
);
using
range_type
=
using
range_type
=
internal
::
output_range
<
typename
FormatContext
::
iterator
,
internal
::
output_range
<
typename
FormatContext
::
iterator
,
typename
FormatContext
::
char_type
>
;
typename
FormatContext
::
char_type
>
;
...
@@ -3003,7 +3001,6 @@ struct formatter<T, Char,
...
@@ -3003,7 +3001,6 @@ struct formatter<T, Char,
private:
private:
internal
::
dynamic_format_specs
<
Char
>
specs_
;
internal
::
dynamic_format_specs
<
Char
>
specs_
;
const
Char
*
format_str_
;
};
};
#define FMT_FORMAT_AS(Type, Base) \
#define FMT_FORMAT_AS(Type, Base) \
...
@@ -3104,9 +3101,9 @@ template <typename Char = char> class dynamic_formatter {
...
@@ -3104,9 +3101,9 @@ template <typename Char = char> class dynamic_formatter {
private:
private:
template
<
typename
Context
>
void
handle_specs
(
Context
&
ctx
)
{
template
<
typename
Context
>
void
handle_specs
(
Context
&
ctx
)
{
internal
::
handle_dynamic_spec
<
internal
::
width_checker
>
(
internal
::
handle_dynamic_spec
<
internal
::
width_checker
>
(
specs_
.
width
,
specs_
.
width_ref
,
ctx
,
format_str_
);
specs_
.
width
,
specs_
.
width_ref
,
ctx
);
internal
::
handle_dynamic_spec
<
internal
::
precision_checker
>
(
internal
::
handle_dynamic_spec
<
internal
::
precision_checker
>
(
specs_
.
precision
,
specs_
.
precision_ref
,
ctx
,
format_str_
);
specs_
.
precision
,
specs_
.
precision_ref
,
ctx
);
}
}
internal
::
dynamic_format_specs
<
Char
>
specs_
;
internal
::
dynamic_format_specs
<
Char
>
specs_
;
...
...
test/compile-test.cc
View file @
466128de
...
@@ -67,40 +67,6 @@ TEST(CompileTest, CompileTimePreparedPartsTypeProvider) {
...
@@ -67,40 +67,6 @@ TEST(CompileTest, CompileTimePreparedPartsTypeProvider) {
}
}
#endif
#endif
class
custom_parts_container
{
public:
typedef
fmt
::
internal
::
format_part
<
char
>
format_part_type
;
private:
typedef
std
::
deque
<
format_part_type
>
parts
;
public:
void
add
(
format_part_type
part
)
{
parts_
.
push_back
(
std
::
move
(
part
));
}
void
substitute_last
(
format_part_type
part
)
{
parts_
.
back
()
=
std
::
move
(
part
);
}
format_part_type
last
()
{
return
parts_
.
back
();
}
auto
begin
()
->
decltype
(
std
::
declval
<
parts
>
().
begin
())
{
return
parts_
.
begin
();
}
auto
begin
()
const
->
decltype
(
std
::
declval
<
const
parts
>
().
begin
())
{
return
parts_
.
begin
();
}
auto
end
()
->
decltype
(
std
::
declval
<
parts
>
().
begin
())
{
return
parts_
.
end
();
}
auto
end
()
const
->
decltype
(
std
::
declval
<
const
parts
>
().
begin
())
{
return
parts_
.
end
();
}
private:
parts
parts_
;
};
TEST
(
CompileTest
,
PassStringLiteralFormat
)
{
TEST
(
CompileTest
,
PassStringLiteralFormat
)
{
const
auto
prepared
=
fmt
::
compile
<
int
>
(
"test {}"
);
const
auto
prepared
=
fmt
::
compile
<
int
>
(
"test {}"
);
EXPECT_EQ
(
"test 42"
,
fmt
::
format
(
prepared
,
42
));
EXPECT_EQ
(
"test 42"
,
fmt
::
format
(
prepared
,
42
));
...
@@ -155,12 +121,14 @@ TEST(CompileTest, FormattedSize) {
...
@@ -155,12 +121,14 @@ TEST(CompileTest, FormattedSize) {
struct
formattable
{};
struct
formattable
{};
FMT_BEGIN_NAMESPACE
template
<
>
template
<
>
struct
f
mt
::
f
ormatter
<
formattable
>
:
formatter
<
const
char
*>
{
struct
formatter
<
formattable
>
:
formatter
<
const
char
*>
{
auto
format
(
formattable
,
format_context
&
ctx
)
->
decltype
(
ctx
.
out
())
{
auto
format
(
formattable
,
format_context
&
ctx
)
->
decltype
(
ctx
.
out
())
{
return
formatter
<
const
char
*>::
format
(
"foo"
,
ctx
);
return
formatter
<
const
char
*>::
format
(
"foo"
,
ctx
);
}
}
};
};
FMT_END_NAMESPACE
TEST
(
CompileTest
,
FormatUserDefinedType
)
{
TEST
(
CompileTest
,
FormatUserDefinedType
)
{
auto
f
=
fmt
::
compile
<
formattable
>
(
"{}"
);
auto
f
=
fmt
::
compile
<
formattable
>
(
"{}"
);
...
...
test/format
View file @
466128de
...
@@ -690,9 +690,9 @@ struct formatter {
...
@@ -690,9 +690,9 @@ struct formatter {
template <typename FormatContext>
template <typename FormatContext>
auto format(const T& val, FormatContext& ctx) -> decltype(ctx.out()) {
auto format(const T& val, FormatContext& ctx) -> decltype(ctx.out()) {
fmt::internal::handle_dynamic_spec<fmt::internal::width_checker>(
fmt::internal::handle_dynamic_spec<fmt::internal::width_checker>(
specs_.width, specs_.width_ref, ctx
, nullptr
);
specs_.width, specs_.width_ref, ctx);
fmt::internal::handle_dynamic_spec<fmt::internal::precision_checker>(
fmt::internal::handle_dynamic_spec<fmt::internal::precision_checker>(
specs_.precision, specs_.precision_ref, ctx
, nullptr
);
specs_.precision, specs_.precision_ref, ctx);
using range_type = fmt::internal::output_range<typename FormatContext::iterator,
using range_type = fmt::internal::output_range<typename FormatContext::iterator,
typename FormatContext::char_type>;
typename FormatContext::char_type>;
return visit_format_arg(arg_formatter<range_type>(ctx, nullptr, &specs_),
return visit_format_arg(arg_formatter<range_type>(ctx, nullptr, &specs_),
...
...
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