#ifndef SPROUT_CSTRING_MEMCHR_HPP #define SPROUT_CSTRING_MEMCHR_HPP #include #include #include #include #include #include #include namespace sprout { namespace detail { inline SPROUT_CONSTEXPR unsigned char const* memchr_impl(unsigned char const* found, unsigned char const* last) { return found == last ? nullptr : found ; } inline SPROUT_CONSTEXPR unsigned char* memchr_impl(unsigned char* found, unsigned char* last) { return found == last ? nullptr : found ; } template struct memchr_result { private: static void const* check(void const*); static void* check(void*); static void check(...); public: typedef decltype(check(std::declval())) type; }; } // namespace detail // 7.21.5.1 memchr ֐ // // recursion depth: // O(log N) // #if 0 inline SPROUT_CONSTEXPR void const* memchr(void const* s, int c, std::size_t n) { return sprout::detail::memchr_impl( sprout::ptr_unindex( sprout::find( sprout::ptr_index(static_cast(s)), sprout::ptr_index(static_cast(s), n), static_cast(c) ) ), static_cast(s) + n ); } inline SPROUT_CONSTEXPR void* memchr(void* s, int c, std::size_t n) { return sprout::detail::memchr_impl( sprout::ptr_unindex( sprout::find( sprout::ptr_index(static_cast(s)), sprout::ptr_index(static_cast(s), n), static_cast(c) ) ), static_cast(s) + n ); } #endif template< typename T, typename sprout::enabler_if::type, void const*>::value>::type = sprout::enabler > inline SPROUT_CONSTEXPR void const* memchr(T s, int c, std::size_t n) { return sprout::detail::memchr_impl( sprout::ptr_unindex( sprout::find( sprout::ptr_index(static_cast(s)), sprout::ptr_index(static_cast(s), n), static_cast(c) ) ), static_cast(s) + n ); } template< typename T, typename sprout::enabler_if::type, void*>::value>::type = sprout::enabler > inline SPROUT_CONSTEXPR void* memchr(T s, int c, std::size_t n) { return sprout::detail::memchr_impl( sprout::ptr_unindex( sprout::find( sprout::ptr_index(static_cast(s)), sprout::ptr_index(static_cast(s), n), static_cast(c) ) ), static_cast(s) + n ); } } // namespace sprout #endif // #ifndef SPROUT_CSTRING_MEMCHR_HPP