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
49f78a42
Commit
49f78a42
authored
May 30, 2019
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Demacrify
parent
637bf3c6
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
32 deletions
+39
-32
include/fmt/core.h
include/fmt/core.h
+25
-16
test/core-test.cc
test/core-test.cc
+14
-16
No files found.
include/fmt/core.h
View file @
49f78a42
...
...
@@ -187,25 +187,34 @@
# define FMT_ASSERT(condition, message) assert((condition) && message)
#endif
// An enable_if helper to be used in template parameters. enable_if in template
// parameters results in much shorter symbols: https://godbolt.org/z/sWw4vP.
#define FMT_ENABLE_IF_T(...) typename std::enable_if<(__VA_ARGS__), int>::type
#define FMT_ENABLE_IF(...) FMT_ENABLE_IF_T(__VA_ARGS__) = 0
// libc++ supports string_view in pre-c++17.
#if (FMT_HAS_INCLUDE(<string_view>) && \
(__cplusplus > 201402L || defined(_LIBCPP_VERSION))) || \
(defined(_MSVC_LANG) && _MSVC_LANG > 201402L && _MSC_VER >= 1910)
# include <string_view>
# define FMT_
STRING_VIEW std::basic_string_view
# define FMT_
USE_STRING_VIEW
#elif FMT_HAS_INCLUDE("experimental/string_view") && __cplusplus >= 201402L
# include <experimental/string_view>
# define FMT_
STRING_VIEW std::experimental::basic_string_view
# define FMT_
USE_EXPERIMENTAL_STRING_VIEW
#endif
// An enable_if helper to be used in template parameters. enable_if in template
// parameters results in much shorter symbols: https://godbolt.org/z/sWw4vP.
#define FMT_ENABLE_IF_T(...) typename std::enable_if<(__VA_ARGS__), int>::type
#define FMT_ENABLE_IF(...) FMT_ENABLE_IF_T(__VA_ARGS__) = 0
FMT_BEGIN_NAMESPACE
namespace
internal
{
#if defined(FMT_USE_STRING_VIEW)
template
<
typename
Char
>
using
std_string_view
=
std
::
basic_string_view
<
Char
>
;
#elif defined(FMT_USE_EXPERIMENTAL_STRING_VIEW)
template
<
typename
Char
>
using
std_string_view
=
std
::
experimental
::
basic_string_view
<
Char
>
;
#else
template
<
typename
T
>
struct
std_string_view
{};
#endif
template
<
typename
>
struct
result_of
;
#if (__cplusplus >= 201703L || \
...
...
@@ -396,11 +405,11 @@ template <typename Char> class basic_string_view {
FMT_NOEXCEPT
:
data_
(
s
.
data
()),
size_
(
s
.
size
())
{}
#ifdef FMT_STRING_VIEW
FMT_CONSTEXPR
basic_string_view
(
FMT_STRING_VIEW
<
Char
>
s
)
FMT_NOEXCEPT
:
data_
(
s
.
data
()),
template
<
typename
S
,
FMT_ENABLE_IF
(
std
::
is_same
<
S
,
internal
::
std_string_view
<
Char
>
>::
value
)
>
FMT_CONSTEXPR
basic_string_view
(
S
s
)
FMT_NOEXCEPT
:
data_
(
s
.
data
()),
size_
(
s
.
size
())
{}
#endif
/** Returns a pointer to the string data. */
FMT_CONSTEXPR
const
Char
*
data
()
const
{
return
data_
;
}
...
...
@@ -486,12 +495,12 @@ inline basic_string_view<Char> to_string_view(const Char* s) {
return
s
;
}
#ifdef FMT_STRING_VIEW
template
<
typename
Char
>
inline
basic_string_view
<
Char
>
to_string_view
(
FMT_STRING_VIEW
<
Char
>
s
)
{
template
<
typename
Char
,
FMT_ENABLE_IF
(
!
std
::
is_empty
<
internal
::
std_string_view
<
Char
>
>::
value
)
>
inline
basic_string_view
<
Char
>
to_string_view
(
internal
::
std_string_view
<
Char
>
s
)
{
return
s
;
}
#endif
// 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("{}"), 42).
...
...
test/core-test.cc
View file @
49f78a42
...
...
@@ -475,9 +475,7 @@ class QString {
QString
(
const
wchar_t
*
s
)
:
s_
(
std
::
make_shared
<
std
::
wstring
>
(
s
))
{}
const
wchar_t
*
utf16
()
const
FMT_NOEXCEPT
{
return
s_
->
data
();
}
int
size
()
const
FMT_NOEXCEPT
{
return
static_cast
<
int
>
(
s_
->
size
());
}
#ifdef FMT_STRING_VIEW
operator
FMT_STRING_VIEW
<
wchar_t
>
()
const
FMT_NOEXCEPT
{
return
*
s_
;
}
#endif
private:
std
::
shared_ptr
<
std
::
wstring
>
s_
;
};
...
...
@@ -499,21 +497,21 @@ struct derived_from_string_view : fmt::basic_string_view<Char> {};
}
// namespace
TYPED_TEST
(
IsStringTest
,
IsString
)
{
EXPECT_TRUE
(
(
fmt
::
internal
::
is_string
<
TypeParam
*>::
value
)
);
EXPECT_TRUE
(
(
fmt
::
internal
::
is_string
<
const
TypeParam
*>::
value
)
);
EXPECT_TRUE
(
(
fmt
::
internal
::
is_string
<
TypeParam
[
2
]
>::
value
)
);
EXPECT_TRUE
(
(
fmt
::
internal
::
is_string
<
const
TypeParam
[
2
]
>::
value
)
);
EXPECT_TRUE
(
(
fmt
::
internal
::
is_string
<
std
::
basic_string
<
TypeParam
>>::
value
)
);
EXPECT_TRUE
(
fmt
::
internal
::
is_string
<
TypeParam
*>::
value
);
EXPECT_TRUE
(
fmt
::
internal
::
is_string
<
const
TypeParam
*>::
value
);
EXPECT_TRUE
(
fmt
::
internal
::
is_string
<
TypeParam
[
2
]
>::
value
);
EXPECT_TRUE
(
fmt
::
internal
::
is_string
<
const
TypeParam
[
2
]
>::
value
);
EXPECT_TRUE
(
fmt
::
internal
::
is_string
<
std
::
basic_string
<
TypeParam
>>::
value
);
EXPECT_TRUE
(
(
fmt
::
internal
::
is_string
<
fmt
::
basic_string_view
<
TypeParam
>>::
value
)
);
fmt
::
internal
::
is_string
<
fmt
::
basic_string_view
<
TypeParam
>>::
value
);
EXPECT_TRUE
(
(
fmt
::
internal
::
is_string
<
derived_from_string_view
<
TypeParam
>>::
value
)
);
#ifdef FMT_STRING_VIEW
EXPECT_TRUE
(
(
fmt
::
internal
::
is_string
<
FMT_STRING_VIEW
<
TypeParam
>>::
value
));
#endif
EXPECT_TRUE
(
(
fmt
::
internal
::
is_string
<
my_ns
::
my_string
<
TypeParam
>>::
value
)
);
EXPECT_FALSE
(
(
fmt
::
internal
::
is_string
<
my_ns
::
non_string
>::
value
)
);
EXPECT_TRUE
(
(
fmt
::
internal
::
is_string
<
FakeQt
::
QString
>::
value
)
);
fmt
::
internal
::
is_string
<
derived_from_string_view
<
TypeParam
>>::
value
);
using
string_view
=
fmt
::
internal
::
std_string_view
<
TypeParam
>
;
EXPECT_TRUE
(
std
::
is_empty
<
string_view
>::
value
!=
fmt
::
internal
::
is_string
<
string_view
>::
value
);
EXPECT_TRUE
(
fmt
::
internal
::
is_string
<
my_ns
::
my_string
<
TypeParam
>>::
value
);
EXPECT_FALSE
(
fmt
::
internal
::
is_string
<
my_ns
::
non_string
>::
value
);
EXPECT_TRUE
(
fmt
::
internal
::
is_string
<
FakeQt
::
QString
>::
value
);
}
TEST
(
CoreTest
,
Format
)
{
...
...
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