mirror of
https://github.com/fmtlib/fmt.git
synced 2024-11-02 11:28:20 +00:00
Demacrify
This commit is contained in:
parent
637bf3c6d9
commit
49f78a427b
@ -187,25 +187,34 @@
|
||||
# define FMT_ASSERT(condition, message) assert((condition) && message)
|
||||
#endif
|
||||
|
||||
// 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
|
||||
#elif FMT_HAS_INCLUDE("experimental/string_view") && __cplusplus >= 201402L
|
||||
# include <experimental/string_view>
|
||||
# define FMT_STRING_VIEW std::experimental::basic_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
|
||||
|
||||
// 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_USE_STRING_VIEW
|
||||
#elif FMT_HAS_INCLUDE("experimental/string_view") && __cplusplus >= 201402L
|
||||
# include <experimental/string_view>
|
||||
# define FMT_USE_EXPERIMENTAL_STRING_VIEW
|
||||
#endif
|
||||
|
||||
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()),
|
||||
size_(s.size()) {}
|
||||
#endif
|
||||
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()) {}
|
||||
|
||||
/** 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).
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user