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
3cf619de
Commit
3cf619de
authored
Mar 17, 2020
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify dynamic_format_arg_store
parent
2559983e
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
27 deletions
+18
-27
include/fmt/core.h
include/fmt/core.h
+18
-27
No files found.
include/fmt/core.h
View file @
3cf619de
...
...
@@ -1211,33 +1211,32 @@ template <typename T> struct is_reference_wrapper : std::false_type {};
template
<
typename
T
>
struct
is_reference_wrapper
<
std
::
reference_wrapper
<
T
>>
:
std
::
true_type
{};
class
dyn
_arg_storage
{
class
dyn
amic_arg_list
{
// Workaround for clang's -Wweak-vtables. Unlike for regular classes, for
// templates it doesn't complain about inability to deduce single translation
// unit for placing vtable. So storage_node_base is made a fake template.
template
<
typename
=
void
>
struct
storage_node_base
{
using
owning_ptr
=
std
::
unique_ptr
<
storage_node_base
<>>
;
virtual
~
storage_node_base
()
=
default
;
owning_ptr
next
;
template
<
typename
=
void
>
struct
node
{
virtual
~
node
()
=
default
;
std
::
unique_ptr
<
node
<>>
next
;
};
template
<
typename
T
>
struct
storage_node
:
storage_node_bas
e
<>
{
template
<
typename
T
>
struct
typed_node
:
nod
e
<>
{
T
value
;
template
<
typename
Arg
>
FMT_CONSTEXPR
storage
_node
(
const
Arg
&
arg
)
:
value
(
arg
)
{}
FMT_CONSTEXPR
typed
_node
(
const
Arg
&
arg
)
:
value
(
arg
)
{}
template
<
typename
Char
>
FMT_CONSTEXPR
storage
_node
(
const
basic_string_view
<
Char
>&
arg
)
FMT_CONSTEXPR
typed
_node
(
const
basic_string_view
<
Char
>&
arg
)
:
value
(
arg
.
data
(),
arg
.
size
())
{}
};
st
orage_node_base
<>::
owning_ptr
head_
;
st
d
::
unique_ptr
<
node
<>>
head_
;
public:
template
<
typename
T
,
typename
Arg
>
const
T
&
push
(
const
Arg
&
arg
)
{
auto
next
=
std
::
move
(
head_
);
auto
node
=
new
storage
_node
<
T
>
(
arg
);
auto
node
=
new
typed
_node
<
T
>
(
arg
);
head_
.
reset
(
node
);
head_
->
next
=
std
::
move
(
next
);
return
node
->
value
;
...
...
@@ -1372,18 +1371,19 @@ class dynamic_format_arg_store
private:
using
char_type
=
typename
Context
::
char_type
;
template
<
typename
T
>
struct
need_
dyn_
copy
{
template
<
typename
T
>
struct
need_copy
{
static
constexpr
internal
::
type
mapped_type
=
internal
::
mapped_type_constant
<
T
,
Context
>::
value
;
using
type
=
std
::
integral_constant
<
bool
,
!
(
internal
::
is_reference_wrapper
<
T
>::
value
||
enum
{
value
=
!
(
internal
::
is_reference_wrapper
<
T
>::
value
||
std
::
is_same
<
T
,
basic_string_view
<
char_type
>>::
value
||
std
::
is_same
<
T
,
internal
::
std_string_view
<
char_type
>>::
value
||
(
mapped_type
!=
internal
::
type
::
cstring_type
&&
mapped_type
!=
internal
::
type
::
string_type
&&
mapped_type
!=
internal
::
type
::
custom_type
&&
mapped_type
!=
internal
::
type
::
named_arg_type
))
>
;
mapped_type
!=
internal
::
type
::
named_arg_type
))
};
};
template
<
typename
T
>
...
...
@@ -1395,7 +1395,7 @@ class dynamic_format_arg_store
// Storage of arguments not fitting into basic_format_arg must grow
// without relocation because items in data_ refer to it.
internal
::
dyn
_arg_storage
storage
_
;
internal
::
dyn
amic_arg_list
dynamic_args
_
;
friend
class
basic_format_args
<
Context
>
;
...
...
@@ -1408,15 +1408,6 @@ class dynamic_format_arg_store
}
public:
dynamic_format_arg_store
()
=
default
;
~
dynamic_format_arg_store
()
=
default
;
dynamic_format_arg_store
(
const
dynamic_format_arg_store
&
)
=
delete
;
dynamic_format_arg_store
&
operator
=
(
const
dynamic_format_arg_store
&
)
=
delete
;
dynamic_format_arg_store
(
dynamic_format_arg_store
&&
)
=
default
;
dynamic_format_arg_store
&
operator
=
(
dynamic_format_arg_store
&&
)
=
default
;
/**
\rst
Adds an argument into the dynamic store for later passing to a formating
...
...
@@ -1438,8 +1429,8 @@ class dynamic_format_arg_store
static_assert
(
!
std
::
is_base_of
<
internal
::
named_arg_base
<
char_type
>
,
T
>::
value
,
"named arguments are not supported yet"
);
if
(
internal
::
const_check
(
need_
dyn_copy
<
T
>::
type
::
value
))
emplace_arg
(
storage
_
.
push
<
stored_type
<
T
>>
(
arg
));
if
(
internal
::
const_check
(
need_
copy
<
T
>
::
value
))
emplace_arg
(
dynamic_args
_
.
push
<
stored_type
<
T
>>
(
arg
));
else
emplace_arg
(
arg
);
}
...
...
@@ -1450,7 +1441,7 @@ class dynamic_format_arg_store
*/
template
<
typename
T
>
void
push_back
(
std
::
reference_wrapper
<
T
>
arg
)
{
static_assert
(
need_
dyn_copy
<
T
>::
type
::
value
,
need_
copy
<
T
>
::
value
,
"objects of built-in types and string views are always copied"
);
emplace_arg
(
arg
.
get
());
}
...
...
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