integral_by_size.hpp 948 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #ifndef BOOST_ENDIAN_DETAIL_INTEGRAL_BY_SIZE_HPP_INCLUDED
  2. #define BOOST_ENDIAN_DETAIL_INTEGRAL_BY_SIZE_HPP_INCLUDED
  3. // Copyright 2019 Peter Dimov
  4. //
  5. // Distributed under the Boost Software License, Version 1.0.
  6. // http://www.boost.org/LICENSE_1_0.txt
  7. #include <cstdint>
  8. #include <cstddef>
  9. namespace boost
  10. {
  11. namespace endian
  12. {
  13. namespace detail
  14. {
  15. template<std::size_t N> struct integral_by_size
  16. {
  17. };
  18. template<> struct integral_by_size<1>
  19. {
  20. typedef std::uint8_t type;
  21. };
  22. template<> struct integral_by_size<2>
  23. {
  24. typedef std::uint16_t type;
  25. };
  26. template<> struct integral_by_size<4>
  27. {
  28. typedef std::uint32_t type;
  29. };
  30. template<> struct integral_by_size<8>
  31. {
  32. typedef std::uint64_t type;
  33. };
  34. #if defined(__SIZEOF_INT128__)
  35. template<> struct integral_by_size<16>
  36. {
  37. typedef __uint128_t type;
  38. };
  39. #endif
  40. } // namespace detail
  41. } // namespace endian
  42. } // namespace boost
  43. #endif // BOOST_ENDIAN_DETAIL_INTEGRAL_BY_SIZE_HPP_INCLUDED