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
b3cf8613
Commit
b3cf8613
authored
Jun 07, 2019
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make formatter specializations override implicit conversions
parent
3fdba049
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
2 deletions
+29
-2
include/fmt/core.h
include/fmt/core.h
+10
-2
test/core-test.cc
test/core-test.cc
+19
-0
No files found.
include/fmt/core.h
View file @
b3cf8613
...
...
@@ -853,8 +853,8 @@ void make_value(const T*) {
}
template
<
typename
C
,
typename
T
,
FMT_ENABLE_IF
(
convert_to_int
<
T
,
typename
C
::
char_type
>
::
value
&&
std
::
is_enum
<
T
>::
value
)
>
FMT_ENABLE_IF
(
std
::
is_enum
<
T
>
::
value
&&
convert_to_int
<
T
,
typename
C
::
char_type
>::
value
)
>
inline
init
<
C
,
int
,
int_type
>
make_value
(
const
T
&
val
)
{
return
static_cast
<
int
>
(
val
);
}
...
...
@@ -873,6 +873,14 @@ inline init<C, const T&, custom_type> make_value(const T& val) {
return
val
;
}
template
<
typename
C
,
typename
T
,
FMT_ENABLE_IF
(
std
::
is_class
<
T
>
::
value
&&
std
::
is_convertible
<
T
,
int
>::
value
&&
is_formattable
<
T
,
C
>::
value
&&
!
std
::
is_same
<
T
,
typename
C
::
char_type
>::
value
)
>
inline
init
<
C
,
const
T
&
,
custom_type
>
make_value
(
const
T
&
val
)
{
return
val
;
}
template
<
typename
C
,
typename
T
>
init
<
C
,
const
void
*
,
named_arg_type
>
make_value
(
const
named_arg
<
T
,
typename
C
::
char_type
>&
val
)
{
...
...
test/core-test.cc
View file @
b3cf8613
...
...
@@ -442,6 +442,25 @@ TEST(CoreTest, ConvertToInt) {
EXPECT_TRUE
((
fmt
::
convert_to_int
<
enum_with_underlying_type
,
char
>::
value
));
}
struct
convertible_to_int
{
operator
int
()
const
{
return
42
;
}
};
FMT_BEGIN_NAMESPACE
template
<
>
struct
formatter
<
convertible_to_int
>
{
auto
parse
(
format_parse_context
&
ctx
)
->
decltype
(
ctx
.
begin
())
{
return
ctx
.
begin
();
}
auto
format
(
convertible_to_int
,
format_context
&
ctx
)
->
decltype
(
ctx
.
out
())
{
return
std
::
copy_n
(
"foo"
,
3
,
ctx
.
out
());
}
};
FMT_END_NAMESPACE
TEST
(
CoreTest
,
FormatterOverridesImplicitConversion
)
{
EXPECT_EQ
(
fmt
::
format
(
"{}"
,
convertible_to_int
()),
"foo"
);
}
namespace
my_ns
{
template
<
typename
Char
>
class
my_string
{
public:
...
...
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