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
4f164097
Commit
4f164097
authored
Jul 22, 2018
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Merge format overloads using SFINAE
parent
2a4e9488
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
16 deletions
+55
-16
include/fmt/core.h
include/fmt/core.h
+47
-9
include/fmt/format.h
include/fmt/format.h
+8
-7
No files found.
include/fmt/core.h
View file @
4f164097
...
...
@@ -711,7 +711,7 @@ struct result_of<F(Args...)> {
typedef
typename
std
::
result_of
<
typename
std
::
remove_reference
<
F
>::
type
(
Args
...)
>::
type
type
;
};
}
}
// namespace internal
// A formatting argument. It is a trivially copyable/constructible type to
// allow storage in basic_memory_buffer.
...
...
@@ -1292,6 +1292,44 @@ typename std::enable_if<
std
::
string
vformat
(
string_view
format_str
,
format_args
args
);
std
::
wstring
vformat
(
wstring_view
format_str
,
wformat_args
args
);
namespace
internal
{
// If S is a format string type, format_string_traints<S>::char_type gives its
// character type.
template
<
typename
S
>
struct
format_string_traits
{
private:
// Use construtbility as a way to detect if format_string_traits is
// specialized because other methods are broken on MSVC2013.
format_string_traits
();
};
template
<
typename
Char
>
struct
format_string_traits_base
{
typedef
Char
char_type
;
};
template
<
typename
Char
>
struct
format_string_traits
<
const
Char
*>:
format_string_traits_base
<
Char
>
{};
template
<
typename
Char
>
struct
format_string_traits
<
Char
*>:
format_string_traits_base
<
Char
>
{};
template
<
typename
Char
>
struct
format_string_traits
<
std
::
basic_string
<
Char
>>:
format_string_traits_base
<
Char
>
{};
template
<
typename
Char
>
struct
format_string_traits
<
basic_string_view
<
Char
>>:
format_string_traits_base
<
Char
>
{};
template
<
typename
S
>
struct
is_format_string
:
std
::
integral_constant
<
bool
,
std
::
is_constructible
<
format_string_traits
<
S
>>::
value
>
{};
template
<
typename
...
Args
,
typename
S
>
typename
std
::
enable_if
<
is_format_string
<
S
>::
value
>::
type
check_format_string
(
S
)
{}
}
// namespace internal
/**
\rst
Formats arguments and returns the result as a string.
...
...
@@ -1302,17 +1340,17 @@ std::wstring vformat(wstring_view format_str, wformat_args args);
std::string message = fmt::format("The answer is {}", 42);
\endrst
*/
template
<
typename
...
Args
>
inline
std
::
string
format
(
string_view
format_str
,
const
Args
&
...
args
)
{
template
<
typename
String
,
typename
...
Args
>
inline
std
::
basic_string
<
typename
internal
::
format_string_traits
<
String
>::
char_type
>
format
(
String
format_str
,
const
Args
&
...
args
)
{
typedef
typename
internal
::
format_string_traits
<
String
>::
char_type
char_type
;
internal
::
check_format_string
<
Args
...
>
(
format_str
);
// This should be just
// return vformat(format_str, make_format_args(args...));
// but gcc has trouble optimizing the latter, so break it down.
format_arg_store
<
format_context
,
Args
...
>
as
{
args
...};
return
vformat
(
format_str
,
as
);
}
template
<
typename
...
Args
>
inline
std
::
wstring
format
(
wstring_view
format_str
,
const
Args
&
...
args
)
{
format_arg_store
<
wformat_context
,
Args
...
>
as
{
args
...};
typedef
typename
buffer_context
<
char_type
>::
type
context_type
;
format_arg_store
<
context_type
,
Args
...
>
as
{
args
...};
return
vformat
(
format_str
,
as
);
}
...
...
include/fmt/format.h
View file @
4f164097
...
...
@@ -1352,7 +1352,7 @@ FMT_CONSTEXPR unsigned basic_parse_context<Char, ErrorHandler>::next_arg_id() {
return
0
;
}
struct
format
_string
{};
struct
compile
_string
{};
namespace
internal
{
...
...
@@ -1646,8 +1646,8 @@ class arg_formatter_base {
};
template
<
typename
S
>
struct
is_
format
_string
:
std
::
integral_constant
<
bool
,
std
::
is_base_of
<
format
_string
,
S
>::
value
>
{};
struct
is_
compile
_string
:
std
::
integral_constant
<
bool
,
std
::
is_base_of
<
compile
_string
,
S
>::
value
>
{};
template
<
typename
Char
>
FMT_CONSTEXPR
bool
is_name_start
(
Char
c
)
{
...
...
@@ -2317,7 +2317,8 @@ FMT_CONSTEXPR bool check_format_string(
}
template
<
typename
...
Args
,
typename
String
>
void
check_format_string
(
String
format_str
)
{
typename
std
::
enable_if
<
is_compile_string
<
String
>::
value
>::
type
check_format_string
(
String
format_str
)
{
FMT_CONSTEXPR_DECL
bool
invalid_format
=
internal
::
check_format_string
<
char
,
internal
::
error_handler
,
Args
...
>
(
string_view
(
format_str
.
data
(),
format_str
.
size
()));
...
...
@@ -3678,14 +3679,14 @@ inline std::wstring vformat(wstring_view format_str, wformat_args args) {
template
<
typename
String
,
typename
...
Args
>
inline
typename
std
::
enable_if
<
internal
::
is_
format
_string
<
String
>::
value
,
std
::
string
>::
type
internal
::
is_
compile
_string
<
String
>::
value
,
std
::
string
>::
type
format
(
String
format_str
,
const
Args
&
...
args
)
{
internal
::
check_format_string
<
Args
...
>
(
format_str
);
return
vformat
(
format_str
.
data
(),
make_format_args
(
args
...));
}
template
<
typename
String
,
typename
...
Args
>
inline
typename
std
::
enable_if
<
internal
::
is_
format
_string
<
String
>::
value
>::
type
inline
typename
std
::
enable_if
<
internal
::
is_
compile
_string
<
String
>::
value
>::
type
print
(
String
format_str
,
const
Args
&
...
args
)
{
internal
::
check_format_string
<
Args
...
>
(
format_str
);
return
vprint
(
format_str
.
data
(),
make_format_args
(
args
...));
...
...
@@ -3979,7 +3980,7 @@ FMT_END_NAMESPACE
#define FMT_STRING(s) [] { \
typedef typename std::decay<decltype(s)>::type pointer; \
struct S : fmt::
format
_string { \
struct S : fmt::
compile
_string { \
static FMT_CONSTEXPR pointer data() { return s; } \
static FMT_CONSTEXPR size_t size() { return sizeof(s); } \
}; \
...
...
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