Make 'std::*::basic_string_view' a valid argument type for 'format_str' parameters.

Signed-off-by: Daniela Engert <dani@ngrt.de>
This commit is contained in:
Daniela Engert 2018-10-07 18:54:12 +02:00 committed by Victor Zverovich
parent 87a0408c64
commit 6a685571df
2 changed files with 30 additions and 0 deletions

View File

@ -493,6 +493,12 @@ template <typename Char>
struct format_string_traits<std::basic_string<Char>> : struct format_string_traits<std::basic_string<Char>> :
format_string_traits_base<Char> {}; format_string_traits_base<Char> {};
#ifdef FMT_STRING_VIEW
template <typename Char>
struct format_string_traits<FMT_STRING_VIEW<Char>> :
format_string_traits_base<Char> {};
#endif
template <typename S> template <typename S>
struct format_string_traits< struct format_string_traits<
S, typename std::enable_if<std::is_base_of< S, typename std::enable_if<std::is_base_of<

View File

@ -451,6 +451,30 @@ TEST(CoreTest, IsEnumConvertibleToInt) {
EXPECT_TRUE((fmt::convert_to_int<enum_with_underlying_type, char>::value)); EXPECT_TRUE((fmt::convert_to_int<enum_with_underlying_type, char>::value));
} }
template <typename T>
class IsStringTest : public testing::Test {};
typedef ::testing::Types<char, wchar_t, char16_t, char32_t> StringCharTypes;
TYPED_TEST_CASE(IsStringTest, StringCharTypes);
namespace {
template <typename Char>
struct derived_from_string_view : fmt::basic_string_view<Char> {};
}
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<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
}
TEST(CoreTest, Format) { TEST(CoreTest, Format) {
// This should work without including fmt/format.h. // This should work without including fmt/format.h.
#ifdef FMT_FORMAT_H_ #ifdef FMT_FORMAT_H_