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
ea4010d7
Commit
ea4010d7
authored
Oct 24, 2018
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Merge has_to_string_view into is_string
parent
486fff59
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
53 additions
and
68 deletions
+53
-68
include/fmt/color.h
include/fmt/color.h
+6
-8
include/fmt/core.h
include/fmt/core.h
+43
-54
include/fmt/format.h
include/fmt/format.h
+4
-6
No files found.
include/fmt/color.h
View file @
ea4010d7
...
@@ -269,9 +269,8 @@ inline void reset_color<wchar_t>(FILE *stream) FMT_NOEXCEPT {
...
@@ -269,9 +269,8 @@ inline void reset_color<wchar_t>(FILE *stream) FMT_NOEXCEPT {
}
// namespace internal
}
// namespace internal
template
<
template
<
typename
String
,
typename
S
,
typename
Char
=
typename
internal
::
char_t
<
S
>
::
type
>
typename
Char
=
typename
internal
::
has_to_string_view
<
String
>
::
char_type
>
void
vprint_rgb
(
rgb
fd
,
const
S
&
format
,
void
vprint_rgb
(
rgb
fd
,
const
String
&
format
,
basic_format_args
<
typename
buffer_context
<
Char
>::
type
>
args
)
{
basic_format_args
<
typename
buffer_context
<
Char
>::
type
>
args
)
{
internal
::
fputs
<
Char
>
(
internal
::
make_foreground_color
<
Char
>
(
fd
),
stdout
);
internal
::
fputs
<
Char
>
(
internal
::
make_foreground_color
<
Char
>
(
fd
),
stdout
);
vprint
(
format
,
args
);
vprint
(
format
,
args
);
...
@@ -279,9 +278,8 @@ void vprint_rgb(rgb fd, const String &format,
...
@@ -279,9 +278,8 @@ void vprint_rgb(rgb fd, const String &format,
}
}
template
<
template
<
typename
String
,
typename
S
,
typename
Char
=
typename
internal
::
char_t
<
S
>
::
type
>
typename
Char
=
typename
internal
::
has_to_string_view
<
String
>
::
char_type
>
void
vprint_rgb
(
rgb
fd
,
rgb
bg
,
const
S
&
format
,
void
vprint_rgb
(
rgb
fd
,
rgb
bg
,
const
String
&
format
,
basic_format_args
<
typename
buffer_context
<
Char
>::
type
>
args
)
{
basic_format_args
<
typename
buffer_context
<
Char
>::
type
>
args
)
{
internal
::
fputs
<
Char
>
(
internal
::
make_foreground_color
<
Char
>
(
fd
),
stdout
);
internal
::
fputs
<
Char
>
(
internal
::
make_foreground_color
<
Char
>
(
fd
),
stdout
);
internal
::
fputs
<
Char
>
(
internal
::
make_background_color
<
Char
>
(
bg
),
stdout
);
internal
::
fputs
<
Char
>
(
internal
::
make_background_color
<
Char
>
(
bg
),
stdout
);
...
@@ -299,7 +297,7 @@ template <typename String, typename... Args>
...
@@ -299,7 +297,7 @@ template <typename String, typename... Args>
typename
std
::
enable_if
<
internal
::
is_string
<
String
>::
value
>::
type
typename
std
::
enable_if
<
internal
::
is_string
<
String
>::
value
>::
type
print
(
rgb
fd
,
const
String
&
format_str
,
const
Args
&
...
args
)
{
print
(
rgb
fd
,
const
String
&
format_str
,
const
Args
&
...
args
)
{
internal
::
check_format_string
<
Args
...
>
(
format_str
);
internal
::
check_format_string
<
Args
...
>
(
format_str
);
typedef
typename
internal
::
has_to_string_view
<
String
>::
char_
type
char_t
;
typedef
typename
internal
::
char_t
<
String
>::
type
char_t
;
typedef
typename
buffer_context
<
char_t
>::
type
context_t
;
typedef
typename
buffer_context
<
char_t
>::
type
context_t
;
format_arg_store
<
context_t
,
Args
...
>
as
{
args
...};
format_arg_store
<
context_t
,
Args
...
>
as
{
args
...};
vprint_rgb
(
fd
,
format_str
,
basic_format_args
<
context_t
>
(
as
));
vprint_rgb
(
fd
,
format_str
,
basic_format_args
<
context_t
>
(
as
));
...
@@ -316,7 +314,7 @@ template <typename String, typename... Args>
...
@@ -316,7 +314,7 @@ template <typename String, typename... Args>
typename
std
::
enable_if
<
internal
::
is_string
<
String
>::
value
>::
type
typename
std
::
enable_if
<
internal
::
is_string
<
String
>::
value
>::
type
print
(
rgb
fd
,
rgb
bg
,
const
String
&
format_str
,
const
Args
&
...
args
)
{
print
(
rgb
fd
,
rgb
bg
,
const
String
&
format_str
,
const
Args
&
...
args
)
{
internal
::
check_format_string
<
Args
...
>
(
format_str
);
internal
::
check_format_string
<
Args
...
>
(
format_str
);
typedef
typename
internal
::
has_to_string_view
<
String
>::
char_type
char_t
;
typedef
typename
internal
::
is_string
<
String
>::
char_type
char_t
;
typedef
typename
buffer_context
<
char_t
>::
type
context_t
;
typedef
typename
buffer_context
<
char_t
>::
type
context_t
;
format_arg_store
<
context_t
,
Args
...
>
as
{
args
...};
format_arg_store
<
context_t
,
Args
...
>
as
{
args
...};
vprint_rgb
(
fd
,
bg
,
format_str
,
basic_format_args
<
context_t
>
(
as
));
vprint_rgb
(
fd
,
bg
,
format_str
,
basic_format_args
<
context_t
>
(
as
));
...
...
include/fmt/core.h
View file @
ea4010d7
...
@@ -426,6 +426,32 @@ class basic_string_view {
...
@@ -426,6 +426,32 @@ class basic_string_view {
typedef
basic_string_view
<
char
>
string_view
;
typedef
basic_string_view
<
char
>
string_view
;
typedef
basic_string_view
<
wchar_t
>
wstring_view
;
typedef
basic_string_view
<
wchar_t
>
wstring_view
;
/**
\rst
The function ``to_string_view`` adapts non-intrusively any kind of string or
string-like type if the user provides a (possibly templated) overload of
``to_string_view`` which takes an instance of the string class
``StringType<Char>`` and returns a ``fmt::basic_string_view<Char>``.
The conversion function must live in the very same namespace as
``StringType<Char>`` to be picked up by ADL. Non-templated string types
like f.e. QString must return a ``basic_string_view`` with a fixed matching
char type.
**Example**::
namespace my_ns {
inline string_view to_string_view(const my_string &s) {
return { s.data(), s.length() };
}
}
std::string message = fmt::format(my_string("The answer is {}"), 42);
\endrst
*/
template
<
typename
Char
>
inline
basic_string_view
<
Char
>
to_string_view
(
basic_string_view
<
Char
>
s
)
{
return
s
;
}
template
<
typename
Char
>
template
<
typename
Char
>
inline
basic_string_view
<
Char
>
inline
basic_string_view
<
Char
>
to_string_view
(
const
std
::
basic_string
<
Char
>
&
s
)
{
return
s
;
}
to_string_view
(
const
std
::
basic_string
<
Char
>
&
s
)
{
return
s
;
}
...
@@ -476,28 +502,20 @@ struct convert_to_int: std::integral_constant<
...
@@ -476,28 +502,20 @@ struct convert_to_int: std::integral_constant<
namespace
internal
{
namespace
internal
{
template
<
typename
S
>
struct
dummy_string_view
{
typedef
void
char_type
;
};
struct
get_char_type
{
dummy_string_view
to_string_view
(...);
typedef
void
char_type
;
};
template
<
typename
Char
>
struct
get_char_type
<
basic_string_view
<
Char
>>
{
typedef
Char
char_type
;
};
using
fmt
::
v5
::
to_string_view
;
using
fmt
::
v5
::
to_string_view
;
void
to_string_view
(...);
// Specifies whether S is a string type convertible to fmt::basic_string_view.
template
<
typename
S
>
template
<
typename
S
>
struct
has_to_string_view
{
struct
is_string
:
std
::
integral_constant
<
bool
,
!
std
::
is_same
<
typedef
typename
get_char_type
<
decltype
(
to_string_view
(
internal
::
declval
<
S
>
()))
>::
char_type
char_type
;
dummy_string_view
,
decltype
(
to_string_view
(
declval
<
S
>
()))
>::
value
>
{};
static
const
bool
value
=
!
std
::
is_same
<
void
,
decltype
(
to_string_view
(
internal
::
declval
<
S
>
()))
>::
value
;
};
template
<
typename
S
>
template
<
typename
S
>
struct
is_string
:
internal
::
has_to_string_view
<
S
>
{};
struct
char_t
{
typedef
decltype
(
to_string_view
(
declval
<
S
>
()))
result
;
typedef
typename
result
::
char_type
type
;
};
template
<
typename
Char
>
template
<
typename
Char
>
struct
named_arg_base
;
struct
named_arg_base
;
...
@@ -708,7 +726,7 @@ inline typename std::enable_if<
...
@@ -708,7 +726,7 @@ inline typename std::enable_if<
template
<
typename
C
,
typename
T
,
typename
Char
=
typename
C
::
char_type
>
template
<
typename
C
,
typename
T
,
typename
Char
=
typename
C
::
char_type
>
inline
typename
std
::
enable_if
<
inline
typename
std
::
enable_if
<
internal
::
is_constructible
<
basic_string_view
<
Char
>
,
T
>::
value
&&
internal
::
is_constructible
<
basic_string_view
<
Char
>
,
T
>::
value
&&
!
internal
::
has_to_string_view
<
T
>::
value
,
!
internal
::
is_string
<
T
>::
value
,
init
<
C
,
basic_string_view
<
Char
>
,
string_type
>>::
type
init
<
C
,
basic_string_view
<
Char
>
,
string_type
>>::
type
make_value
(
const
T
&
val
)
{
return
basic_string_view
<
Char
>
(
val
);
}
make_value
(
const
T
&
val
)
{
return
basic_string_view
<
Char
>
(
val
);
}
...
@@ -717,7 +735,7 @@ inline typename std::enable_if<
...
@@ -717,7 +735,7 @@ inline typename std::enable_if<
!
convert_to_int
<
T
,
Char
>::
value
&&
!
std
::
is_same
<
T
,
Char
>::
value
&&
!
convert_to_int
<
T
,
Char
>::
value
&&
!
std
::
is_same
<
T
,
Char
>::
value
&&
!
std
::
is_convertible
<
T
,
basic_string_view
<
Char
>>::
value
&&
!
std
::
is_convertible
<
T
,
basic_string_view
<
Char
>>::
value
&&
!
internal
::
is_constructible
<
basic_string_view
<
Char
>
,
T
>::
value
&&
!
internal
::
is_constructible
<
basic_string_view
<
Char
>
,
T
>::
value
&&
!
internal
::
has_to_string_view
<
T
>::
value
,
!
internal
::
is_string
<
T
>::
value
,
// Implicit conversion to std::string is not handled here because it's
// Implicit conversion to std::string is not handled here because it's
// unsafe: https://github.com/fmtlib/fmt/issues/729
// unsafe: https://github.com/fmtlib/fmt/issues/729
init
<
C
,
const
T
&
,
custom_type
>>::
type
init
<
C
,
const
T
&
,
custom_type
>>::
type
...
@@ -733,13 +751,12 @@ init<C, const void*, named_arg_type>
...
@@ -733,13 +751,12 @@ init<C, const void*, named_arg_type>
template
<
typename
C
,
typename
S
>
template
<
typename
C
,
typename
S
>
FMT_CONSTEXPR11
typename
std
::
enable_if
<
FMT_CONSTEXPR11
typename
std
::
enable_if
<
internal
::
has_to_string_view
<
S
>::
value
,
internal
::
is_string
<
S
>::
value
,
init
<
C
,
basic_string_view
<
typename
C
::
char_type
>
,
string_type
>>::
type
init
<
C
,
basic_string_view
<
typename
C
::
char_type
>
,
string_type
>>::
type
make_value
(
const
S
&
val
)
{
make_value
(
const
S
&
val
)
{
// Handle adapted strings.
// Handle adapted strings.
static_assert
(
std
::
is_same
<
static_assert
(
std
::
is_same
<
typename
C
::
char_type
,
typename
C
::
char_type
,
typename
internal
::
char_t
<
S
>::
type
>::
value
,
typename
internal
::
has_to_string_view
<
S
>::
char_type
>::
value
,
"mismatch between char-types of context and argument"
);
"mismatch between char-types of context and argument"
);
return
to_string_view
(
val
);
return
to_string_view
(
val
);
}
}
...
@@ -1264,9 +1281,9 @@ struct wformat_args : basic_format_args<wformat_context> {
...
@@ -1264,9 +1281,9 @@ struct wformat_args : basic_format_args<wformat_context> {
#if FMT_USE_ALIAS_TEMPLATES
#if FMT_USE_ALIAS_TEMPLATES
/** String's character type. */
/** String's character type. */
template
<
typename
S
>
template
<
typename
S
>
using
char_t
=
typename
std
::
enable_if
<
internal
::
has_to_string_view
<
S
>::
value
,
using
char_t
=
typename
std
::
enable_if
<
internal
::
is_string
<
S
>::
value
,
typename
internal
::
has_to_string_view
<
S
>::
char_
type
>::
type
;
typename
internal
::
char_t
<
S
>::
type
>::
type
;
#define FMT_CHAR(S) char_t<S>
#define FMT_CHAR(S)
fmt::
char_t<S>
template
<
typename
S
,
typename
T
>
template
<
typename
S
,
typename
T
>
using
enable_if_string_t
=
using
enable_if_string_t
=
...
@@ -1275,8 +1292,7 @@ using enable_if_string_t =
...
@@ -1275,8 +1292,7 @@ using enable_if_string_t =
#else
#else
template
<
typename
S
>
template
<
typename
S
>
struct
char_t
:
std
::
enable_if
<
struct
char_t
:
std
::
enable_if
<
internal
::
has_to_string_view
<
S
>::
value
,
internal
::
is_string
<
S
>::
value
,
typename
internal
::
char_t
<
S
>::
type
>
{};
typename
internal
::
has_to_string_view
<
S
>::
char_type
>
{};
#define FMT_CHAR(S) typename char_t<S>::type
#define FMT_CHAR(S) typename char_t<S>::type
#define FMT_ENABLE_IF_STRING(S, T) \
#define FMT_ENABLE_IF_STRING(S, T) \
...
@@ -1336,33 +1352,6 @@ std::basic_string<Char> vformat(
...
@@ -1336,33 +1352,6 @@ std::basic_string<Char> vformat(
basic_format_args
<
typename
buffer_context
<
Char
>::
type
>
args
);
basic_format_args
<
typename
buffer_context
<
Char
>::
type
>
args
);
}
}
/**
\rst
The function ``to_string_view`` adapts non-intrusively any kind of string or
string-like type if the user provides a (possibly templated) overload of
``to_string_view`` which takes an instance of the string class
``StringType<Char>`` and returns a ``fmt::basic_string_view<Char>``.
The conversion function must live in the very same namespace as
``StringType<Char>`` to be picked up by ADL. Non-templated string types
like f.e. QString must return a ``basic_string_view`` with a fixed matching
char type.
**Example**::
namespace my_ns {
inline string_view to_string_view(const my_string &s) {
return { s.data(), s.length() };
}
}
std::string message = fmt::format(my_string("The answer is {}"), 42);
\endrst
*/
template
<
typename
Char
>
inline
basic_string_view
<
Char
>
to_string_view
(
basic_string_view
<
Char
>
s
)
{
return
s
;
}
/**
/**
\rst
\rst
Returns a named argument to be used in a formatting function.
Returns a named argument to be used in a formatting function.
...
...
include/fmt/format.h
View file @
ea4010d7
...
@@ -753,7 +753,7 @@ class truncating_iterator_base {
...
@@ -753,7 +753,7 @@ class truncating_iterator_base {
typedef
void
difference_type
;
typedef
void
difference_type
;
typedef
void
pointer
;
typedef
void
pointer
;
typedef
void
reference
;
typedef
void
reference
;
typedef
truncating_iterator_base
_Unchecked_type
;
// Mark iterator as checked.
typedef
truncating_iterator_base
_Unchecked_type
;
// Mark iterator as checked.
OutputIt
base
()
const
{
return
out_
;
}
OutputIt
base
()
const
{
return
out_
;
}
std
::
size_t
count
()
const
{
return
count_
;
}
std
::
size_t
count
()
const
{
return
count_
;
}
...
@@ -811,9 +811,7 @@ class truncating_iterator<OutputIt, std::true_type>:
...
@@ -811,9 +811,7 @@ class truncating_iterator<OutputIt, std::true_type>:
}
}
truncating_iterator
&
operator
++
()
{
return
*
this
;
}
truncating_iterator
&
operator
++
()
{
return
*
this
;
}
truncating_iterator
&
operator
++
(
int
)
{
return
*
this
;
}
truncating_iterator
&
operator
++
(
int
)
{
return
*
this
;
}
truncating_iterator
&
operator
*
()
{
return
*
this
;
}
truncating_iterator
&
operator
*
()
{
return
*
this
;
}
};
};
...
@@ -3377,11 +3375,11 @@ inline typename buffer_context<FMT_CHAR(String)>::type::iterator vformat_to(
...
@@ -3377,11 +3375,11 @@ inline typename buffer_context<FMT_CHAR(String)>::type::iterator vformat_to(
}
}
template
<
template
<
typename
S
tring
,
typename
...
Args
,
typename
S
,
typename
...
Args
,
std
::
size_t
SIZE
=
inline_buffer_size
,
std
::
size_t
SIZE
=
inline_buffer_size
,
typename
Char
=
typename
internal
::
has_to_string_view
<
String
>
::
char_
type
>
typename
Char
=
typename
internal
::
char_t
<
S
>
::
type
>
inline
typename
buffer_context
<
Char
>::
type
::
iterator
format_to
(
inline
typename
buffer_context
<
Char
>::
type
::
iterator
format_to
(
basic_memory_buffer
<
Char
,
SIZE
>
&
buf
,
const
S
tring
&
format_str
,
basic_memory_buffer
<
Char
,
SIZE
>
&
buf
,
const
S
&
format_str
,
const
Args
&
...
args
)
{
const
Args
&
...
args
)
{
internal
::
check_format_string
<
Args
...
>
(
format_str
);
internal
::
check_format_string
<
Args
...
>
(
format_str
);
typedef
typename
buffer_context
<
Char
>::
type
context
;
typedef
typename
buffer_context
<
Char
>::
type
context
;
...
...
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