Simplify compile-time strings

This commit is contained in:
Victor Zverovich
2018-10-28 06:57:35 -07:00
parent 5ee1a4bc8a
commit bdda4d6030
2 changed files with 19 additions and 19 deletions

View File

@ -472,11 +472,11 @@ struct compile_string {};
template <typename S> template <typename S>
struct is_compile_string : std::is_base_of<compile_string, S> {}; struct is_compile_string : std::is_base_of<compile_string, S> {};
template <typename S, typename Enable = typename std::enable_if<is_compile_string<S>::value>::type> template <
inline auto to_string_view(const S &s) -> basic_string_view<typename S::char_type> { typename S,
typedef typename S::char_type char_type; typename Enable = typename std::enable_if<is_compile_string<S>::value>::type>
return basic_string_view<char_type>{s.data(), s.size() - 1}; FMT_CONSTEXPR basic_string_view<typename S::char_type>
} to_string_view(const S &s) { return s; }
template <typename Context> template <typename Context>
class basic_format_arg; class basic_format_arg;

View File

@ -2240,13 +2240,12 @@ FMT_CONSTEXPR bool check_format_string(
return true; return true;
} }
template <typename... Args, typename String> template <typename... Args, typename S>
typename std::enable_if<is_compile_string<String>::value>::type typename std::enable_if<is_compile_string<S>::value>::type
check_format_string(String format_str) { check_format_string(S format_str) {
typedef typename String::char_type char_type; typedef typename S::char_type char_t;
FMT_CONSTEXPR_DECL bool invalid_format = FMT_CONSTEXPR_DECL bool invalid_format = internal::check_format_string<
internal::check_format_string<char_type, internal::error_handler, Args...>( char_t, internal::error_handler, Args...>(to_string_view(format_str));
basic_string_view<char_type>(format_str.data(), format_str.size()));
(void)invalid_format; (void)invalid_format;
} }
@ -3649,14 +3648,15 @@ operator"" _a(const wchar_t *s, std::size_t) { return {s}; }
FMT_END_NAMESPACE FMT_END_NAMESPACE
#define FMT_STRING(s) [] { \ #define FMT_STRING(s) [] { \
typedef typename std::decay<decltype(s)>::type pointer; \ typedef typename std::remove_cv<std::remove_pointer< \
struct S : fmt::compile_string { \ typename std::decay<decltype(s)>::type>::type>::type ct; \
typedef typename std::remove_cv<std::remove_pointer<pointer>::type>::type char_type;\ struct str : fmt::compile_string { \
static FMT_CONSTEXPR pointer data() { return s; } \ typedef ct char_type; \
static FMT_CONSTEXPR size_t size() { return sizeof(s) / sizeof(char_type); } \ FMT_CONSTEXPR operator fmt::basic_string_view<ct>() const { \
explicit operator fmt::basic_string_view<char_type>() const { return s; } \ return {s, sizeof(s) / sizeof(ct) - 1}; \
} \
}; \ }; \
return S{}; \ return str{}; \
}() }()
#if defined(FMT_STRING_ALIAS) && FMT_STRING_ALIAS #if defined(FMT_STRING_ALIAS) && FMT_STRING_ALIAS