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
ec665108
Commit
ec665108
authored
Jun 02, 2019
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove old is_constructible workarounds and replace typedefs with using
parent
4d4b8c23
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
57 additions
and
86 deletions
+57
-86
include/fmt/core.h
include/fmt/core.h
+45
-69
include/fmt/printf.h
include/fmt/printf.h
+3
-6
test/core-test.cc
test/core-test.cc
+9
-11
No files found.
include/fmt/core.h
View file @
ec665108
...
@@ -204,6 +204,10 @@ FMT_BEGIN_NAMESPACE
...
@@ -204,6 +204,10 @@ FMT_BEGIN_NAMESPACE
template
<
bool
B
,
class
T
=
void
>
template
<
bool
B
,
class
T
=
void
>
using
enable_if_t
=
typename
std
::
enable_if
<
B
,
T
>::
type
;
using
enable_if_t
=
typename
std
::
enable_if
<
B
,
T
>::
type
;
// An enable_if helper to be used in template parameters which results in much
// shorter symbols: https://godbolt.org/z/sWw4vP.
#define FMT_ENABLE_IF(...) enable_if_t<__VA_ARGS__, int> = 0
namespace
internal
{
namespace
internal
{
#if defined(FMT_USE_STRING_VIEW)
#if defined(FMT_USE_STRING_VIEW)
...
@@ -215,10 +219,6 @@ using std_string_view = std::experimental::basic_string_view<Char>;
...
@@ -215,10 +219,6 @@ using std_string_view = std::experimental::basic_string_view<Char>;
template
<
typename
T
>
struct
std_string_view
{};
template
<
typename
T
>
struct
std_string_view
{};
#endif
#endif
// An enable_if helper to be used in template parameters which results in much
// shorter symbols: https://godbolt.org/z/sWw4vP.
#define FMT_ENABLE_IF(...) enable_if_t<__VA_ARGS__, int> = 0
#if (__cplusplus >= 201703L || \
#if (__cplusplus >= 201703L || \
(defined(_MSVC_LANG) && _MSVC_LANG >= 201703L)) && \
(defined(_MSVC_LANG) && _MSVC_LANG >= 201703L)) && \
__cpp_lib_is_invocable >= 201703L
__cpp_lib_is_invocable >= 201703L
...
@@ -266,8 +266,8 @@ template <typename T> class buffer {
...
@@ -266,8 +266,8 @@ template <typename T> class buffer {
virtual
void
grow
(
std
::
size_t
capacity
)
=
0
;
virtual
void
grow
(
std
::
size_t
capacity
)
=
0
;
public:
public:
typedef
T
value_type
;
using
value_type
=
T
;
typedef
const
T
&
const_reference
;
using
const_reference
=
const
T
&
;
virtual
~
buffer
()
{}
virtual
~
buffer
()
{}
...
@@ -334,7 +334,7 @@ class container_buffer : public buffer<typename Container::value_type> {
...
@@ -334,7 +334,7 @@ class container_buffer : public buffer<typename Container::value_type> {
// Extracts a reference to the container from back_insert_iterator.
// Extracts a reference to the container from back_insert_iterator.
template
<
typename
Container
>
template
<
typename
Container
>
inline
Container
&
get_container
(
std
::
back_insert_iterator
<
Container
>
it
)
{
inline
Container
&
get_container
(
std
::
back_insert_iterator
<
Container
>
it
)
{
typedef
std
::
back_insert_iterator
<
Container
>
bi_iterator
;
using
bi_iterator
=
std
::
back_insert_iterator
<
Container
>
;
struct
accessor
:
bi_iterator
{
struct
accessor
:
bi_iterator
{
accessor
(
bi_iterator
iter
)
:
bi_iterator
(
iter
)
{}
accessor
(
bi_iterator
iter
)
:
bi_iterator
(
iter
)
{}
using
bi_iterator
::
container
;
using
bi_iterator
::
container
;
...
@@ -349,23 +349,6 @@ struct error_handler {
...
@@ -349,23 +349,6 @@ struct error_handler {
// This function is intentionally not constexpr to give a compile-time error.
// This function is intentionally not constexpr to give a compile-time error.
FMT_API
FMT_NORETURN
void
on_error
(
const
char
*
message
);
FMT_API
FMT_NORETURN
void
on_error
(
const
char
*
message
);
};
};
// GCC 4.6.x cannot expand `T...`.
#if FMT_GCC_VERSION && FMT_GCC_VERSION < 407
typedef
char
yes
[
1
];
typedef
char
no
[
2
];
template
<
typename
T
,
typename
V
>
struct
is_constructible
{
template
<
typename
U
>
static
yes
&
test
(
int
(
*
)[
sizeof
(
new
U
(
std
::
declval
<
V
>
()))]);
template
<
typename
U
>
static
no
&
test
(...);
enum
{
value
=
sizeof
(
test
<
T
>
(
nullptr
))
==
sizeof
(
yes
)
};
};
#else
template
<
typename
...
T
>
struct
is_constructible
:
std
::
is_constructible
<
T
...
>
{};
#endif
struct
dummy_formatter_arg
{};
// Workaround broken is_constructible in MSVC.
}
// namespace internal
}
// namespace internal
/**
/**
...
@@ -381,8 +364,8 @@ template <typename Char> class basic_string_view {
...
@@ -381,8 +364,8 @@ template <typename Char> class basic_string_view {
size_t
size_
;
size_t
size_
;
public:
public:
typedef
Char
char_type
;
using
char_type
=
Char
;
typedef
const
Char
*
iterator
;
using
iterator
=
const
Char
*
;
FMT_CONSTEXPR
basic_string_view
()
FMT_NOEXCEPT
:
data_
(
nullptr
),
size_
(
0
)
{}
FMT_CONSTEXPR
basic_string_view
()
FMT_NOEXCEPT
:
data_
(
nullptr
),
size_
(
0
)
{}
...
@@ -455,8 +438,8 @@ template <typename Char> class basic_string_view {
...
@@ -455,8 +438,8 @@ template <typename Char> class basic_string_view {
}
}
};
};
typedef
basic_string_view
<
char
>
string_view
;
using
string_view
=
basic_string_view
<
char
>
;
typedef
basic_string_view
<
wchar_t
>
wstring_view
;
using
wstring_view
=
basic_string_view
<
wchar_t
>
;
/**
/**
\rst
\rst
...
@@ -525,8 +508,8 @@ class basic_parse_context : private ErrorHandler {
...
@@ -525,8 +508,8 @@ class basic_parse_context : private ErrorHandler {
int
next_arg_id_
;
int
next_arg_id_
;
public:
public:
typedef
Char
char_type
;
using
char_type
=
Char
;
typedef
typename
basic_string_view
<
Char
>::
iterator
iterator
;
using
iterator
=
typename
basic_string_view
<
Char
>::
iterator
;
explicit
FMT_CONSTEXPR
basic_parse_context
(
basic_string_view
<
Char
>
format_str
,
explicit
FMT_CONSTEXPR
basic_parse_context
(
basic_string_view
<
Char
>
format_str
,
ErrorHandler
eh
=
ErrorHandler
())
ErrorHandler
eh
=
ErrorHandler
())
...
@@ -567,11 +550,11 @@ class basic_parse_context : private ErrorHandler {
...
@@ -567,11 +550,11 @@ class basic_parse_context : private ErrorHandler {
FMT_CONSTEXPR
ErrorHandler
error_handler
()
const
{
return
*
this
;
}
FMT_CONSTEXPR
ErrorHandler
error_handler
()
const
{
return
*
this
;
}
};
};
typedef
basic_parse_context
<
char
>
format_parse_context
;
using
format_parse_context
=
basic_parse_context
<
char
>
;
typedef
basic_parse_context
<
wchar_t
>
wformat_parse_context
;
using
wformat_parse_context
=
basic_parse_context
<
wchar_t
>
;
FMT_DEPRECATED
typedef
basic_parse_context
<
char
>
parse_context
;
using
parse_context
FMT_DEPRECATED
=
basic_parse_context
<
char
>
;
FMT_DEPRECATED
typedef
basic_parse_context
<
wchar_t
>
wparse_context
;
using
wparse_context
FMT_DEPRECATED
=
basic_parse_context
<
wchar_t
>
;
template
<
typename
Context
>
class
basic_format_arg
;
template
<
typename
Context
>
class
basic_format_arg
;
template
<
typename
Context
>
class
basic_format_args
;
template
<
typename
Context
>
class
basic_format_args
;
...
@@ -579,7 +562,7 @@ template <typename Context> class basic_format_args;
...
@@ -579,7 +562,7 @@ template <typename Context> class basic_format_args;
// A formatter for objects of type T.
// A formatter for objects of type T.
template
<
typename
T
,
typename
Char
=
char
,
typename
Enable
=
void
>
template
<
typename
T
,
typename
Char
=
char
,
typename
Enable
=
void
>
struct
formatter
{
struct
formatter
{
explicit
formatter
(
internal
::
dummy_formatter_arg
)
;
formatter
()
=
delete
;
};
};
template
<
typename
T
,
typename
Char
,
typename
Enable
=
void
>
template
<
typename
T
,
typename
Char
,
typename
Enable
=
void
>
...
@@ -669,18 +652,14 @@ template <typename Context> struct custom_value {
...
@@ -669,18 +652,14 @@ template <typename Context> struct custom_value {
Context
&
ctx
);
Context
&
ctx
);
};
};
template
<
typename
T
,
typename
Context
>
struct
is_formattable
{
template
<
typename
T
,
typename
Context
>
enum
{
using
is_formattable
=
value
=
std
::
is_constructible
<
typename
Context
::
template
formatter_type
<
T
>
>
;
!
is_constructible
<
typename
Context
::
template
formatter_type
<
T
>
::
type
,
internal
::
dummy_formatter_arg
>::
value
};
};
// A formatting argument value.
// A formatting argument value.
template
<
typename
Context
>
class
value
{
template
<
typename
Context
>
class
value
{
public:
public:
typedef
typename
Context
::
char_type
char_type
;
using
char_type
=
typename
Context
::
char_type
;
union
{
union
{
int
int_value
;
int
int_value
;
...
@@ -727,7 +706,7 @@ template <typename Context> class value {
...
@@ -727,7 +706,7 @@ template <typename Context> class value {
custom
.
format
=
&
format_custom_arg
<
custom
.
format
=
&
format_custom_arg
<
T
,
typename
std
::
conditional
<
T
,
typename
std
::
conditional
<
is_formattable
<
T
,
Context
>::
value
,
is_formattable
<
T
,
Context
>::
value
,
typename
Context
::
template
formatter_type
<
T
>
::
type
,
typename
Context
::
template
formatter_type
<
T
>,
internal
::
fallback_formatter
<
T
,
char_type
>>::
type
>
;
internal
::
fallback_formatter
<
T
,
char_type
>>::
type
>
;
}
}
...
@@ -779,12 +758,12 @@ FMT_MAKE_VALUE_SAME(uint_type, unsigned)
...
@@ -779,12 +758,12 @@ FMT_MAKE_VALUE_SAME(uint_type, unsigned)
// To minimize the number of types we need to deal with, long is translated
// To minimize the number of types we need to deal with, long is translated
// either to int or to long long depending on its size.
// either to int or to long long depending on its size.
typedef
std
::
conditional
<
sizeof
(
long
)
==
sizeof
(
int
),
int
,
long
long
>::
type
using
long_type
=
long_
type
;
std
::
conditional
<
sizeof
(
long
)
==
sizeof
(
int
),
int
,
long
long
>::
type
;
FMT_MAKE_VALUE
((
sizeof
(
long
)
==
sizeof
(
int
)
?
int_type
:
long_long_type
),
long
,
FMT_MAKE_VALUE
((
sizeof
(
long
)
==
sizeof
(
int
)
?
int_type
:
long_long_type
),
long
,
long_type
)
long_type
)
typedef
std
::
conditional
<
sizeof
(
unsigned
long
)
==
sizeof
(
unsigned
),
unsigned
,
using
ulong_type
=
std
::
conditional
<
sizeof
(
unsigned
long
)
==
sizeof
(
unsigned
)
,
unsigned
long
long
>::
type
ulong_
type
;
unsigned
,
unsigned
long
long
>::
type
;
FMT_MAKE_VALUE
((
sizeof
(
unsigned
long
)
==
sizeof
(
unsigned
)
?
uint_type
FMT_MAKE_VALUE
((
sizeof
(
unsigned
long
)
==
sizeof
(
unsigned
)
?
uint_type
:
ulong_long_type
),
:
ulong_long_type
),
unsigned
long
,
ulong_type
)
unsigned
long
,
ulong_type
)
...
@@ -849,9 +828,10 @@ inline init<C, int, int_type> make_value(const T& val) {
...
@@ -849,9 +828,10 @@ inline init<C, int, int_type> make_value(const T& val) {
return
static_cast
<
int
>
(
val
);
return
static_cast
<
int
>
(
val
);
}
}
template
<
typename
C
,
typename
T
,
typename
Char
=
typename
C
::
char_type
,
template
<
FMT_ENABLE_IF
(
is_constructible
<
basic_string_view
<
Char
>,
T
>::
value
&&
typename
C
,
typename
T
,
typename
Char
=
typename
C
::
char_type
,
!
internal
::
is_string
<
T
>::
value
)
>
FMT_ENABLE_IF
(
std
::
is_constructible
<
basic_string_view
<
Char
>,
T
>::
value
&&
!
internal
::
is_string
<
T
>::
value
)
>
inline
init
<
C
,
basic_string_view
<
Char
>
,
string_type
>
make_value
(
const
T
&
val
)
{
inline
init
<
C
,
basic_string_view
<
Char
>
,
string_type
>
make_value
(
const
T
&
val
)
{
return
basic_string_view
<
Char
>
(
val
);
return
basic_string_view
<
Char
>
(
val
);
}
}
...
@@ -864,7 +844,7 @@ template <
...
@@ -864,7 +844,7 @@ template <
FMT_ENABLE_IF
(
!
convert_to_int
<
U
,
Char
>::
value
&&
FMT_ENABLE_IF
(
!
convert_to_int
<
U
,
Char
>::
value
&&
!
std
::
is_same
<
U
,
Char
>::
value
&&
!
std
::
is_same
<
U
,
Char
>::
value
&&
!
std
::
is_convertible
<
U
,
basic_string_view
<
Char
>>::
value
&&
!
std
::
is_convertible
<
U
,
basic_string_view
<
Char
>>::
value
&&
!
is_constructible
<
basic_string_view
<
Char
>
,
U
>::
value
&&
!
std
::
is_constructible
<
basic_string_view
<
Char
>
,
U
>::
value
&&
!
internal
::
is_string
<
U
>::
value
)
>
!
internal
::
is_string
<
U
>::
value
)
>
inline
init
<
C
,
const
T
&
,
custom_type
>
make_value
(
const
T
&
val
)
{
inline
init
<
C
,
const
T
&
,
custom_type
>
make_value
(
const
T
&
val
)
{
return
val
;
return
val
;
...
@@ -913,7 +893,7 @@ template <typename Context> class basic_format_arg {
...
@@ -913,7 +893,7 @@ template <typename Context> class basic_format_arg {
friend
class
basic_format_args
<
Context
>
;
friend
class
basic_format_args
<
Context
>
;
friend
class
internal
::
arg_map
<
Context
>
;
friend
class
internal
::
arg_map
<
Context
>
;
typedef
typename
Context
::
char_type
char_type
;
using
char_type
=
typename
Context
::
char_type
;
public:
public:
class
handle
{
class
handle
{
...
@@ -952,7 +932,7 @@ struct monostate {};
...
@@ -952,7 +932,7 @@ struct monostate {};
template
<
typename
Visitor
,
typename
Context
>
template
<
typename
Visitor
,
typename
Context
>
FMT_CONSTEXPR
internal
::
invoke_result_t
<
Visitor
,
int
>
visit_format_arg
(
FMT_CONSTEXPR
internal
::
invoke_result_t
<
Visitor
,
int
>
visit_format_arg
(
Visitor
&&
vis
,
const
basic_format_arg
<
Context
>&
arg
)
{
Visitor
&&
vis
,
const
basic_format_arg
<
Context
>&
arg
)
{
typedef
typename
Context
::
char_type
char_type
;
using
char_type
=
typename
Context
::
char_type
;
switch
(
arg
.
type_
)
{
switch
(
arg
.
type_
)
{
case
internal
:
:
none_type
:
case
internal
:
:
none_type
:
break
;
break
;
...
@@ -1001,7 +981,7 @@ template <typename Context> class arg_map {
...
@@ -1001,7 +981,7 @@ template <typename Context> class arg_map {
arg_map
(
const
arg_map
&
)
=
delete
;
arg_map
(
const
arg_map
&
)
=
delete
;
void
operator
=
(
const
arg_map
&
)
=
delete
;
void
operator
=
(
const
arg_map
&
)
=
delete
;
typedef
typename
Context
::
char_type
char_type
;
using
char_type
=
typename
Context
::
char_type
;
struct
entry
{
struct
entry
{
basic_string_view
<
char_type
>
name
;
basic_string_view
<
char_type
>
name
;
...
@@ -1084,7 +1064,7 @@ inline basic_format_arg<Context> make_arg(const T& value) {
...
@@ -1084,7 +1064,7 @@ inline basic_format_arg<Context> make_arg(const T& value) {
template
<
typename
OutputIt
,
typename
Char
>
class
basic_format_context
{
template
<
typename
OutputIt
,
typename
Char
>
class
basic_format_context
{
public:
public:
/** The character type for the output. */
/** The character type for the output. */
typedef
Char
char_type
;
using
char_type
=
Char
;
private:
private:
OutputIt
out_
;
OutputIt
out_
;
...
@@ -1096,13 +1076,9 @@ template <typename OutputIt, typename Char> class basic_format_context {
...
@@ -1096,13 +1076,9 @@ template <typename OutputIt, typename Char> class basic_format_context {
void
operator
=
(
const
basic_format_context
&
)
=
delete
;
void
operator
=
(
const
basic_format_context
&
)
=
delete
;
public:
public:
typedef
OutputIt
iterator
;
using
iterator
=
OutputIt
;
typedef
basic_format_arg
<
basic_format_context
>
format_arg
;
using
format_arg
=
basic_format_arg
<
basic_format_context
>
;
template
<
typename
T
>
using
formatter_type
=
formatter
<
T
,
char_type
>
;
// using formatter_type = formatter<T, char_type>;
template
<
typename
T
>
struct
formatter_type
{
typedef
formatter
<
T
,
char_type
>
type
;
};
/**
/**
Constructs a ``basic_format_context`` object. References to the arguments are
Constructs a ``basic_format_context`` object. References to the arguments are
...
@@ -1137,8 +1113,8 @@ template <typename Char> struct buffer_context {
...
@@ -1137,8 +1113,8 @@ template <typename Char> struct buffer_context {
std
::
back_insert_iterator
<
internal
::
buffer
<
Char
>>
,
Char
>
std
::
back_insert_iterator
<
internal
::
buffer
<
Char
>>
,
Char
>
type
;
type
;
};
};
typedef
buffer_context
<
char
>::
type
format_context
;
using
format_context
=
buffer_context
<
char
>::
type
;
typedef
buffer_context
<
wchar_t
>::
type
wformat_context
;
using
wformat_context
=
buffer_context
<
wchar_t
>::
type
;
/**
/**
\rst
\rst
...
@@ -1154,8 +1130,8 @@ template <typename Context, typename... Args> class format_arg_store {
...
@@ -1154,8 +1130,8 @@ template <typename Context, typename... Args> class format_arg_store {
// Packed is a macro on MinGW so use IS_PACKED instead.
// Packed is a macro on MinGW so use IS_PACKED instead.
static
const
bool
IS_PACKED
=
NUM_ARGS
<
internal
::
max_packed_args
;
static
const
bool
IS_PACKED
=
NUM_ARGS
<
internal
::
max_packed_args
;
typedef
typename
std
::
conditional
<
IS_PACKED
,
internal
::
value
<
Context
>
,
using
value_type
=
typename
std
::
conditional
<
IS_PACKED
,
internal
::
value
<
Context
>
,
basic_format_arg
<
Context
>>::
type
value_type
;
basic_format_arg
<
Context
>>::
type
;
// If the arguments are not packed, add one more element to mark the end.
// If the arguments are not packed, add one more element to mark the end.
static
const
size_t
DATA_SIZE
=
static
const
size_t
DATA_SIZE
=
...
@@ -1213,8 +1189,8 @@ inline format_arg_store<Context, Args...> make_format_args(
...
@@ -1213,8 +1189,8 @@ inline format_arg_store<Context, Args...> make_format_args(
/** Formatting arguments. */
/** Formatting arguments. */
template
<
typename
Context
>
class
basic_format_args
{
template
<
typename
Context
>
class
basic_format_args
{
public:
public:
typedef
unsigned
size_type
;
using
size_type
=
unsigned
;
typedef
basic_format_arg
<
Context
>
format_arg
;
using
format_arg
=
basic_format_arg
<
Context
>
;
private:
private:
// To reduce compiled code size per formatting function call, types of first
// To reduce compiled code size per formatting function call, types of first
...
...
include/fmt/printf.h
View file @
ec665108
...
@@ -329,12 +329,9 @@ template <typename T> struct printf_formatter {
...
@@ -329,12 +329,9 @@ template <typename T> struct printf_formatter {
template
<
typename
OutputIt
,
typename
Char
>
class
basic_printf_context
{
template
<
typename
OutputIt
,
typename
Char
>
class
basic_printf_context
{
public:
public:
/** The character type for the output. */
/** The character type for the output. */
typedef
Char
char_type
;
using
char_type
=
Char
;
typedef
basic_format_arg
<
basic_printf_context
>
format_arg
;
using
format_arg
=
basic_format_arg
<
basic_printf_context
>
;
template
<
typename
T
>
using
formatter_type
=
printf_formatter
<
T
>
;
template
<
typename
T
>
struct
formatter_type
{
typedef
printf_formatter
<
T
>
type
;
};
private:
private:
typedef
basic_format_specs
<
char_type
>
format_specs
;
typedef
basic_format_specs
<
char_type
>
format_specs
;
...
...
test/core-test.cc
View file @
ec665108
...
@@ -209,17 +209,15 @@ struct custom_context {
...
@@ -209,17 +209,15 @@ struct custom_context {
typedef
char
char_type
;
typedef
char
char_type
;
template
<
typename
T
>
struct
formatter_type
{
template
<
typename
T
>
struct
formatter_type
{
struct
type
{
template
<
typename
ParseContext
>
template
<
typename
ParseContext
>
auto
parse
(
ParseContext
&
ctx
)
->
decltype
(
ctx
.
begin
())
{
auto
parse
(
ParseContext
&
ctx
)
->
decltype
(
ctx
.
begin
())
{
return
ctx
.
begin
();
return
ctx
.
begin
();
}
}
const
char
*
format
(
const
T
&
,
custom_context
&
ctx
)
{
const
char
*
format
(
const
T
&
,
custom_context
&
ctx
)
{
ctx
.
called
=
true
;
ctx
.
called
=
true
;
return
nullptr
;
return
nullptr
;
}
}
};
};
};
bool
called
;
bool
called
;
...
...
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