/*============================================================================= Copyright (c) 2011-2013 Bolero MURAKAMI https://github.com/bolero-MURAKAMI/Sprout Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) =============================================================================*/ #ifndef SPROUT_CSTRING_STRCMP_HPP #define SPROUT_CSTRING_STRCMP_HPP #include #include #include #include #include #include #include #include namespace sprout { namespace detail { template inline SPROUT_CONSTEXPR int strcmp_impl_check(sprout::tuples::tuple const& found) { return !*sprout::tuples::get<1>(found) ? (!*sprout::tuples::get<0>(found) ? 0 : 1) : !*sprout::tuples::get<0>(found) ? -1 : sprout::tuples::get<2>(found) ; } template inline SPROUT_CONSTEXPR sprout::tuples::tuple strcmp_impl_1( sprout::tuples::tuple const& current, typename std::iterator_traits::difference_type n ) { typedef sprout::tuples::tuple type; return sprout::tuples::get<2>(current) || !*sprout::tuples::get<1>(current) || !*sprout::tuples::get<0>(current) ? current : n == 1 ? (*sprout::tuples::get<0>(current)) < (*sprout::tuples::get<1>(current)) ? type(sprout::tuples::get<0>(current), sprout::tuples::get<1>(current), -1) : (*sprout::tuples::get<1>(current)) < (*sprout::tuples::get<0>(current)) ? type(sprout::tuples::get<0>(current), sprout::tuples::get<1>(current), 1) : type(sprout::next(sprout::tuples::get<0>(current)), sprout::next(sprout::tuples::get<1>(current)), 0) : sprout::detail::strcmp_impl_1( sprout::detail::strcmp_impl_1( current, n / 2 ), n - n / 2 ) ; } template inline SPROUT_CONSTEXPR sprout::tuples::tuple strcmp_impl( sprout::tuples::tuple const& current, typename std::iterator_traits::difference_type n ) { return sprout::tuples::get<2>(current) || !*sprout::tuples::get<1>(current) || !*sprout::tuples::get<0>(current) ? current : sprout::detail::strcmp_impl( sprout::detail::strcmp_impl_1( current, n ), n * 2 ) ; } template inline SPROUT_CONSTEXPR int strcmp(InputIterator1 first1, InputIterator2 first2) { typedef sprout::tuples::tuple type; return sprout::detail::strcmp_impl_check( sprout::detail::strcmp_impl(type(first1, first2, 0), 1) ); } } // namespace detail // 7.21.4.2 strcmp ֐ // // recursion depth: // O(log(N1+N2)) // inline SPROUT_CONSTEXPR int strcmp(char const* s1, char const* s2) { return sprout::detail::strcmp(s1, s2); } template inline SPROUT_CONSTEXPR typename std::enable_if< sprout::is_char_type::value, int >::type strcmp(Elem* s1, Elem* s2) { return sprout::detail::strcmp(s1, s2); } } // namespace sprout #endif // #ifndef SPROUT_CSTRING_STRCMP_HPP