Skip to content

Commit

Permalink
Simplify char_t
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaut committed Jan 5, 2024
1 parent a5d4c2b commit 7ef3c1a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
22 changes: 10 additions & 12 deletions include/fmt/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -570,9 +570,9 @@ template <> struct is_char<char> : std::true_type {};

namespace detail {

// Constructs fmt::basic_string_view<Char> from types **implicitly** convertible
// to it, deducing Char. Explicitly convertible types such as compile-time
// strings are intentionally excluded.
// Constructs fmt::basic_string_view<Char> from types implicitly convertible
// to it, deducing Char. Explicitly convertible types such as the ones returned
// from FMT_STRING are intentionally excluded.
template <typename Char, FMT_ENABLE_IF(is_char<Char>::value)>
FMT_INLINE auto to_string_view(const Char* s) -> basic_string_view<Char> {
return s;
Expand All @@ -597,12 +597,6 @@ template <typename S, typename = void>
struct is_string
: std::is_class<decltype(detail::to_string_view(std::declval<S>()))> {};

template <typename S, typename = void> struct char_t_impl {};
template <typename S> struct char_t_impl<S, enable_if_t<is_string<S>::value>> {
using result = decltype(to_string_view(std::declval<S>()));
using type = typename result::value_type;
};

enum class type {
none_type,
// Integer types should go first,
Expand Down Expand Up @@ -682,7 +676,9 @@ enum {
FMT_NORETURN FMT_API void throw_format_error(const char* message);

/** String's character type. */
template <typename S> using char_t = typename detail::char_t_impl<S>::type;
template <typename S>
using char_t =
typename decltype(detail::to_string_view(std::declval<S>()))::value_type;

/**
\rst
Expand Down Expand Up @@ -1423,8 +1419,10 @@ template <typename Context> struct arg_mapper {
return val;
}
template <typename T,
FMT_ENABLE_IF(is_string<T>::value && !std::is_pointer<T>::value &&
std::is_same<char_type, char_t<T>>::value)>
typename Char =
typename decltype(detail::to_string_view(T()))::value_type,
FMT_ENABLE_IF(!std::is_pointer<T>::value &&
std::is_same<Char, char_type>::value)>
FMT_CONSTEXPR FMT_INLINE auto map(const T& val)
-> basic_string_view<char_type> {
return to_string_view(val);
Expand Down
7 changes: 5 additions & 2 deletions include/fmt/xchar.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@ enum char8_type : unsigned char {};
template <typename T>
using is_exotic_char = bool_constant<!std::is_same<T, char>::value>;

template <typename S, typename = void>
struct format_string_char : char_t_impl<S> {};
template <typename S, typename = void> struct format_string_char {};

template <typename S> struct format_string_char<S, void_t<char_t<S>>> {
using type = char_t<S>;
};

template <typename S>
struct format_string_char<S, enable_if_t<is_compile_string<S>::value>> {
Expand Down

0 comments on commit 7ef3c1a

Please sign in to comment.