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
3730b4f0
Commit
3730b4f0
authored
Jul 25, 2019
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleanup compile implementation
parent
25ff2efc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
58 deletions
+29
-58
include/fmt/compile.h
include/fmt/compile.h
+26
-55
test/compile-test.cc
test/compile-test.cc
+3
-3
No files found.
include/fmt/compile.h
View file @
3730b4f0
...
...
@@ -8,14 +8,8 @@
#ifndef FMT_COMPILE_H_
#define FMT_COMPILE_H_
#ifndef FMT_HAS_CONSTRUCTIBLE_TRAITS
# define FMT_HAS_CONSTRUCTIBLE_TRAITS \
(FMT_GCC_VERSION >= 407 || FMT_CLANG_VERSION || FMT_MSC_VER)
#endif
#include "format.h"
#include <vector>
#include "format.h"
FMT_BEGIN_NAMESPACE
...
...
@@ -506,12 +500,10 @@ struct compiletime_parts_provider {
template
<
typename
PartsContainer
>
struct
parts_container_concept_check
:
std
::
true_type
{
#if FMT_HAS_CONSTRUCTIBLE_TRAITS
static_assert
(
std
::
is_copy_constructible
<
PartsContainer
>::
value
,
"PartsContainer is not copy constructible"
);
static_assert
(
std
::
is_move_constructible
<
PartsContainer
>::
value
,
"PartsContainer is not move constructible"
);
#endif
template
<
typename
T
,
typename
=
void
>
struct
has_format_part_type
:
std
::
false_type
{};
...
...
@@ -669,98 +661,77 @@ template <typename Format> struct format_tag {
#if FMT_USE_CONSTEXPR
template
<
typename
Format
,
typename
...
Args
>
auto
do_
prepar
e
(
runtime_format_tag
,
Format
format
)
{
auto
do_
compil
e
(
runtime_format_tag
,
Format
format
)
{
return
preparator
<
Format
,
Args
...
>::
prepare
(
std
::
move
(
format
));
}
template
<
typename
Format
,
typename
...
Args
>
FMT_CONSTEXPR
auto
do_
prepar
e
(
compiletime_format_tag
,
const
Format
&
format
)
{
FMT_CONSTEXPR
auto
do_
compil
e
(
compiletime_format_tag
,
const
Format
&
format
)
{
return
typename
basic_prepared_format
<
Format
,
void
,
Args
...
>::
type
(
format
);
}
#else
template
<
typename
Format
,
typename
...
Args
>
auto
do_
prepar
e
(
const
Format
&
format
)
auto
do_
compil
e
(
const
Format
&
format
)
->
decltype
(
preparator
<
Format
,
Args
...
>::
prepare
(
format
))
{
return
preparator
<
Format
,
Args
...
>::
prepare
(
format
);
}
#endif
}
// namespace internal
template
<
typename
Char
,
typename
Container
=
std
::
vector
<
format_part
<
Char
>
>>
struct
parts_container
{
typedef
internal
::
parts_container
<
Char
,
Container
>
type
;
};
template
<
typename
Format
,
typename
PartsContainer
,
typename
...
Args
>
struct
basic_prepared_format
{
typedef
typename
internal
::
basic_prepared_format
<
Format
,
PartsContainer
,
Args
...
>::
type
type
;
};
template
<
typename
...
Args
>
struct
prepared_format
{
typedef
typename
basic_prepared_format
<
std
::
string
,
typename
parts_container
<
char
>::
type
,
Args
...
>::
type
type
;
typedef
typename
internal
::
basic_prepared_format
<
std
::
string
,
internal
::
parts_container
<
char
>
,
Args
...
>::
type
type
;
};
template
<
typename
...
Args
>
struct
wprepared_format
{
typedef
typename
basic_prepared_format
<
std
::
wstring
,
typename
parts_container
<
wchar_t
>::
type
,
Args
...
>::
type
type
;
typedef
typename
internal
::
basic_prepared_format
<
std
::
wstring
,
internal
::
parts_container
<
wchar_t
>
,
Args
...
>::
type
type
;
};
template
<
typename
Char
,
typename
Container
=
std
::
vector
<
format_part
<
Char
>
>>
using
parts_container_t
=
typename
parts_container
<
Char
,
Container
>::
type
;
template
<
typename
Format
,
typename
PreparedPartsContainer
,
typename
...
Args
>
using
basic_prepared_format_t
=
typename
basic_prepared_format
<
Format
,
PreparedPartsContainer
,
Args
...
>::
type
;
template
<
typename
...
Args
>
using
prepared_format_t
=
basic_prepared_format_t
<
std
::
string
,
parts_container
<
char
>
,
Args
...
>
;
using
prepared_format_t
=
typename
internal
::
basic_prepared_format
<
std
::
string
,
internal
::
parts_container
<
char
>
,
Args
...
>::
type
;
template
<
typename
...
Args
>
using
wprepared_format_t
=
basic_prepared_format_t
<
std
::
wstring
,
parts_container
<
wchar_t
>
,
Args
...
>
;
using
wprepared_format_t
=
typename
internal
::
basic_prepared_format
<
std
::
wstring
,
internal
::
parts_container
<
wchar_t
>
,
Args
...
>::
type
;
#if FMT_USE_CONSTEXPR
template
<
typename
...
Args
,
typename
Format
>
FMT_CONSTEXPR
auto
compile
(
Format
format
)
{
return
internal
::
do_
prepare
<
Format
,
Args
...
>
(
typename
internal
::
format_tag
<
Format
>::
type
{},
std
::
move
(
format
));
template
<
typename
...
Args
,
typename
S
>
FMT_CONSTEXPR
auto
compile
(
S
format_str
)
{
return
internal
::
do_
compile
<
S
,
Args
...
>
(
typename
internal
::
format_tag
<
S
>::
type
{},
std
::
move
(
format_str
));
}
#else
template
<
typename
...
Args
,
typename
Format
>
auto
compile
(
Format
format
)
->
typename
internal
::
preparator
<
Format
,
Args
...
>::
prepared_format_type
{
return
internal
::
preparator
<
Format
,
Args
...
>::
prepare
(
std
::
move
(
format
));
template
<
typename
...
Args
,
typename
S
>
auto
compile
(
S
format_str
)
->
typename
internal
::
preparator
<
S
,
Args
...
>::
prepared_format_type
{
return
internal
::
preparator
<
S
,
Args
...
>::
prepare
(
std
::
move
(
format_str
));
}
#endif
template
<
typename
...
Args
,
typename
Char
>
auto
compile
(
const
Char
*
format
)
->
auto
compile
(
const
Char
*
format
_str
)
->
typename
internal
::
preparator
<
std
::
basic_string
<
Char
>
,
Args
...
>::
prepared_format_type
{
return
compile
<
Args
...
>
(
internal
::
to_runtime_format
(
format
));
return
compile
<
Args
...
>
(
internal
::
to_runtime_format
(
format
_str
));
}
template
<
typename
...
Args
,
typename
Char
,
unsigned
N
>
auto
compile
(
const
Char
(
format
)[
N
])
->
auto
compile
(
const
Char
(
format
_str
)[
N
])
->
typename
internal
::
preparator
<
std
::
basic_string
<
Char
>
,
Args
...
>::
prepared_format_type
{
const
auto
view
=
basic_string_view
<
Char
>
(
format
,
N
);
const
auto
view
=
basic_string_view
<
Char
>
(
format
_str
,
N
);
return
compile
<
Args
...
>
(
internal
::
to_runtime_format
(
view
));
}
template
<
typename
...
Args
,
typename
Char
>
auto
compile
(
basic_string_view
<
Char
>
format
)
->
auto
compile
(
basic_string_view
<
Char
>
format
_str
)
->
typename
internal
::
preparator
<
std
::
basic_string
<
Char
>
,
Args
...
>::
prepared_format_type
{
return
compile
<
Args
...
>
(
internal
::
to_runtime_format
(
format
));
return
compile
<
Args
...
>
(
internal
::
to_runtime_format
(
format
_str
));
}
FMT_END_NAMESPACE
...
...
test/compile-test.cc
View file @
3730b4f0
...
...
@@ -486,9 +486,9 @@ TEST(PrepareTest, ReusedPreparedFormatType) {
TEST
(
PrepareTest
,
UserProvidedPartsContainerUnderlyingContainer
)
{
typedef
fmt
::
format_part
<
char
>
format_part
;
typedef
fmt
::
parts_container
<
char
,
std
::
list
<
format_part
>>::
type
typedef
fmt
::
internal
::
parts_container
<
char
,
std
::
list
<
format_part
>>
parts_container
;
typedef
fmt
::
basic_prepared_format
<
std
::
string
,
parts_container
,
std
::
string
,
typedef
fmt
::
internal
::
basic_prepared_format
<
std
::
string
,
parts_container
,
std
::
string
,
int
>::
type
prepared_format
;
prepared_format
prepared
=
fmt
::
compile
<
prepared_format
>
(
"The {} is {}."
);
...
...
@@ -532,7 +532,7 @@ class custom_parts_container {
};
TEST
(
PrepareTest
,
UserProvidedPartsContainer
)
{
typedef
fmt
::
basic_prepared_format
<
std
::
string
,
custom_parts_container
,
typedef
fmt
::
internal
::
basic_prepared_format
<
std
::
string
,
custom_parts_container
,
std
::
string
,
int
>::
type
prepared_format
;
prepared_format
prepared
=
fmt
::
compile
<
prepared_format
>
(
"The {} is {}."
);
...
...
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