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
918bb1ce
Commit
918bb1ce
authored
Sep 08, 2018
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Optimize argument capture
parent
a3ba6b4f
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
13 deletions
+13
-13
include/fmt/core.h
include/fmt/core.h
+13
-13
No files found.
include/fmt/core.h
View file @
918bb1ce
...
...
@@ -576,12 +576,14 @@ class value {
}
};
template
<
typename
Context
,
type
TYPE
>
struct
typed_value
:
value
<
Context
>
{
// Value initializer used to delay conversion to value and reduce memory churn.
template
<
typename
Context
,
typename
T
,
type
TYPE
>
struct
init
{
T
val
;
static
const
type
type_tag
=
TYPE
;
template
<
typename
T
>
FMT_CONSTEXPR
typed_value
(
const
T
&
val
)
:
value
<
Context
>
(
val
)
{
}
FMT_CONSTEXPR
init
(
const
T
&
v
)
:
val
(
v
)
{}
FMT_CONSTEXPR
operator
value
<
Context
>
()
const
{
return
value
<
Context
>
(
val
);
}
};
template
<
typename
Context
,
typename
T
>
...
...
@@ -589,15 +591,13 @@ FMT_CONSTEXPR basic_format_arg<Context> make_arg(const T &value);
#define FMT_MAKE_VALUE(TAG, ArgType, ValueType) \
template <typename C> \
FMT_CONSTEXPR
typed_value<C
, TAG> make_value(ArgType val) { \
FMT_CONSTEXPR
init<C, ValueType
, TAG> make_value(ArgType val) { \
return static_cast<ValueType>(val); \
}
#define FMT_MAKE_VALUE_SAME(TAG, Type) \
template <typename C> \
FMT_CONSTEXPR typed_value<C, TAG> make_value(Type val) { \
return val; \
}
FMT_CONSTEXPR init<C, Type, TAG> make_value(Type val) { return val; }
FMT_MAKE_VALUE
(
bool_type
,
bool
,
int
)
FMT_MAKE_VALUE
(
int_type
,
short
,
int
)
...
...
@@ -625,7 +625,7 @@ FMT_MAKE_VALUE(char_type, char, int)
#if !defined(_MSC_VER) || defined(_NATIVE_WCHAR_T_DEFINED)
template
<
typename
C
>
inline
typed_value
<
C
,
char_type
>
make_value
(
wchar_t
val
)
{
inline
init
<
C
,
int
,
char_type
>
make_value
(
wchar_t
val
)
{
require_wchar
<
typename
C
::
char_type
>
();
return
static_cast
<
int
>
(
val
);
}
...
...
@@ -672,13 +672,13 @@ typename std::enable_if<!std::is_same<T, typename C::char_type>::value>::type
template
<
typename
C
,
typename
T
>
inline
typename
std
::
enable_if
<
std
::
is_enum
<
T
>::
value
&&
convert_to_int
<
T
,
typename
C
::
char_type
>::
value
,
typed_value
<
C
,
int_type
>>::
type
init
<
C
,
int
,
int_type
>>::
type
make_value
(
const
T
&
val
)
{
return
static_cast
<
int
>
(
val
);
}
template
<
typename
C
,
typename
T
,
typename
Char
=
typename
C
::
char_type
>
inline
typename
std
::
enable_if
<
std
::
is_constructible
<
basic_string_view
<
Char
>
,
T
>::
value
,
typed_value
<
C
,
string_type
>>::
type
init
<
C
,
basic_string_view
<
Char
>
,
string_type
>>::
type
make_value
(
const
T
&
val
)
{
return
basic_string_view
<
Char
>
(
val
);
}
template
<
typename
C
,
typename
T
,
typename
Char
=
typename
C
::
char_type
>
...
...
@@ -688,11 +688,11 @@ inline typename std::enable_if<
!
std
::
is_constructible
<
basic_string_view
<
Char
>
,
T
>::
value
,
// Implicit conversion to std::string is not handled here because it's
// unsafe: https://github.com/fmtlib/fmt/issues/729
typed_value
<
C
,
custom_type
>>::
type
init
<
C
,
const
T
&
,
custom_type
>>::
type
make_value
(
const
T
&
val
)
{
return
val
;
}
template
<
typename
C
,
typename
T
>
typed_value
<
C
,
named_arg_type
>
init
<
C
,
const
void
*
,
named_arg_type
>
make_value
(
const
named_arg
<
T
,
typename
C
::
char_type
>
&
val
)
{
basic_format_arg
<
C
>
arg
=
make_arg
<
C
>
(
val
.
value
);
std
::
memcpy
(
val
.
data
,
&
arg
,
sizeof
(
arg
));
...
...
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