From 6957d28cfb924f6b068c3d7347b889eb3a1a7f97 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Mon, 26 Mar 2018 06:50:22 -1000 Subject: [PATCH 1/4] Detect string_view on libc++ (#686) --- include/fmt/core.h | 3 ++- test/format-test.cc | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/include/fmt/core.h b/include/fmt/core.h index 3ddb3b4a..f519b5d9 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -156,7 +156,8 @@ void operator=(const Type &) FMT_DELETED #if (FMT_HAS_INCLUDE() && __cplusplus > 201402L) || \ - (defined(_MSVC_LANG) && _MSVC_LANG > 201402L && _MSC_VER >= 1910) + (defined(_MSVC_LANG) && _MSVC_LANG > 201402L && _MSC_VER >= 1910) || \ + _LIBCPP_VERSION // libc++ supports string_view in pre-c++17 # include # define FMT_USE_STD_STRING_VIEW // std::experimental::basic_string_view::remove_prefix isn't constexpr until diff --git a/test/format-test.cc b/test/format-test.cc index 0ea41c83..8c35dc43 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -1201,7 +1201,7 @@ TEST(FormatterTest, FormatStringView) { } #ifdef FMT_USE_STD_STRING_VIEW -TEST(FormatterTest, FormatStringView) { +TEST(FormatterTest, FormatStdStringView) { EXPECT_EQ("test", format("{0}", std::string_view("test"))); } #endif From 4fea018b2d3de314120a79e638499319f183429b Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Mon, 26 Mar 2018 07:00:41 -1000 Subject: [PATCH 2/4] Fix string_view detection --- include/fmt/core.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/include/fmt/core.h b/include/fmt/core.h index f519b5d9..fd53cfbe 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -155,9 +155,10 @@ Type(const Type &) FMT_DELETED; \ void operator=(const Type &) FMT_DELETED -#if (FMT_HAS_INCLUDE() && __cplusplus > 201402L) || \ - (defined(_MSVC_LANG) && _MSVC_LANG > 201402L && _MSC_VER >= 1910) || \ - _LIBCPP_VERSION // libc++ supports string_view in pre-c++17 +// libc++ supports string_view in pre-c++17. +#if (FMT_HAS_INCLUDE() && \ + (__cplusplus > 201402L || _LIBCPP_VERSION)) || \ + (defined(_MSVC_LANG) && _MSVC_LANG > 201402L && _MSC_VER >= 1910) # include # define FMT_USE_STD_STRING_VIEW // std::experimental::basic_string_view::remove_prefix isn't constexpr until From 7a41d61d798a5cb7f56007e20c9fc8bf0a635f4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Germ=C3=A1n=20M=C3=A9ndez=20Bravo?= Date: Mon, 26 Mar 2018 12:42:40 -0600 Subject: [PATCH 3/4] Add make_printf_args Fixes #687 --- include/fmt/printf.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/fmt/printf.h b/include/fmt/printf.h index 9a189844..15bdf7b9 100644 --- a/include/fmt/printf.h +++ b/include/fmt/printf.h @@ -540,6 +540,10 @@ struct printf_context { std::back_insert_iterator, typename Buffer::value_type> type; }; +template +inline arg_store::type, Args...> make_printf_args(const Args & ... args) { + return arg_store::type, Args...>(args...); +} typedef basic_format_args::type> printf_args; inline std::string vsprintf(string_view format, printf_args args) { From 8e10d404dbe9bcd7f73070b53788fe6341912be4 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Tue, 27 Mar 2018 07:39:03 -1000 Subject: [PATCH 4/4] Fix compile tests --- test/compile-test/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/compile-test/CMakeLists.txt b/test/compile-test/CMakeLists.txt index cebcee01..ede0c3ce 100644 --- a/test/compile-test/CMakeLists.txt +++ b/test/compile-test/CMakeLists.txt @@ -48,10 +48,10 @@ endfunction () expect_compile("") # Formatting a wide character with a narrow format string is forbidden. -expect_compile_error("fmt::format(\"{}\", L'a';") +expect_compile_error("fmt::format(\"{}\", L'a');") # Formatting a wide string with a narrow format string is forbidden. -expect_compile_error("fmt::format(\"{}\", L\"foo\";") +expect_compile_error("fmt::format(\"{}\", L\"foo\");") # Make sure that compiler features detected in the header # match the features detected in CMake.