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
ad972589
Commit
ad972589
authored
Jun 01, 2021
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of github.com:fmtlib/fmt
parents
ed2a6377
99768695
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
14 deletions
+30
-14
include/fmt/core.h
include/fmt/core.h
+1
-1
include/fmt/format.h
include/fmt/format.h
+5
-4
test/compile-test.cc
test/compile-test.cc
+24
-9
No files found.
include/fmt/core.h
View file @
ad972589
...
...
@@ -1140,7 +1140,7 @@ template <typename Context> class value {
FMT_INLINE
value
(
const
named_arg_info
<
char_type
>*
args
,
size_t
size
)
:
named_args
{
args
,
size
}
{}
template
<
typename
T
>
FMT_INLINE
value
(
const
T
&
val
)
{
template
<
typename
T
>
FMT_
CONSTEXPR
FMT_
INLINE
value
(
const
T
&
val
)
{
custom
.
value
=
&
val
;
// Get the formatter type through the context to allow different contexts
// have different extension points, e.g. `formatter<T>` for `format` and
...
...
include/fmt/format.h
View file @
ad972589
...
...
@@ -1935,10 +1935,11 @@ OutputIt write(OutputIt out, const T* value,
}
template
<
typename
Char
,
typename
OutputIt
,
typename
T
>
auto
write
(
OutputIt
out
,
const
T
&
value
)
->
typename
std
::
enable_if
<
mapped_type_constant
<
T
,
basic_format_context
<
OutputIt
,
Char
>>::
value
==
type
::
custom_type
,
OutputIt
>::
type
{
FMT_CONSTEXPR
auto
write
(
OutputIt
out
,
const
T
&
value
)
->
typename
std
::
enable_if
<
mapped_type_constant
<
T
,
basic_format_context
<
OutputIt
,
Char
>>::
value
==
type
::
custom_type
,
OutputIt
>::
type
{
using
context_type
=
basic_format_context
<
OutputIt
,
Char
>
;
using
formatter_type
=
conditional_t
<
has_formatter
<
T
,
context_type
>::
value
,
...
...
test/compile-test.cc
View file @
ad972589
...
...
@@ -53,24 +53,34 @@ TEST(iterator_test, truncating_back_inserter) {
EXPECT_EQ
(
buffer
,
"42"
);
}
TEST
(
compile_test
,
compile_fallback
)
{
// FMT_COMPILE should fallback on runtime formatting when `if constexpr` is
// not available.
EXPECT_EQ
(
"42"
,
fmt
::
format
(
FMT_COMPILE
(
"{}"
),
42
));
}
#ifdef __cpp_if_constexpr
struct
test_formattable
{};
FMT_BEGIN_NAMESPACE
template
<
>
struct
formatter
<
test_formattable
>
:
formatter
<
const
char
*>
{
char
word_spec
=
'f'
;
constexpr
auto
parse
(
format_parse_context
&
ctx
)
{
auto
it
=
ctx
.
begin
(),
end
=
ctx
.
end
();
if
(
it
==
end
||
*
it
==
'}'
)
return
it
;
if
(
it
!=
end
&&
(
*
it
==
'f'
||
*
it
==
'b'
))
word_spec
=
*
it
++
;
if
(
it
!=
end
&&
*
it
!=
'}'
)
throw
format_error
(
"invalid format"
);
return
it
;
}
template
<
typename
FormatContext
>
auto
format
(
test_formattable
,
FormatContext
&
ctx
)
->
decltype
(
ctx
.
out
())
{
return
formatter
<
const
char
*>::
format
(
"foo"
,
ctx
);
constexpr
auto
format
(
test_formattable
,
FormatContext
&
ctx
)
const
->
decltype
(
ctx
.
out
())
{
return
formatter
<
const
char
*>::
format
(
word_spec
==
'f'
?
"foo"
:
"bar"
,
ctx
);
}
};
FMT_END_NAMESPACE
TEST
(
compile_test
,
compile_fallback
)
{
// FMT_COMPILE should fallback on runtime formatting when `if constexpr` is
// not available.
EXPECT_EQ
(
"42"
,
fmt
::
format
(
FMT_COMPILE
(
"{}"
),
42
));
}
#ifdef __cpp_if_constexpr
TEST
(
compile_test
,
format_default
)
{
EXPECT_EQ
(
"42"
,
fmt
::
format
(
FMT_COMPILE
(
"{}"
),
42
));
EXPECT_EQ
(
"42"
,
fmt
::
format
(
FMT_COMPILE
(
"{}"
),
42u
));
...
...
@@ -336,6 +346,11 @@ TEST(compile_time_formatting_test, combination) {
EXPECT_EQ
(
" -42"
,
test_format
<
5
>
(
FMT_COMPILE
(
"{:{}}"
),
-
42
,
4
));
}
TEST
(
compile_time_formatting_test
,
custom_type
)
{
EXPECT_EQ
(
"foo"
,
test_format
<
4
>
(
FMT_COMPILE
(
"{}"
),
test_formattable
()));
EXPECT_EQ
(
"bar"
,
test_format
<
4
>
(
FMT_COMPILE
(
"{:b}"
),
test_formattable
()));
}
TEST
(
compile_time_formatting_test
,
multibyte_fill
)
{
EXPECT_EQ
(
"жж42"
,
test_format
<
8
>
(
FMT_COMPILE
(
"{:ж>4}"
),
42
));
}
...
...
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