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
17b362f7
Commit
17b362f7
authored
Feb 04, 2022
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify ostream opt-in API
parent
a5a7e3a2
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
20 deletions
+23
-20
include/fmt/ostream.h
include/fmt/ostream.h
+14
-9
test/ostream-test.cc
test/ostream-test.cc
+7
-9
test/xchar-test.cc
test/xchar-test.cc
+2
-2
No files found.
include/fmt/ostream.h
View file @
17b362f7
...
...
@@ -78,14 +78,12 @@ void format_value(buffer<Char>& buf, const T& value,
output
.
exceptions
(
std
::
ios_base
::
failbit
|
std
::
ios_base
::
badbit
);
buf
.
try_resize
(
buf
.
size
());
}
}
// namespace detail
// Formats an object of type T that has an overloaded ostream operator<<.
template
<
typename
T
,
typename
Char
>
struct
fallback_formatter
<
T
,
Char
,
enable_if_t
<
is_streamable
<
T
,
Char
>::
value
>>
:
private
formatter
<
basic_string_view
<
Char
>
,
Char
>
{
using
formatter
<
basic_string_view
<
Char
>
,
Char
>::
parse
;
template
<
typename
OutputIt
>
template
<
typename
Char
>
struct
basic_ostream_formatter
:
formatter
<
basic_string_view
<
Char
>
,
Char
>
{
template
<
typename
T
,
typename
OutputIt
>
auto
format
(
const
T
&
value
,
basic_format_context
<
OutputIt
,
Char
>&
ctx
)
const
->
OutputIt
{
auto
buffer
=
basic_memory_buffer
<
Char
>
();
...
...
@@ -93,7 +91,17 @@ struct fallback_formatter<T, Char, enable_if_t<is_streamable<T, Char>::value>>
return
formatter
<
basic_string_view
<
Char
>
,
Char
>::
format
(
{
buffer
.
data
(),
buffer
.
size
()},
ctx
);
}
};
using
ostream_formatter
=
basic_ostream_formatter
<
char
>
;
namespace
detail
{
// Formats an object of type T that has an overloaded ostream operator<<.
template
<
typename
T
,
typename
Char
>
struct
fallback_formatter
<
T
,
Char
,
enable_if_t
<
is_streamable
<
T
,
Char
>::
value
>>
:
basic_ostream_formatter
<
Char
>
{
using
basic_ostream_formatter
<
Char
>::
format
;
// DEPRECATED!
template
<
typename
OutputIt
>
auto
format
(
const
T
&
value
,
basic_printf_context
<
OutputIt
,
Char
>&
ctx
)
const
...
...
@@ -105,9 +113,6 @@ struct fallback_formatter<T, Char, enable_if_t<is_streamable<T, Char>::value>>
};
}
// namespace detail
template
<
typename
T
,
typename
Char
=
char
>
using
ostream_formatter
=
detail
::
fallback_formatter
<
T
,
Char
>
;
FMT_MODULE_EXPORT
template
<
typename
Char
>
void
vprint
(
std
::
basic_ostream
<
Char
>&
os
,
basic_string_view
<
Char
>
format_str
,
...
...
test/ostream-test.cc
View file @
17b362f7
...
...
@@ -57,11 +57,10 @@ struct empty_test {};
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
empty_test
)
{
return
os
<<
""
;
}
namespace
fmt
{
template
<
>
struct
formatter
<
test_string
>
:
ostream_formatter
<
test_string
>
{};
template
<
>
struct
formatter
<
date
>
:
ostream_formatter
<
date
>
{};
template
<
>
struct
formatter
<
streamable_enum
>
:
ostream_formatter
<
streamable_enum
>
{};
template
<
>
struct
formatter
<
empty_test
>
:
ostream_formatter
<
empty_test
>
{};
template
<
>
struct
formatter
<
test_string
>
:
ostream_formatter
{};
template
<
>
struct
formatter
<
date
>
:
ostream_formatter
{};
template
<
>
struct
formatter
<
streamable_enum
>
:
ostream_formatter
{};
template
<
>
struct
formatter
<
empty_test
>
:
ostream_formatter
{};
}
// namespace fmt
TEST
(
ostream_test
,
enum
)
{
...
...
@@ -193,8 +192,7 @@ template <typename T> struct formatter<test_template<T>> : formatter<int> {
}
};
template
<
>
struct
formatter
<
fmt_test
::
abc
>
:
ostream_formatter
<
fmt_test
::
abc
>
{};
template
<
>
struct
formatter
<
fmt_test
::
abc
>
:
ostream_formatter
{};
}
// namespace fmt
TEST
(
ostream_test
,
template
)
{
...
...
@@ -262,7 +260,7 @@ std::ostream& operator<<(std::ostream& os, copyfmt_test) {
}
namespace
fmt
{
template
<
>
struct
formatter
<
copyfmt_test
>
:
ostream_formatter
<
copyfmt_test
>
{};
template
<
>
struct
formatter
<
copyfmt_test
>
:
ostream_formatter
{};
}
// namespace fmt
TEST
(
ostream_test
,
copyfmt
)
{
...
...
@@ -287,7 +285,7 @@ struct abstract {
};
namespace
fmt
{
template
<
>
struct
formatter
<
abstract
>
:
ostream_formatter
<
abstract
>
{};
template
<
>
struct
formatter
<
abstract
>
:
ostream_formatter
{};
}
// namespace fmt
void
format_abstract_compiles
(
const
abstract
&
a
)
{
...
...
test/xchar-test.cc
View file @
17b362f7
...
...
@@ -222,8 +222,8 @@ std::wostream& operator<<(std::wostream& os, streamable_enum) {
namespace
fmt
{
template
<
>
struct
formatter
<
streamable_enum
,
wchar_t
>
:
ostream_formatter
<
streamable_enum
,
wchar_t
>
{
};
struct
formatter
<
streamable_enum
,
wchar_t
>
:
basic_ostream_formatter
<
wchar_t
>
{
};
}
// namespace fmt
enum
unstreamable_enum
{};
...
...
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