Move compile string to detail

This commit is contained in:
Victor Zverovich 2022-05-30 06:41:33 -07:00
parent cb682f36f4
commit 926ddd0631
3 changed files with 10 additions and 10 deletions

View File

@ -493,15 +493,14 @@ using string_view = basic_string_view<char>;
template <typename T> struct is_char : std::false_type {};
template <> struct is_char<char> : std::true_type {};
// 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_STRING("{}"), 42).
FMT_BEGIN_DETAIL_NAMESPACE
// A base class for compile-time strings.
struct compile_string {};
template <typename S>
struct is_compile_string : std::is_base_of<compile_string, S> {};
FMT_BEGIN_DETAIL_NAMESPACE
// Returns a string view of `s`.
template <typename Char, FMT_ENABLE_IF(is_char<Char>::value)>
FMT_INLINE auto to_string_view(const Char* s) -> basic_string_view<Char> {
@ -519,8 +518,7 @@ constexpr auto to_string_view(basic_string_view<Char> s)
}
template <typename Char,
FMT_ENABLE_IF(!std::is_empty<std_string_view<Char>>::value)>
inline auto to_string_view(std_string_view<Char> s)
-> basic_string_view<Char> {
inline auto to_string_view(std_string_view<Char> s) -> basic_string_view<Char> {
return s;
}
template <typename S, FMT_ENABLE_IF(is_compile_string<S>::value)>
@ -533,6 +531,7 @@ void to_string_view(...);
// Specifies whether S is a string type convertible to fmt::basic_string_view.
// It should be a constexpr function but MSVC 2017 fails to compile it in
// enable_if and MSVC 2015 fails to compile it as an alias template.
// ADL invocation of to_string_view is DEPRECATED!
template <typename S>
struct is_string : std::is_class<decltype(to_string_view(std::declval<S>()))> {
};
@ -2918,7 +2917,7 @@ FMT_INLINE void check_format_string(const S&) {
template <typename... Args, typename S,
FMT_ENABLE_IF(is_compile_string<S>::value)>
void check_format_string(S format_str) {
FMT_CONSTEXPR auto s = to_string_view(format_str);
FMT_CONSTEXPR auto s = basic_string_view<typename S::char_type>(format_str);
using checker = format_string_checker<typename S::char_type, error_handler,
remove_cvref_t<Args>...>;
FMT_CONSTEXPR bool invalid_format =

View File

@ -1762,7 +1762,7 @@ inline auto find_escape(const char* begin, const char* end)
std::string s = fmt::format(FMT_STRING("{:d}"), "foo");
\endrst
*/
#define FMT_STRING(s) FMT_STRING_IMPL(s, fmt::compile_string, )
#define FMT_STRING(s) FMT_STRING_IMPL(s, fmt::detail::compile_string, )
template <size_t width, typename Char, typename OutputIt>
auto write_codepoint(OutputIt out, char prefix, uint32_t cp) -> OutputIt {

View File

@ -165,8 +165,9 @@ TEST(ostream_test, join_fallback_formatter) {
#if FMT_USE_CONSTEXPR
TEST(ostream_test, constexpr_string) {
EXPECT_EQ("42", format(FMT_STRING("{}"), std::string("42")));
EXPECT_EQ("a string", format(FMT_STRING("{0}"), test_string("a string")));
EXPECT_EQ("42", fmt::format(FMT_STRING("{}"), std::string("42")));
EXPECT_EQ("a string",
fmt::format(FMT_STRING("{0}"), test_string("a string")));
}
#endif