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
1ab80aa9
Commit
1ab80aa9
authored
Dec 05, 2019
by
Deniz Evrenci
Committed by
Victor Zverovich
Dec 06, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix handling of types with custom formatters that are convertible to std::string_view
parent
4f4d8766
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
1 deletion
+25
-1
include/fmt/core.h
include/fmt/core.h
+3
-1
test/format-test.cc
test/format-test.cc
+22
-0
No files found.
include/fmt/core.h
View file @
1ab80aa9
...
...
@@ -878,7 +878,9 @@ template <typename Context> struct arg_mapper {
FMT_ENABLE_IF
(
std
::
is_constructible
<
std_string_view
<
char_type
>,
T
>::
value
&&
!
std
::
is_constructible
<
basic_string_view
<
char_type
>
,
T
>::
value
&&
!
is_string
<
T
>::
value
)
>
!
is_string
<
T
>::
value
&&
!
has_formatter
<
T
,
Context
>::
value
&&
!
has_fallback_formatter
<
T
,
Context
>::
value
)
>
FMT_CONSTEXPR
basic_string_view
<
char_type
>
map
(
const
T
&
val
)
{
return
std_string_view
<
char_type
>
(
val
);
}
...
...
test/format-test.cc
View file @
1ab80aa9
...
...
@@ -1685,6 +1685,28 @@ TEST(FormatterTest, FormatStdStringView) {
EXPECT_EQ
(
"test"
,
format
(
"{}"
,
std
::
string_view
(
"test"
)));
EXPECT_EQ
(
"foo"
,
format
(
"{}"
,
string_viewable
()));
}
struct
explicitly_convertible_to_std_string_view
{
explicit
operator
std
::
string_view
()
const
{
return
"foo"
;
}
};
namespace
fmt
{
template
<
>
struct
formatter
<
explicitly_convertible_to_std_string_view
>
:
formatter
<
std
::
string_view
>
{
auto
format
(
const
explicitly_convertible_to_std_string_view
&
v
,
format_context
&
ctx
)
{
return
format_to
(
ctx
.
out
(),
"'{}'"
,
std
::
string_view
(
v
));
}
};
}
// namespace fmt
TEST
(
FormatterTest
,
FormatExplicitlyConvertibleToStdStringView
)
{
EXPECT_EQ
(
"'foo'"
,
fmt
::
format
(
"{}"
,
explicitly_convertible_to_std_string_view
()));
}
#endif
FMT_BEGIN_NAMESPACE
...
...
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