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
f13906f4
Commit
f13906f4
authored
Jun 19, 2019
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
back_insert_range<internal::buffer> -> buffer_range
parent
22ddd4b9
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
39 additions
and
39 deletions
+39
-39
include/fmt/format.h
include/fmt/format.h
+27
-25
include/fmt/locale.h
include/fmt/locale.h
+1
-1
include/fmt/prepare.h
include/fmt/prepare.h
+3
-3
include/fmt/printf.h
include/fmt/printf.h
+1
-1
test/custom-formatter-test.cc
test/custom-formatter-test.cc
+2
-3
test/format
test/format
+1
-1
test/format-test.cc
test/format-test.cc
+2
-2
test/ostream-test.cc
test/ostream-test.cc
+1
-1
test/printf-test.cc
test/printf-test.cc
+1
-2
No files found.
include/fmt/format.h
View file @
f13906f4
...
...
@@ -191,10 +191,6 @@ FMT_END_NAMESPACE
FMT_BEGIN_NAMESPACE
namespace
internal
{
#ifndef FMT_USE_GRISU
# define FMT_USE_GRISU 1
#endif
// A fallback implementation of uintptr_t for systems that lack it.
struct
fallback_uintptr
{
unsigned
char
value
[
sizeof
(
void
*
)];
...
...
@@ -205,11 +201,6 @@ using uintptr_t = ::uintptr_t;
using
uintptr_t
=
fallback_uintptr
;
#endif
template
<
typename
T
>
inline
bool
use_grisu
()
{
return
FMT_USE_GRISU
&&
std
::
numeric_limits
<
double
>::
is_iec559
&&
sizeof
(
T
)
<=
sizeof
(
double
);
}
// An equivalent of `*reinterpret_cast<Dest*>(&source)` that doesn't produce
// undefined behavior (e.g. due to type aliasing).
// Example: uint64_t d = bit_cast<uint64_t>(2.718);
...
...
@@ -224,6 +215,30 @@ inline Dest bit_cast(const Source& source) {
// An implementation of iterator_t for pre-C++20 systems.
template
<
typename
T
>
using
iterator_t
=
decltype
(
std
::
begin
(
std
::
declval
<
T
&>
()));
#ifndef FMT_USE_GRISU
# define FMT_USE_GRISU 1
#endif
template
<
typename
T
>
inline
bool
use_grisu
()
{
return
FMT_USE_GRISU
&&
std
::
numeric_limits
<
double
>::
is_iec559
&&
sizeof
(
T
)
<=
sizeof
(
double
);
}
// A range whose output iterator appends to a buffer.
template
<
typename
T
>
class
buffer_range
{
public:
using
value_type
=
T
;
using
iterator
=
std
::
back_insert_iterator
<
internal
::
buffer
<
T
>>
;
private:
iterator
begin_
;
public:
buffer_range
(
internal
::
buffer
<
T
>&
buf
)
:
begin_
(
std
::
back_inserter
(
buf
))
{}
explicit
buffer_range
(
iterator
it
)
:
begin_
(
it
)
{}
iterator
begin
()
const
{
return
begin_
;
}
};
}
// namespace internal
template
<
typename
OutputIt
,
typename
T
=
typename
OutputIt
::
value_type
>
...
...
@@ -243,22 +258,9 @@ class output_range {
OutputIt
begin
()
const
{
return
it_
;
}
};
// A range where begin() returns back_insert_iterator.
template
<
typename
Container
>
class
back_insert_range
:
public
output_range
<
std
::
back_insert_iterator
<
Container
>>
{
using
base
=
output_range
<
std
::
back_insert_iterator
<
Container
>>
;
public:
using
value_type
=
typename
Container
::
value_type
;
back_insert_range
(
Container
&
c
)
:
base
(
std
::
back_inserter
(
c
))
{}
back_insert_range
(
typename
base
::
iterator
it
)
:
base
(
it
)
{}
};
template
<
typename
Range
>
class
basic_writer
;
using
writer
=
basic_writer
<
back_insert_range
<
internal
::
buffer
<
char
>
>>
;
using
wwriter
=
basic_writer
<
back_insert_range
<
internal
::
buffer
<
wchar_t
>
>>
;
using
writer
=
basic_writer
<
internal
::
buffer_range
<
char
>>
;
using
wwriter
=
basic_writer
<
internal
::
buffer_range
<
wchar_t
>>
;
/** A formatting error such as invalid format string. */
class
format_error
:
public
std
::
runtime_error
{
...
...
@@ -3284,7 +3286,7 @@ template <typename Char>
typename
buffer_context
<
Char
>::
iterator
internal
::
vformat_to
(
internal
::
buffer
<
Char
>&
buf
,
basic_string_view
<
Char
>
format_str
,
basic_format_args
<
buffer_context
<
Char
>>
args
)
{
typedef
back_insert_range
<
internal
::
buffer
<
Char
>>
range
;
using
range
=
buffer_range
<
Char
>
;
return
vformat_to
<
arg_formatter
<
range
>>
(
buf
,
to_string_view
(
format_str
),
args
);
}
...
...
include/fmt/locale.h
View file @
f13906f4
...
...
@@ -19,7 +19,7 @@ typename buffer_context<Char>::iterator vformat_to(
const
std
::
locale
&
loc
,
buffer
<
Char
>&
buf
,
basic_string_view
<
Char
>
format_str
,
basic_format_args
<
buffer_context
<
Char
>>
args
)
{
typedef
back_insert_range
<
buffer
<
Char
>>
range
;
using
range
=
buffer_range
<
Char
>
;
return
vformat_to
<
arg_formatter
<
range
>>
(
buf
,
to_string_view
(
format_str
),
args
,
internal
::
locale_ref
(
loc
));
}
...
...
include/fmt/prepare.h
View file @
f13906f4
...
...
@@ -214,7 +214,7 @@ class prepared_format {
std
::
basic_string
<
char_type
>
format
(
const
Args
&
...
args
)
const
{
basic_memory_buffer
<
char_type
>
buffer
;
typedef
back_insert_range
<
internal
::
buffer
<
char_type
>>
range
;
using
range
=
buffer_range
<
char_type
>
;
this
->
vformat_to
(
range
(
buffer
),
basic_format_args
<
context
>
{
make_args_checked
(
format_
,
args
...)});
return
to_string
(
buffer
);
...
...
@@ -224,7 +224,7 @@ class prepared_format {
inline
std
::
back_insert_iterator
<
Container
>
format_to
(
std
::
back_insert_iterator
<
Container
>
out
,
const
Args
&
...
args
)
const
{
internal
::
container_buffer
<
Container
>
buffer
(
internal
::
get_container
(
out
));
typedef
back_insert_range
<
internal
::
buffer
<
char_type
>>
range
;
using
range
=
buffer_range
<
char_type
>
;
this
->
vformat_to
(
range
(
buffer
),
basic_format_args
<
context
>
{
make_args_checked
(
format_
,
args
...)});
return
out
;
...
...
@@ -241,7 +241,7 @@ class prepared_format {
template
<
std
::
size_t
SIZE
=
inline_buffer_size
>
inline
typename
buffer_context
<
char_type
>::
iterator
format_to
(
basic_memory_buffer
<
char_type
,
SIZE
>&
buf
,
const
Args
&
...
args
)
const
{
typedef
back_insert_range
<
internal
::
buffer
<
char_type
>>
range
;
using
range
=
buffer_range
<
char_type
>
;
return
this
->
vformat_to
(
range
(
buf
),
basic_format_args
<
context
>
{
make_args_checked
(
format_
,
args
...)});
...
...
include/fmt/printf.h
View file @
f13906f4
...
...
@@ -368,7 +368,7 @@ template <typename OutputIt, typename Char> class basic_printf_context {
/** Formats stored arguments and writes the output to the range. */
template
<
typename
ArgFormatter
=
printf_arg_formatter
<
back_insert_range
<
internal
::
buffer
<
Char
>
>>>
printf_arg_formatter
<
internal
::
buffer_range
<
Char
>
>>
OutputIt
format
();
};
...
...
test/custom-formatter-test.cc
View file @
f13906f4
...
...
@@ -18,10 +18,9 @@
// A custom argument formatter that doesn't print `-` for floating-point values
// rounded to 0.
class
custom_arg_formatter
:
public
fmt
::
arg_formatter
<
fmt
::
back_insert_range
<
fmt
::
internal
::
buffer
<
char
>>>
{
:
public
fmt
::
arg_formatter
<
fmt
::
internal
::
buffer_range
<
char
>>
{
public:
typedef
fmt
::
back_insert_range
<
fmt
::
internal
::
buffer
<
char
>>
range
;
using
range
=
fmt
::
internal
::
buffer_range
<
char
>
;
typedef
fmt
::
arg_formatter
<
range
>
base
;
custom_arg_formatter
(
fmt
::
format_context
&
ctx
,
...
...
test/format
View file @
f13906f4
...
...
@@ -719,7 +719,7 @@ template<class... Args>
string vformat(string_view fmt, format_args args) {
fmt::memory_buffer mbuf;
fmt::internal::buffer<char>& buf = mbuf;
typedef fmt::back_insert_range<fmt::internal::buffer<char>> range
;
using range = fmt::internal::buffer_range<char>
;
detail::format_handler<detail::arg_formatter<range>, char, format_context>
h(range(std::back_inserter(buf)), fmt, args, {});
fmt::internal::parse_format_string<false>(fmt::to_string_view(fmt), h);
...
...
test/format-test.cc
View file @
f13906f4
...
...
@@ -99,7 +99,7 @@ void std_format(long double value, std::wstring& result) {
template
<
typename
Char
,
typename
T
>
::
testing
::
AssertionResult
check_write
(
const
T
&
value
,
const
char
*
type
)
{
fmt
::
basic_memory_buffer
<
Char
>
buffer
;
typedef
fmt
::
back_insert_range
<
fmt
::
internal
::
buffer
<
Char
>>
range
;
using
range
=
fmt
::
internal
::
buffer_range
<
Char
>
;
fmt
::
basic_writer
<
range
>
writer
(
buffer
);
writer
.
write
(
value
);
std
::
basic_string
<
Char
>
actual
=
to_string
(
buffer
);
...
...
@@ -1894,7 +1894,7 @@ enum TestFixedEnum : short { B };
TEST
(
FormatTest
,
FixedEnum
)
{
EXPECT_EQ
(
"0"
,
fmt
::
format
(
"{}"
,
B
));
}
#endif
typedef
fmt
::
back_insert_range
<
fmt
::
internal
::
buffer
<
char
>>
buffer_range
;
using
buffer_range
=
fmt
::
internal
::
buffer_range
<
char
>
;
class
mock_arg_formatter
:
public
fmt
::
internal
::
arg_formatter_base
<
buffer_range
>
{
...
...
test/ostream-test.cc
View file @
f13906f4
...
...
@@ -64,7 +64,7 @@ TEST(OStreamTest, Enum) {
EXPECT_EQ
(
L"0"
,
fmt
::
format
(
L"{}"
,
unstreamable_enum
()));
}
typedef
fmt
::
back_insert_range
<
fmt
::
internal
::
buffer
<
char
>>
range
;
using
range
=
fmt
::
internal
::
buffer_range
<
char
>
;
struct
test_arg_formatter
:
fmt
::
arg_formatter
<
range
>
{
fmt
::
format_parse_context
parse_ctx
;
...
...
test/printf-test.cc
View file @
f13906f4
...
...
@@ -561,8 +561,7 @@ TEST(PrintfTest, VSPrintfMakeWArgsExample) {
#endif
}
typedef
fmt
::
printf_arg_formatter
<
fmt
::
back_insert_range
<
fmt
::
internal
::
buffer
<
char
>>>
typedef
fmt
::
printf_arg_formatter
<
fmt
::
internal
::
buffer_range
<
char
>>
formatter_t
;
typedef
fmt
::
basic_printf_context
<
formatter_t
::
iterator
,
char
>
context_t
;
...
...
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