Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-17 08:33:42

0001 #ifndef BOOST_HASH2_DETAIL_MEMCMP_HPP_INCLUDED
0002 #define BOOST_HASH2_DETAIL_MEMCMP_HPP_INCLUDED
0003 
0004 // Copyright 2024 Peter Dimov
0005 // Distributed under the Boost Software License, Version 1.0.
0006 // https://www.boost.org/LICENSE_1_0.txt
0007 
0008 #include <boost/hash2/detail/is_constant_evaluated.hpp>
0009 #include <boost/config.hpp>
0010 #include <cstring>
0011 
0012 namespace boost
0013 {
0014 namespace hash2
0015 {
0016 namespace detail
0017 {
0018 
0019 #if defined(BOOST_NO_CXX14_CONSTEXPR)
0020 
0021 BOOST_FORCEINLINE int memcmp( unsigned char const* p, unsigned char const* q, std::size_t n ) noexcept
0022 {
0023     return std::memcmp( p, q, n );
0024 }
0025 
0026 #else
0027 
0028 constexpr int memcmp( unsigned char const* p, unsigned char const* q, std::size_t n ) noexcept
0029 {
0030     if( !detail::is_constant_evaluated() )
0031     {
0032         return std::memcmp( p, q, n );
0033     }
0034     else
0035     {
0036         for( std::size_t i = 0; i < n; ++i )
0037         {
0038             if( p[ i ] != q[ i ] ) return p[ i ] - q[ i ];
0039         }
0040 
0041         return 0;
0042     }
0043 }
0044 
0045 #endif
0046 
0047 } // namespace detail
0048 } // namespace hash2
0049 } // namespace boost
0050 
0051 #endif // #ifndef BOOST_HASH2_DETAIL_MEMCMP_HPP_INCLUDED