Skip to content

Commit

Permalink
fix build errors
Browse files Browse the repository at this point in the history
  • Loading branch information
kitegi committed Oct 24, 2020
1 parent 8702f3a commit 404fb19
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions include/fmt/ranges.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,33 @@ auto range_end(T const (&arr)[N]) -> T const* {
return arr + N;
}

template <typename T, typename Enable = void>
struct has_member_fn_begin_end_t : std::false_type {};

template <typename T>
struct has_member_fn_begin_end_t<T, void_t<decltype(std::declval<T>().begin()),
decltype(std::declval<T>().end())>>
: std::true_type {};

// Member function overload
template <typename T>
auto range_begin(T&& rng) FMT_DECLTYPE_RETURN(static_cast<T&&>(rng).begin());
template <typename T>
auto range_end(T&& rng) FMT_DECLTYPE_RETURN(static_cast<T&&>(rng).end());

// ADL overload
// ADL overload. Only participates in overload resolution if member functions
// are not found.
template <typename T>
auto range_begin(T& rng) FMT_DECLTYPE_RETURN(begin(static_cast<T&&>(rng)));
auto range_begin(T&& rng)
-> enable_if_t<!has_member_fn_begin_end_t<T&&>::value,
decltype(begin(static_cast<T&&>(rng)))> {
return begin(static_cast<T&&>(rng));
}
template <typename T>
auto range_end(T& rng) FMT_DECLTYPE_RETURN(end(static_cast<T&&>(rng)));
auto range_end(T&& rng) -> enable_if_t<!has_member_fn_begin_end_t<T&&>::value,
decltype(end(static_cast<T&&>(rng)))> {
return end(static_cast<T&&>(rng));
}

template <typename T, typename Enable = void>
struct has_const_begin_end : std::false_type {};
Expand All @@ -142,7 +158,7 @@ struct has_mutable_begin_end<

template <typename T>
struct is_range_<T, void>
: std::integral_constant<bool, ((has_const_begin_end<T>::value) or
: std::integral_constant<bool, ((has_const_begin_end<T>::value) ||
(has_mutable_begin_end<T>::value))> {};

template <typename T, typename Enable = void> struct range_to_view;
Expand All @@ -158,7 +174,7 @@ struct range_to_view<T, enable_if_t<has_const_begin_end<T>::value>> {
};

template <typename T>
struct range_to_view<T, enable_if_t<not has_const_begin_end<T>::value and
struct range_to_view<T, enable_if_t<!has_const_begin_end<T>::value &&
has_mutable_begin_end<T>::value>> {
struct view_t {
T m_range_copy;
Expand All @@ -168,6 +184,7 @@ struct range_to_view<T, enable_if_t<not has_const_begin_end<T>::value and
};
static auto view(T const& range) -> view_t { return {range}; }
};
# undef FMT_DECLTYPE_RETURN
#endif

/// tuple_size and tuple_element check.
Expand Down Expand Up @@ -225,7 +242,8 @@ template <class Tuple, class F> void for_each(Tuple&& tup, F&& f) {
}

template <typename Range>
using value_type = remove_cvref_t<decltype(*detail::range_begin(std::declval<Range>()))>;
using value_type =
remove_cvref_t<decltype(*detail::range_begin(std::declval<Range>()))>;

template <typename Arg, FMT_ENABLE_IF(!is_like_std_string<
typename std::decay<Arg>::type>::value)>
Expand Down

0 comments on commit 404fb19

Please sign in to comment.