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
2cac8a9d
Commit
2cac8a9d
authored
Jun 21, 2020
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reintroduce UDT support to fmt::to_string and test ADL
parent
9a4cc884
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
0 deletions
+30
-0
include/fmt/format.h
include/fmt/format.h
+9
-0
test/format-test.cc
test/format-test.cc
+21
-0
No files found.
include/fmt/format.h
View file @
2cac8a9d
...
@@ -1777,6 +1777,15 @@ OutputIt write(OutputIt out, const void* value) {
...
@@ -1777,6 +1777,15 @@ OutputIt write(OutputIt out, const void* value) {
return
write_ptr
<
Char
>
(
out
,
to_uintptr
(
value
),
nullptr
);
return
write_ptr
<
Char
>
(
out
,
to_uintptr
(
value
),
nullptr
);
}
}
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
{
basic_format_context
<
OutputIt
,
Char
>
ctx
(
out
,
{},
{});
return
formatter
<
T
>
().
format
(
value
,
ctx
);
}
// An argument visitor that formats the argument and writes it via the output
// An argument visitor that formats the argument and writes it via the output
// iterator. It's a class and not a generic lambda for compatibility with C++11.
// iterator. It's a class and not a generic lambda for compatibility with C++11.
template
<
typename
OutputIt
,
typename
Char
>
struct
default_arg_formatter
{
template
<
typename
OutputIt
,
typename
Char
>
struct
default_arg_formatter
{
...
...
test/format-test.cc
View file @
2cac8a9d
...
@@ -1906,9 +1906,30 @@ TEST(FormatTest, DynamicFormatter) {
...
@@ -1906,9 +1906,30 @@ TEST(FormatTest, DynamicFormatter) {
"precision not allowed for this argument type"
);
"precision not allowed for this argument type"
);
}
}
namespace
adl_test
{
namespace
fmt
{
namespace
detail
{
struct
foo
{};
template
<
typename
,
typename
OutputIt
>
void
write
(
OutputIt
,
foo
)
=
delete
;
}
// namespace detail
}
// namespace fmt
}
// namespace adl_test
FMT_BEGIN_NAMESPACE
template
<
>
struct
formatter
<
adl_test
::
fmt
::
detail
::
foo
>
:
formatter
<
std
::
string
>
{
template
<
typename
FormatContext
>
auto
format
(
adl_test
::
fmt
::
detail
::
foo
,
FormatContext
&
ctx
)
->
decltype
(
ctx
.
out
())
{
return
formatter
<
std
::
string
>::
format
(
"foo"
,
ctx
);
}
};
FMT_END_NAMESPACE
TEST
(
FormatTest
,
ToString
)
{
TEST
(
FormatTest
,
ToString
)
{
EXPECT_EQ
(
"42"
,
fmt
::
to_string
(
42
));
EXPECT_EQ
(
"42"
,
fmt
::
to_string
(
42
));
EXPECT_EQ
(
"0x1234"
,
fmt
::
to_string
(
reinterpret_cast
<
void
*>
(
0x1234
)));
EXPECT_EQ
(
"0x1234"
,
fmt
::
to_string
(
reinterpret_cast
<
void
*>
(
0x1234
)));
EXPECT_EQ
(
"foo"
,
fmt
::
to_string
(
adl_test
::
fmt
::
detail
::
foo
()));
}
}
TEST
(
FormatTest
,
ToWString
)
{
EXPECT_EQ
(
L"42"
,
fmt
::
to_wstring
(
42
));
}
TEST
(
FormatTest
,
ToWString
)
{
EXPECT_EQ
(
L"42"
,
fmt
::
to_wstring
(
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