fix: [imp] dataof/countof's SFINAE may be invalid

This commit is contained in:
mutouyun 2023-07-29 13:18:46 +08:00
parent 08b6649946
commit bad1ff4696
2 changed files with 14 additions and 6 deletions

View File

@ -71,9 +71,11 @@ struct trait<C, false, true> {
} // namespace detail_countof
template <typename C, typename R = detail_countof::trait<C>>
constexpr auto countof(C const &c) noexcept(noexcept(R::countof(c))) {
return R::countof(c);
template <typename C,
typename T = detail_countof::trait<C>,
typename R = decltype(T::countof(std::declval<C const &>()))>
constexpr R countof(C const &c) noexcept(noexcept(T::countof(c))) {
return T::countof(c);
}
LIBIMP_NAMESPACE_END_

View File

@ -80,13 +80,19 @@ struct trait<C, false, false> {
constexpr static T const *dataof(std::initializer_list<T> il) noexcept {
return il.begin();
}
template <typename T>
constexpr static T const *dataof(T const *p) noexcept {
return p;
}
};
} // namespace detail_dataof
template <typename T, typename R = detail_dataof::trait<std::remove_cv_t<std::remove_reference_t<T>>>>
constexpr auto dataof(T &&c) noexcept(noexcept(R::dataof(std::forward<T>(c)))) {
return R::dataof(std::forward<T>(c));
template <typename C,
typename T = detail_dataof::trait<std::remove_cv_t<std::remove_reference_t<C>>>,
typename R = decltype(T::dataof(std::declval<C>()))>
constexpr R dataof(C &&c) noexcept(noexcept(T::dataof(std::forward<C>(c)))) {
return T::dataof(std::forward<C>(c));
}
LIBIMP_NAMESPACE_END_