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
0d07db12
Commit
0d07db12
authored
Nov 25, 2019
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix handling of streamable and convertible to string types
parent
d19ed671
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
15 deletions
+25
-15
include/fmt/core.h
include/fmt/core.h
+2
-0
test/core-test.cc
test/core-test.cc
+0
-13
test/ostream-test.cc
test/ostream-test.cc
+23
-2
No files found.
include/fmt/core.h
View file @
0d07db12
...
@@ -905,6 +905,8 @@ template <typename Context> struct arg_mapper {
...
@@ -905,6 +905,8 @@ template <typename Context> struct arg_mapper {
}
}
template
<
typename
T
,
template
<
typename
T
,
FMT_ENABLE_IF
(
!
is_string
<
T
>
::
value
&&
!
is_char
<
T
>::
value
&&
FMT_ENABLE_IF
(
!
is_string
<
T
>
::
value
&&
!
is_char
<
T
>::
value
&&
!
std
::
is_constructible
<
basic_string_view
<
char_type
>
,
T
>::
value
&&
(
has_formatter
<
T
,
Context
>::
value
||
(
has_formatter
<
T
,
Context
>::
value
||
has_fallback_formatter
<
T
,
Context
>::
value
))
>
has_fallback_formatter
<
T
,
Context
>::
value
))
>
FMT_CONSTEXPR
const
T
&
map
(
const
T
&
val
)
{
FMT_CONSTEXPR
const
T
&
map
(
const
T
&
val
)
{
...
...
test/core-test.cc
View file @
0d07db12
...
@@ -635,19 +635,6 @@ TEST(FormatterTest, FormatExplicitlyConvertibleToWStringView) {
...
@@ -635,19 +635,6 @@ TEST(FormatterTest, FormatExplicitlyConvertibleToWStringView) {
EXPECT_EQ
(
L"foo"
,
EXPECT_EQ
(
L"foo"
,
fmt
::
format
(
L"{}"
,
explicitly_convertible_to_wstring_view
()));
fmt
::
format
(
L"{}"
,
explicitly_convertible_to_wstring_view
()));
}
}
struct
explicitly_convertible_to_string_like
{
template
<
typename
String
,
typename
=
typename
std
::
enable_if
<
std
::
is_constructible
<
String
,
const
char
*
,
std
::
size_t
>
::
value
>::
type
>
explicit
operator
String
()
const
{
return
String
(
"foo"
,
3u
);
}
};
TEST
(
FormatterTest
,
FormatExplicitlyConvertibleToStringLike
)
{
EXPECT_EQ
(
"foo"
,
fmt
::
format
(
"{}"
,
explicitly_convertible_to_string_like
()));
}
#endif
#endif
struct
disabled_rvalue_conversion
{
struct
disabled_rvalue_conversion
{
...
...
test/ostream-test.cc
View file @
0d07db12
...
@@ -243,8 +243,7 @@ TEST(FormatTest, UDL) {
...
@@ -243,8 +243,7 @@ TEST(FormatTest, UDL) {
}
}
#endif
#endif
template
<
typename
T
>
template
<
typename
T
>
struct
convertible
{
struct
convertible
{
T
value
;
T
value
;
explicit
convertible
(
const
T
&
val
)
:
value
(
val
)
{}
explicit
convertible
(
const
T
&
val
)
:
value
(
val
)
{}
operator
T
()
const
{
return
value
;
}
operator
T
()
const
{
return
value
;
}
...
@@ -255,3 +254,25 @@ TEST(OStreamTest, DisableBuiltinOStreamOperators) {
...
@@ -255,3 +254,25 @@ TEST(OStreamTest, DisableBuiltinOStreamOperators) {
EXPECT_EQ
(
L"42"
,
fmt
::
format
(
L"{:d}"
,
convertible
<
unsigned
short
>
(
42
)));
EXPECT_EQ
(
L"42"
,
fmt
::
format
(
L"{:d}"
,
convertible
<
unsigned
short
>
(
42
)));
EXPECT_EQ
(
"foo"
,
fmt
::
format
(
"{}"
,
convertible
<
const
char
*>
(
"foo"
)));
EXPECT_EQ
(
"foo"
,
fmt
::
format
(
"{}"
,
convertible
<
const
char
*>
(
"foo"
)));
}
}
struct
explicitly_convertible_to_string_like
{
template
<
typename
String
,
typename
=
typename
std
::
enable_if
<
std
::
is_constructible
<
String
,
const
char
*
,
std
::
size_t
>
::
value
>::
type
>
explicit
operator
String
()
const
{
return
String
(
"foo"
,
3u
);
}
};
TEST
(
FormatterTest
,
FormatExplicitlyConvertibleToStringLike
)
{
EXPECT_EQ
(
"foo"
,
fmt
::
format
(
"{}"
,
explicitly_convertible_to_string_like
()));
}
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
explicitly_convertible_to_string_like
)
{
return
os
<<
"bar"
;
}
TEST
(
FormatterTest
,
FormatExplicitlyConvertibleToStringLikeIgnoreInserter
)
{
EXPECT_EQ
(
"foo"
,
fmt
::
format
(
"{}"
,
explicitly_convertible_to_string_like
()));
}
\ No newline at end of file
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