mirror of
https://github.com/mutouyun/cpp-ipc.git
synced 2025-12-07 01:06:45 +08:00
try vc2015 countof ut
This commit is contained in:
parent
da22d0f7b2
commit
c4029bcde9
@ -17,11 +17,6 @@ LIBIPC_NAMESPACE_BEG_
|
|||||||
* @see https://en.cppreference.com/w/cpp/iterator/size
|
* @see https://en.cppreference.com/w/cpp/iterator/size
|
||||||
*/
|
*/
|
||||||
|
|
||||||
template <typename T, std::size_t N>
|
|
||||||
constexpr std::size_t countof(T const (&)[N]) noexcept {
|
|
||||||
return N;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace detail {
|
namespace detail {
|
||||||
|
|
||||||
template <typename C, typename = void>
|
template <typename C, typename = void>
|
||||||
@ -48,13 +43,18 @@ template <typename C, bool = countof_trait_has_size<C>::value
|
|||||||
, bool = countof_trait_has_Size<C>::value>
|
, bool = countof_trait_has_Size<C>::value>
|
||||||
struct countof_trait;
|
struct countof_trait;
|
||||||
|
|
||||||
|
template <typename T, std::size_t N>
|
||||||
|
struct countof_trait<T[N], false, false> {
|
||||||
|
constexpr static auto countof(T const (&)[N]) noexcept {
|
||||||
|
return N;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
template <typename C, bool B>
|
template <typename C, bool B>
|
||||||
struct countof_trait<C, true, B> {
|
struct countof_trait<C, true, B> {
|
||||||
constexpr static auto countof(C const &c) noexcept(noexcept(c.size())) {
|
constexpr static auto countof(C const &c) noexcept(noexcept(c.size())) {
|
||||||
return c.size();
|
return c.size();
|
||||||
}
|
}
|
||||||
using return_t = decltype(countof_trait::countof(std::declval<C>()));
|
|
||||||
enum : bool { noexcept_value = noexcept(countof_trait::countof(std::declval<C>())) };
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename C>
|
template <typename C>
|
||||||
@ -62,15 +62,12 @@ struct countof_trait<C, false, true> {
|
|||||||
constexpr static auto countof(C const &c) noexcept(noexcept(c.Size())) {
|
constexpr static auto countof(C const &c) noexcept(noexcept(c.Size())) {
|
||||||
return c.Size();
|
return c.Size();
|
||||||
}
|
}
|
||||||
using return_t = decltype(countof_trait::countof(std::declval<C>()));
|
|
||||||
enum : bool { noexcept_value = noexcept(countof_trait::countof(std::declval<C>())) };
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
|
|
||||||
template <typename C, typename R = detail::countof_trait<C>>
|
template <typename C, typename R = detail::countof_trait<C>>
|
||||||
constexpr auto countof(C const &c) noexcept(R::noexcept_value)
|
constexpr auto countof(C const &c) noexcept(noexcept(R::countof(c))) {
|
||||||
-> typename R::return_t {
|
|
||||||
return R::countof(c);
|
return R::countof(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user