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
9f2e7eda
Commit
9f2e7eda
authored
Dec 09, 2019
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix handling of types convertible to std::string_view
parent
fd52de0c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
12 deletions
+32
-12
include/fmt/core.h
include/fmt/core.h
+9
-9
test/format-test.cc
test/format-test.cc
+1
-3
test/ostream-test.cc
test/ostream-test.cc
+22
-0
No files found.
include/fmt/core.h
View file @
9f2e7eda
...
@@ -878,9 +878,7 @@ template <typename Context> struct arg_mapper {
...
@@ -878,9 +878,7 @@ template <typename Context> struct arg_mapper {
FMT_ENABLE_IF
(
FMT_ENABLE_IF
(
std
::
is_constructible
<
std_string_view
<
char_type
>,
T
>::
value
&&
std
::
is_constructible
<
std_string_view
<
char_type
>,
T
>::
value
&&
!
std
::
is_constructible
<
basic_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_formatter
<
T
,
Context
>::
value
&&
!
has_fallback_formatter
<
T
,
Context
>::
value
)
>
FMT_CONSTEXPR
basic_string_view
<
char_type
>
map
(
const
T
&
val
)
{
FMT_CONSTEXPR
basic_string_view
<
char_type
>
map
(
const
T
&
val
)
{
return
std_string_view
<
char_type
>
(
val
);
return
std_string_view
<
char_type
>
(
val
);
}
}
...
@@ -913,12 +911,14 @@ template <typename Context> struct arg_mapper {
...
@@ -913,12 +911,14 @@ template <typename Context> struct arg_mapper {
map
(
static_cast
<
typename
std
::
underlying_type
<
T
>::
type
>
(
val
)))
{
map
(
static_cast
<
typename
std
::
underlying_type
<
T
>::
type
>
(
val
)))
{
return
map
(
static_cast
<
typename
std
::
underlying_type
<
T
>::
type
>
(
val
));
return
map
(
static_cast
<
typename
std
::
underlying_type
<
T
>::
type
>
(
val
));
}
}
template
<
typename
T
,
template
<
FMT_ENABLE_IF
(
!
is_string
<
T
>
::
value
&&
!
is_char
<
T
>::
value
&&
typename
T
,
!
std
::
is_constructible
<
basic_string_view
<
char_type
>
,
FMT_ENABLE_IF
(
T
>::
value
&&
!
is_string
<
T
>
::
value
&&
!
is_char
<
T
>::
value
&&
(
has_formatter
<
T
,
Context
>::
value
||
!
std
::
is_constructible
<
basic_string_view
<
char_type
>
,
T
>::
value
&&
has_fallback_formatter
<
T
,
Context
>::
value
))
>
(
has_formatter
<
T
,
Context
>::
value
||
(
has_fallback_formatter
<
T
,
Context
>::
value
&&
!
std
::
is_constructible
<
std_string_view
<
char_type
>
,
T
>::
value
)))
>
FMT_CONSTEXPR
const
T
&
map
(
const
T
&
val
)
{
FMT_CONSTEXPR
const
T
&
map
(
const
T
&
val
)
{
return
val
;
return
val
;
}
}
...
...
test/format-test.cc
View file @
9f2e7eda
...
@@ -1691,16 +1691,14 @@ struct explicitly_convertible_to_std_string_view {
...
@@ -1691,16 +1691,14 @@ struct explicitly_convertible_to_std_string_view {
};
};
namespace
fmt
{
namespace
fmt
{
template
<
>
template
<
>
struct
formatter
<
explicitly_convertible_to_std_string_view
>
struct
formatter
<
explicitly_convertible_to_std_string_view
>
:
formatter
<
std
::
string_view
>
{
:
formatter
<
std
::
string_view
>
{
auto
format
(
const
explicitly_convertible_to_std_string_view
&
v
,
auto
format
(
const
explicitly_convertible_to_std_string_view
&
v
,
format_context
&
ctx
)
{
format_context
&
ctx
)
->
decltype
(
ctx
.
out
())
{
return
format_to
(
ctx
.
out
(),
"'{}'"
,
std
::
string_view
(
v
));
return
format_to
(
ctx
.
out
(),
"'{}'"
,
std
::
string_view
(
v
));
}
}
};
};
}
// namespace fmt
}
// namespace fmt
TEST
(
FormatterTest
,
FormatExplicitlyConvertibleToStdStringView
)
{
TEST
(
FormatterTest
,
FormatExplicitlyConvertibleToStdStringView
)
{
...
...
test/ostream-test.cc
View file @
9f2e7eda
...
@@ -276,3 +276,25 @@ std::ostream& operator<<(std::ostream& os,
...
@@ -276,3 +276,25 @@ std::ostream& operator<<(std::ostream& os,
TEST
(
FormatterTest
,
FormatExplicitlyConvertibleToStringLikeIgnoreInserter
)
{
TEST
(
FormatterTest
,
FormatExplicitlyConvertibleToStringLikeIgnoreInserter
)
{
EXPECT_EQ
(
"foo"
,
fmt
::
format
(
"{}"
,
explicitly_convertible_to_string_like
()));
EXPECT_EQ
(
"foo"
,
fmt
::
format
(
"{}"
,
explicitly_convertible_to_string_like
()));
}
}
#ifdef FMT_USE_STRING_VIEW
struct
explicitly_convertible_to_std_string_view
{
explicit
operator
fmt
::
internal
::
std_string_view
<
char
>
()
const
{
return
{
"foo"
,
3u
};
}
};
TEST
(
FormatterTest
,
FormatExplicitlyConvertibleToStdStringView
)
{
EXPECT_EQ
(
"foo"
,
fmt
::
format
(
"{}"
,
explicitly_convertible_to_string_like
()));
}
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
explicitly_convertible_to_std_string_view
)
{
return
os
<<
"bar"
;
}
TEST
(
FormatterTest
,
FormatExplicitlyConvertibleToStdStringViewIgnoreInserter
)
{
EXPECT_EQ
(
"foo"
,
fmt
::
format
(
"{}"
,
explicitly_convertible_to_std_string_view
()));
}
#endif // FMT_USE_STRING_VIEW
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