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
926ddd06
Commit
926ddd06
authored
May 30, 2022
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move compile string to detail
parent
cb682f36
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
10 additions
and
10 deletions
+10
-10
include/fmt/core.h
include/fmt/core.h
+6
-7
include/fmt/format.h
include/fmt/format.h
+1
-1
test/ostream-test.cc
test/ostream-test.cc
+3
-2
No files found.
include/fmt/core.h
View file @
926ddd06
...
...
@@ -493,15 +493,14 @@ using string_view = basic_string_view<char>;
template
<
typename
T
>
struct
is_char
:
std
::
false_type
{};
template
<
>
struct
is_char
<
char
>
:
std
::
true_type
{};
// A base class for compile-time strings. It is defined in the fmt namespace to
// make formatting functions visible via ADL, e.g. format(FMT_STRING("{}"), 42).
FMT_BEGIN_DETAIL_NAMESPACE
// A base class for compile-time strings.
struct
compile_string
{};
template
<
typename
S
>
struct
is_compile_string
:
std
::
is_base_of
<
compile_string
,
S
>
{};
FMT_BEGIN_DETAIL_NAMESPACE
// Returns a string view of `s`.
template
<
typename
Char
,
FMT_ENABLE_IF
(
is_char
<
Char
>
::
value
)
>
FMT_INLINE
auto
to_string_view
(
const
Char
*
s
)
->
basic_string_view
<
Char
>
{
...
...
@@ -519,8 +518,7 @@ constexpr auto to_string_view(basic_string_view<Char> s)
}
template
<
typename
Char
,
FMT_ENABLE_IF
(
!
std
::
is_empty
<
std_string_view
<
Char
>
>::
value
)
>
inline
auto
to_string_view
(
std_string_view
<
Char
>
s
)
->
basic_string_view
<
Char
>
{
inline
auto
to_string_view
(
std_string_view
<
Char
>
s
)
->
basic_string_view
<
Char
>
{
return
s
;
}
template
<
typename
S
,
FMT_ENABLE_IF
(
is_compile_string
<
S
>
::
value
)
>
...
...
@@ -533,6 +531,7 @@ void to_string_view(...);
// Specifies whether S is a string type convertible to fmt::basic_string_view.
// It should be a constexpr function but MSVC 2017 fails to compile it in
// enable_if and MSVC 2015 fails to compile it as an alias template.
// ADL invocation of to_string_view is DEPRECATED!
template
<
typename
S
>
struct
is_string
:
std
::
is_class
<
decltype
(
to_string_view
(
std
::
declval
<
S
>
()))
>
{
};
...
...
@@ -2918,7 +2917,7 @@ FMT_INLINE void check_format_string(const S&) {
template
<
typename
...
Args
,
typename
S
,
FMT_ENABLE_IF
(
is_compile_string
<
S
>
::
value
)
>
void
check_format_string
(
S
format_str
)
{
FMT_CONSTEXPR
auto
s
=
to_string_view
(
format_str
);
FMT_CONSTEXPR
auto
s
=
basic_string_view
<
typename
S
::
char_type
>
(
format_str
);
using
checker
=
format_string_checker
<
typename
S
::
char_type
,
error_handler
,
remove_cvref_t
<
Args
>
...
>
;
FMT_CONSTEXPR
bool
invalid_format
=
...
...
include/fmt/format.h
View file @
926ddd06
...
...
@@ -1762,7 +1762,7 @@ inline auto find_escape(const char* begin, const char* end)
std::string s = fmt::format(FMT_STRING("{:d}"), "foo");
\endrst
*/
#define FMT_STRING(s) FMT_STRING_IMPL(s, fmt::compile_string, )
#define FMT_STRING(s) FMT_STRING_IMPL(s, fmt::
detail::
compile_string, )
template
<
size_t
width
,
typename
Char
,
typename
OutputIt
>
auto
write_codepoint
(
OutputIt
out
,
char
prefix
,
uint32_t
cp
)
->
OutputIt
{
...
...
test/ostream-test.cc
View file @
926ddd06
...
...
@@ -165,8 +165,9 @@ TEST(ostream_test, join_fallback_formatter) {
#if FMT_USE_CONSTEXPR
TEST
(
ostream_test
,
constexpr_string
)
{
EXPECT_EQ
(
"42"
,
format
(
FMT_STRING
(
"{}"
),
std
::
string
(
"42"
)));
EXPECT_EQ
(
"a string"
,
format
(
FMT_STRING
(
"{0}"
),
test_string
(
"a string"
)));
EXPECT_EQ
(
"42"
,
fmt
::
format
(
FMT_STRING
(
"{}"
),
std
::
string
(
"42"
)));
EXPECT_EQ
(
"a string"
,
fmt
::
format
(
FMT_STRING
(
"{0}"
),
test_string
(
"a string"
)));
}
#endif
...
...
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