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
dd8cc8b0
Commit
dd8cc8b0
authored
Jul 09, 2019
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Disallow passing views as lvalues
parent
f6f0415b
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
60 additions
and
51 deletions
+60
-51
include/fmt/core.h
include/fmt/core.h
+26
-15
include/fmt/format.h
include/fmt/format.h
+5
-5
include/fmt/locale.h
include/fmt/locale.h
+5
-5
include/fmt/ostream.h
include/fmt/ostream.h
+2
-3
include/fmt/prepare.h
include/fmt/prepare.h
+10
-8
include/fmt/printf.h
include/fmt/printf.h
+12
-15
No files found.
include/fmt/core.h
View file @
dd8cc8b0
...
...
@@ -1260,10 +1260,20 @@ inline void check_format_string(const S&) {}
template
<
typename
...
,
typename
S
,
FMT_ENABLE_IF
(
is_compile_string
<
S
>
::
value
)
>
void
check_format_string
(
S
);
template
<
typename
S
,
typename
...
Args
,
typename
Char
=
char_t
<
S
>
>
inline
format_arg_store
<
buffer_context
<
Char
>
,
Args
...
>
make_args_checked
(
const
S
&
format_str
,
const
Args
&
...
args
)
{
check_format_string
<
Args
...
>
(
format_str
);
struct
view
{};
template
<
bool
...>
struct
bool_pack
;
template
<
bool
...
Args
>
using
all_true
=
std
::
is_same
<
bool_pack
<
Args
...,
true
>
,
bool_pack
<
true
,
Args
...
>>
;
template
<
typename
...
Args
,
typename
S
,
typename
Char
=
char_t
<
S
>
>
inline
format_arg_store
<
buffer_context
<
Char
>
,
remove_reference_t
<
Args
>
...
>
make_args_checked
(
const
S
&
format_str
,
const
remove_reference_t
<
Args
>&
...
args
)
{
static_assert
(
all_true
<
(
!
std
::
is_base_of
<
view
,
remove_reference_t
<
Args
>>
()
||
!
std
::
is_reference
<
Args
>
())...
>::
value
,
"passing views as lvalues is disallowed"
);
check_format_string
<
remove_reference_t
<
Args
>
...
>
(
format_str
);
return
{
args
...};
}
...
...
@@ -1321,9 +1331,10 @@ template <typename Container, typename S, typename... Args,
is_contiguous
<
Container
>
::
value
&&
internal
::
is_string
<
S
>::
value
)
>
inline
std
::
back_insert_iterator
<
Container
>
format_to
(
std
::
back_insert_iterator
<
Container
>
out
,
const
S
&
format_str
,
const
Args
&
...
args
)
{
return
vformat_to
(
out
,
to_string_view
(
format_str
),
{
internal
::
make_args_checked
(
format_str
,
args
...)});
Args
&&
...
args
)
{
return
vformat_to
(
out
,
to_string_view
(
format_str
),
{
internal
::
make_args_checked
<
Args
...
>
(
format_str
,
args
...)});
}
template
<
typename
S
,
typename
Char
=
char_t
<
S
>
>
...
...
@@ -1345,10 +1356,10 @@ inline std::basic_string<Char> vformat(
// Pass char_t as a default template parameter instead of using
// std::basic_string<char_t<S>> to reduce the symbol size.
template
<
typename
S
,
typename
...
Args
,
typename
Char
=
char_t
<
S
>
>
inline
std
::
basic_string
<
Char
>
format
(
const
S
&
format_str
,
const
Args
&
...
args
)
{
return
internal
::
vformat
(
to_string_view
(
format_str
),
{
internal
::
make_args_checked
(
format_str
,
args
...)});
inline
std
::
basic_string
<
Char
>
format
(
const
S
&
format_str
,
Args
&&
...
args
)
{
return
internal
::
vformat
(
to_string_view
(
format_str
),
{
internal
::
make_args_checked
<
Args
...
>
(
format_str
,
args
...)});
}
FMT_API
void
vprint
(
std
::
FILE
*
f
,
string_view
format_str
,
format_args
args
);
...
...
@@ -1367,9 +1378,9 @@ FMT_API void vprint(std::FILE* f, wstring_view format_str, wformat_args args);
*/
template
<
typename
S
,
typename
...
Args
,
FMT_ENABLE_IF
(
internal
::
is_string
<
S
>
::
value
)
>
inline
void
print
(
std
::
FILE
*
f
,
const
S
&
format_str
,
const
Args
&
...
args
)
{
inline
void
print
(
std
::
FILE
*
f
,
const
S
&
format_str
,
Args
&
&
...
args
)
{
vprint
(
f
,
to_string_view
(
format_str
),
internal
::
make_args_checked
(
format_str
,
args
...));
internal
::
make_args_checked
<
Args
...
>
(
format_str
,
args
...));
}
FMT_API
void
vprint
(
string_view
format_str
,
format_args
args
);
...
...
@@ -1386,9 +1397,9 @@ FMT_API void vprint(wstring_view format_str, wformat_args args);
*/
template
<
typename
S
,
typename
...
Args
,
FMT_ENABLE_IF
(
internal
::
is_string
<
S
>
::
value
)
>
inline
void
print
(
const
S
&
format_str
,
const
Args
&
...
args
)
{
inline
void
print
(
const
S
&
format_str
,
Args
&
&
...
args
)
{
vprint
(
to_string_view
(
format_str
),
internal
::
make_args_checked
(
format_str
,
args
...));
internal
::
make_args_checked
<
Args
...
>
(
format_str
,
args
...));
}
FMT_END_NAMESPACE
...
...
include/fmt/format.h
View file @
dd8cc8b0
...
...
@@ -3218,10 +3218,12 @@ template <typename T> inline const void* ptr(const std::shared_ptr<T>& p) {
return
p
.
get
();
}
template
<
typename
It
,
typename
Char
>
struct
arg_join
{
template
<
typename
It
,
typename
Char
>
struct
arg_join
:
internal
::
view
{
It
begin
;
It
end
;
basic_string_view
<
Char
>
sep
;
arg_join
(
It
b
,
It
e
,
basic_string_view
<
Char
>
s
)
:
begin
(
b
),
end
(
e
),
sep
(
s
)
{}
};
template
<
typename
It
,
typename
Char
>
...
...
@@ -3330,8 +3332,7 @@ inline typename buffer_context<Char>::iterator vformat_to(
template
<
typename
S
,
typename
...
Args
,
std
::
size_t
SIZE
=
inline_buffer_size
,
typename
Char
=
enable_if_t
<
internal
::
is_string
<
S
>
::
value
,
char_t
<
S
>>>
inline
typename
buffer_context
<
Char
>::
iterator
format_to
(
basic_memory_buffer
<
Char
,
SIZE
>&
buf
,
const
S
&
format_str
,
const
Args
&
...
args
)
{
basic_memory_buffer
<
Char
,
SIZE
>&
buf
,
const
S
&
format_str
,
Args
&&
...
args
)
{
internal
::
check_format_string
<
Args
...
>
(
format_str
);
using
context
=
buffer_context
<
Char
>
;
return
internal
::
vformat_to
(
buf
,
to_string_view
(
format_str
),
...
...
@@ -3367,8 +3368,7 @@ inline OutputIt vformat_to(OutputIt out, const S& format_str,
\endrst
*/
template
<
typename
OutputIt
,
typename
S
,
typename
...
Args
>
inline
OutputIt
format_to
(
OutputIt
out
,
const
S
&
format_str
,
const
Args
&
...
args
)
{
inline
OutputIt
format_to
(
OutputIt
out
,
const
S
&
format_str
,
Args
&&
...
args
)
{
static_assert
(
internal
::
is_output_iterator
<
OutputIt
>::
value
&&
internal
::
is_string
<
S
>::
value
,
""
);
...
...
include/fmt/locale.h
View file @
dd8cc8b0
...
...
@@ -43,10 +43,10 @@ inline std::basic_string<Char> vformat(
template
<
typename
S
,
typename
...
Args
,
typename
Char
=
char_t
<
S
>
>
inline
std
::
basic_string
<
Char
>
format
(
const
std
::
locale
&
loc
,
const
S
&
format_str
,
const
Args
&
...
args
)
{
return
internal
::
vformat
(
loc
,
to_string_view
(
format_str
),
{
internal
::
make_args_checked
(
format_str
,
args
...)});
const
S
&
format_str
,
Args
&&
...
args
)
{
return
internal
::
vformat
(
loc
,
to_string_view
(
format_str
),
{
internal
::
make_args_checked
<
Args
...
>
(
format_str
,
args
...)});
}
template
<
typename
S
,
typename
OutputIt
,
typename
...
Args
,
...
...
@@ -64,7 +64,7 @@ template <typename OutputIt, typename S, typename... Args,
FMT_ENABLE_IF
(
internal
::
is_output_iterator
<
OutputIt
>
::
value
&&
internal
::
is_string
<
S
>::
value
)
>
inline
OutputIt
format_to
(
OutputIt
out
,
const
std
::
locale
&
loc
,
const
S
&
format_str
,
const
Args
&
...
args
)
{
const
S
&
format_str
,
Args
&
&
...
args
)
{
internal
::
check_format_string
<
Args
...
>
(
format_str
);
using
context
=
format_context_t
<
OutputIt
,
char_t
<
S
>>
;
format_arg_store
<
context
,
Args
...
>
as
{
args
...};
...
...
include/fmt/ostream.h
View file @
dd8cc8b0
...
...
@@ -127,10 +127,9 @@ void vprint(std::basic_ostream<Char>& os, basic_string_view<Char> format_str,
*/
template
<
typename
S
,
typename
...
Args
,
typename
Char
=
enable_if_t
<
internal
::
is_string
<
S
>
::
value
,
char_t
<
S
>>>
void
print
(
std
::
basic_ostream
<
Char
>&
os
,
const
S
&
format_str
,
const
Args
&
...
args
)
{
void
print
(
std
::
basic_ostream
<
Char
>&
os
,
const
S
&
format_str
,
Args
&&
...
args
)
{
vprint
(
os
,
to_string_view
(
format_str
),
{
internal
::
make_args_checked
(
format_str
,
args
...)});
{
internal
::
make_args_checked
<
Args
...
>
(
format_str
,
args
...)});
}
FMT_END_NAMESPACE
...
...
include/fmt/prepare.h
View file @
dd8cc8b0
...
...
@@ -215,18 +215,20 @@ class prepared_format {
std
::
basic_string
<
char_type
>
format
(
const
Args
&
...
args
)
const
{
basic_memory_buffer
<
char_type
>
buffer
;
using
range
=
buffer_range
<
char_type
>
;
this
->
vformat_to
(
range
(
buffer
),
basic_format_args
<
context
>
{
make_args_checked
(
format_
,
args
...)});
this
->
vformat_to
(
range
(
buffer
),
basic_format_args
<
context
>
{
make_args_checked
<
Args
...
>
(
format_
,
args
...)});
return
to_string
(
buffer
);
}
template
<
typename
Container
,
FMT_ENABLE_IF
(
is_contiguous
<
Container
>
::
value
)
>
inline
std
::
back_insert_iterator
<
Container
>
format_to
(
std
::
back_insert_iterator
<
Container
>
out
,
const
Args
&
...
args
)
const
{
std
::
back_insert_iterator
<
Container
>
out
,
Args
&
&
...
args
)
const
{
internal
::
container_buffer
<
Container
>
buffer
(
internal
::
get_container
(
out
));
using
range
=
buffer_range
<
char_type
>
;
this
->
vformat_to
(
range
(
buffer
),
basic_format_args
<
context
>
{
make_args_checked
(
format_
,
args
...)});
this
->
vformat_to
(
range
(
buffer
),
basic_format_args
<
context
>
{
make_args_checked
<
Args
...
>
(
format_
,
args
...)});
return
out
;
}
...
...
@@ -242,9 +244,9 @@ class prepared_format {
inline
typename
buffer_context
<
char_type
>::
iterator
format_to
(
basic_memory_buffer
<
char_type
,
SIZE
>&
buf
,
const
Args
&
...
args
)
const
{
using
range
=
buffer_range
<
char_type
>
;
return
this
->
vformat_to
(
range
(
buf
),
basic_format_args
<
context
>
{
make_args_checked
(
format_
,
args
...)});
return
this
->
vformat_to
(
range
(
buf
),
basic_format_args
<
context
>
{
make_args_checked
<
Args
...
>
(
format_
,
args
...)});
}
private:
...
...
include/fmt/printf.h
View file @
dd8cc8b0
...
...
@@ -138,7 +138,7 @@ template <typename Context> class char_converter {
template
<
typename
T
,
FMT_ENABLE_IF
(
std
::
is_integral
<
T
>
::
value
)
>
void
operator
()(
T
value
)
{
arg_
=
internal
::
make_arg
<
Context
>
(
static_cast
<
typename
Context
::
char_type
>
(
value
));
static_cast
<
typename
Context
::
char_type
>
(
value
));
}
template
<
typename
T
,
FMT_ENABLE_IF
(
!
std
::
is_integral
<
T
>
::
value
)
>
...
...
@@ -563,9 +563,10 @@ OutputIt basic_printf_context<OutputIt, Char>::format() {
return
std
::
copy
(
start
,
it
,
out
);
}
template
<
typename
Char
>
using
basic_printf_context_t
=
basic_printf_context
<
std
::
back_insert_iterator
<
internal
::
buffer
<
Char
>>
,
Char
>
;
template
<
typename
Char
>
using
basic_printf_context_t
=
basic_printf_context
<
std
::
back_insert_iterator
<
internal
::
buffer
<
Char
>>
,
Char
>
;
using
printf_context
=
basic_printf_context_t
<
char
>
;
using
wprintf_context
=
basic_printf_context_t
<
wchar_t
>
;
...
...
@@ -599,8 +600,7 @@ inline format_arg_store<wprintf_context, Args...> make_wprintf_args(
template
<
typename
S
,
typename
Char
=
char_t
<
S
>
>
inline
std
::
basic_string
<
Char
>
vsprintf
(
const
S
&
format
,
basic_format_args
<
basic_printf_context_t
<
Char
>>
args
)
{
const
S
&
format
,
basic_format_args
<
basic_printf_context_t
<
Char
>>
args
)
{
basic_memory_buffer
<
Char
>
buffer
;
printf
(
buffer
,
to_string_view
(
format
),
args
);
return
to_string
(
buffer
);
...
...
@@ -623,9 +623,8 @@ inline std::basic_string<Char> sprintf(const S& format, const Args&... args) {
}
template
<
typename
S
,
typename
Char
=
char_t
<
S
>
>
inline
int
vfprintf
(
std
::
FILE
*
f
,
const
S
&
format
,
basic_format_args
<
basic_printf_context_t
<
Char
>>
args
)
{
inline
int
vfprintf
(
std
::
FILE
*
f
,
const
S
&
format
,
basic_format_args
<
basic_printf_context_t
<
Char
>>
args
)
{
basic_memory_buffer
<
Char
>
buffer
;
printf
(
buffer
,
to_string_view
(
format
),
args
);
std
::
size_t
size
=
buffer
.
size
();
...
...
@@ -652,9 +651,8 @@ inline int fprintf(std::FILE* f, const S& format, const Args&... args) {
}
template
<
typename
S
,
typename
Char
=
char_t
<
S
>
>
inline
int
vprintf
(
const
S
&
format
,
basic_format_args
<
basic_printf_context_t
<
Char
>>
args
)
{
inline
int
vprintf
(
const
S
&
format
,
basic_format_args
<
basic_printf_context_t
<
Char
>>
args
)
{
return
vfprintf
(
stdout
,
to_string_view
(
format
),
args
);
}
...
...
@@ -676,9 +674,8 @@ inline int printf(const S& format_str, const Args&... args) {
}
template
<
typename
S
,
typename
Char
=
char_t
<
S
>
>
inline
int
vfprintf
(
std
::
basic_ostream
<
Char
>&
os
,
const
S
&
format
,
basic_format_args
<
basic_printf_context_t
<
Char
>>
args
)
{
inline
int
vfprintf
(
std
::
basic_ostream
<
Char
>&
os
,
const
S
&
format
,
basic_format_args
<
basic_printf_context_t
<
Char
>>
args
)
{
basic_memory_buffer
<
Char
>
buffer
;
printf
(
buffer
,
to_string_view
(
format
),
args
);
internal
::
write
(
os
,
buffer
);
...
...
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