memset.hpp 974 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #ifndef BOOST_HASH2_DETAIL_MEMSET_HPP_INCLUDED
  2. #define BOOST_HASH2_DETAIL_MEMSET_HPP_INCLUDED
  3. // Copyright 2024 Peter Dimov
  4. // Distributed under the Boost Software License, Version 1.0.
  5. // https://www.boost.org/LICENSE_1_0.txt
  6. #include <boost/hash2/detail/is_constant_evaluated.hpp>
  7. #include <boost/config.hpp>
  8. #include <cstring>
  9. namespace boost
  10. {
  11. namespace hash2
  12. {
  13. namespace detail
  14. {
  15. #if defined(BOOST_NO_CXX14_CONSTEXPR)
  16. BOOST_FORCEINLINE void memset( unsigned char* p, unsigned char v, std::size_t n ) noexcept
  17. {
  18. std::memset( p, v, n );
  19. }
  20. #else
  21. constexpr void memset( unsigned char* p, unsigned char v, std::size_t n ) noexcept
  22. {
  23. if( !detail::is_constant_evaluated() )
  24. {
  25. std::memset( p, v, n );
  26. }
  27. else
  28. {
  29. for( std::size_t i = 0; i < n; ++i )
  30. {
  31. p[ i ] = v;
  32. }
  33. }
  34. }
  35. #endif
  36. } // namespace detail
  37. } // namespace hash2
  38. } // namespace boost
  39. #endif // #ifndef BOOST_HASH2_DETAIL_MEMSET_HPP_INCLUDED