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
87fbc6f7
Commit
87fbc6f7
authored
Jun 10, 2019
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
get_type -> mapped_type_constant
parent
a48daa60
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
20 additions
and
14 deletions
+20
-14
include/fmt/core.h
include/fmt/core.h
+9
-7
include/fmt/format.h
include/fmt/format.h
+2
-1
test/core-test.cc
test/core-test.cc
+8
-5
test/format
test/format
+1
-1
No files found.
include/fmt/core.h
View file @
87fbc6f7
...
...
@@ -827,6 +827,12 @@ template <typename Context> struct arg_mapper {
}
};
// A type constant after applying arg_mapper<Context>.
template
<
typename
T
,
typename
Context
>
using
mapped_type_constant
=
type_constant
<
decltype
(
arg_mapper
<
Context
>
().
map
(
std
::
declval
<
T
>
())),
typename
Context
::
char_type
>
;
// Maximum number of arguments with packed types.
enum
{
max_packed_args
=
15
};
enum
:
unsigned
long
long
{
is_unpacked_bit
=
1ull
<<
63
};
...
...
@@ -983,22 +989,18 @@ class locale_ref {
template
<
typename
Locale
>
Locale
get
()
const
;
};
template
<
typename
Context
,
typename
T
>
using
get_type
=
type_constant
<
decltype
(
arg_mapper
<
Context
>
().
map
(
std
::
declval
<
T
>
())),
typename
Context
::
char_type
>
;
template
<
typename
>
constexpr
unsigned
long
long
get_types
()
{
return
0
;
}
template
<
typename
Context
,
typename
Arg
,
typename
...
Args
>
constexpr
unsigned
long
long
get_types
()
{
return
get_type
<
Context
,
Arg
>::
value
|
(
get_types
<
Context
,
Args
...
>
()
<<
4
);
return
mapped_type_constant
<
Arg
,
Context
>::
value
|
(
get_types
<
Context
,
Args
...
>
()
<<
4
);
}
template
<
typename
Context
,
typename
T
>
FMT_CONSTEXPR
basic_format_arg
<
Context
>
make_arg
(
const
T
&
value
)
{
basic_format_arg
<
Context
>
arg
;
arg
.
type_
=
get_type
<
Context
,
T
>::
value
;
arg
.
type_
=
mapped_type_constant
<
T
,
Context
>::
value
;
arg
.
value_
=
arg_mapper
<
Context
>
().
map
(
value
);
return
arg
;
}
...
...
include/fmt/format.h
View file @
87fbc6f7
...
...
@@ -3165,7 +3165,8 @@ template <typename Char = char> class dynamic_formatter {
auto
format
(
const
T
&
val
,
FormatContext
&
ctx
)
->
decltype
(
ctx
.
out
())
{
handle_specs
(
ctx
);
internal
::
specs_checker
<
null_handler
>
checker
(
null_handler
(),
internal
::
get_type
<
FormatContext
,
T
>::
value
);
null_handler
(),
internal
::
mapped_type_constant
<
T
,
FormatContext
>::
value
);
checker
.
on_align
(
specs_
.
align
());
if
(
specs_
.
flags
==
0
)
;
// Do nothing.
...
...
test/core-test.cc
View file @
87fbc6f7
...
...
@@ -567,15 +567,18 @@ TEST(CoreTest, ToStringViewForeignStrings) {
EXPECT_EQ
(
to_string_view
(
my_string
<
wchar_t
>
(
L"42"
)),
L"42"
);
EXPECT_EQ
(
to_string_view
(
QString
(
L"42"
)),
L"42"
);
fmt
::
internal
::
type
type
=
fmt
::
internal
::
get_type
<
fmt
::
format_context
,
my_string
<
char
>>::
value
;
fmt
::
internal
::
mapped_type_constant
<
my_string
<
char
>
,
fmt
::
format_context
>::
value
;
EXPECT_EQ
(
type
,
fmt
::
internal
::
string_type
);
type
=
fmt
::
internal
::
get_type
<
fmt
::
wformat_context
,
my_string
<
wchar_t
>
>::
value
;
type
=
fmt
::
internal
::
mapped_type_constant
<
my_string
<
wchar_t
>
,
fmt
::
wformat_context
>::
value
;
EXPECT_EQ
(
type
,
fmt
::
internal
::
string_type
);
type
=
fmt
::
internal
::
get_type
<
fmt
::
wformat_context
,
QString
>::
value
;
type
=
fmt
::
internal
::
mapped_type_constant
<
QString
,
fmt
::
wformat_context
>::
value
;
EXPECT_EQ
(
type
,
fmt
::
internal
::
string_type
);
// Does not compile: only wide format contexts are compatible with QString!
// type = fmt::internal::get_type<fmt::format_context, QString>::value;
// type = fmt::internal::mapped_type_constant<QString,
// fmt::format_context>::value;
}
TEST
(
CoreTest
,
FormatForeignStrings
)
{
...
...
test/format
View file @
87fbc6f7
...
...
@@ -643,7 +643,7 @@ struct formatter {
FMT_CONSTEXPR typename ParseContext::iterator parse(ParseContext& ctx) {
namespace internal = fmt::internal;
typedef internal::dynamic_specs_handler<ParseContext> handler_type;
auto type = internal::
get_type<fmt::buffer_context<Char>, T
>::value;
auto type = internal::
mapped_type_constant<T, fmt::buffer_context<Char>
>::value;
internal::specs_checker<handler_type> handler(handler_type(specs_, ctx),
type);
auto it = parse_format_specs(ctx.begin(), ctx.end(), handler);
...
...
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