From 6a685571dfc36490ba1d2ef28a6439de89422c55 Mon Sep 17 00:00:00 2001 From: Daniela Engert Date: Sun, 7 Oct 2018 18:54:12 +0200 Subject: [PATCH] Make 'std::*::basic_string_view' a valid argument type for 'format_str' parameters. Signed-off-by: Daniela Engert --- include/fmt/core.h | 6 ++++++ test/core-test.cc | 24 ++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/include/fmt/core.h b/include/fmt/core.h index c6c44e53..2c83f045 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -493,6 +493,12 @@ template struct format_string_traits> : format_string_traits_base {}; +#ifdef FMT_STRING_VIEW +template +struct format_string_traits> : + format_string_traits_base {}; +#endif + template struct format_string_traits< S, typename std::enable_if::value)); } +template +class IsStringTest : public testing::Test {}; + +typedef ::testing::Types StringCharTypes; +TYPED_TEST_CASE(IsStringTest, StringCharTypes); + +namespace { +template +struct derived_from_string_view : fmt::basic_string_view {}; +} + +TYPED_TEST(IsStringTest, IsString) { + EXPECT_TRUE((fmt::internal::is_string::value)); + EXPECT_TRUE((fmt::internal::is_string::value)); + EXPECT_TRUE((fmt::internal::is_string::value)); + EXPECT_TRUE((fmt::internal::is_string::value)); + EXPECT_TRUE((fmt::internal::is_string>::value)); + EXPECT_TRUE((fmt::internal::is_string>::value)); + EXPECT_TRUE((fmt::internal::is_string>::value)); +#ifdef FMT_STRING_VIEW + EXPECT_TRUE((fmt::internal::is_string>::value)); +#endif +} + TEST(CoreTest, Format) { // This should work without including fmt/format.h. #ifdef FMT_FORMAT_H_