Sprout/sprout/cstring/memcmp.hpp
2012-04-01 22:15:09 +09:00

29 lines
787 B
C++
Raw Blame History

#ifndef SPROUT_CSTRING_MEMCMP_HPP
#define SPROUT_CSTRING_MEMCMP_HPP
#include <cstddef>
#include <sprout/config.hpp>
namespace sprout {
// Copyright (C) 2011 RiSK (sscrisk)
namespace detail {
inline SPROUT_CONSTEXPR int memcmp_impl(unsigned char const* s1, unsigned char const* s2, std::size_t n) {
return !n ? 0
: *s1 == *s2 ? sprout::detail::memcmp_impl(s1 + 1, s2 + 1, n - 1)
: *s1 - *s2
;
}
} // namespace detail
// 7.21.4.1 memcmp ŠÖ<C5A0>
inline SPROUT_CONSTEXPR int memcmp(void const * s1, void const * s2, std::size_t n) {
return sprout::detail::memcmp_impl(
static_cast<unsigned char const*>(s1),
static_cast<unsigned char const*>(s2),
n
);
}
} // namespace sprout
#endif // #ifndef SPROUT_CSTRING_MEMCMP_HPP