is_channel_integral.cpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. //
  2. // Copyright 2019 Mateusz Loskot <mateusz at loskot dot net>
  3. //
  4. // Distributed under the Boost Software License, Version 1.0
  5. // See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt
  7. //
  8. #include <boost/gil/channel.hpp>
  9. #include <boost/gil/typedefs.hpp>
  10. #include <boost/gil/detail/is_channel_integral.hpp>
  11. #include <type_traits>
  12. namespace gil = boost::gil;
  13. int main()
  14. {
  15. static_assert(gil::detail::is_channel_integral
  16. <
  17. gil::packed_channel_value<1>
  18. >::value,
  19. "1-bit packed_channel_value should be recognized as integral");
  20. static_assert(gil::detail::is_channel_integral
  21. <
  22. gil::packed_channel_value<8>
  23. >::value,
  24. "8-bit packed_channel_value should be recognized as integral");
  25. static_assert(gil::detail::is_channel_integral
  26. <
  27. gil::packed_channel_reference
  28. <
  29. std::uint8_t, 0, 3, true
  30. >
  31. >::value,
  32. "3-bit packed_channel_reference should be recognized as integral");
  33. static_assert(gil::detail::is_channel_integral
  34. <
  35. gil::packed_dynamic_channel_reference
  36. <
  37. std::uint8_t, 2, true
  38. >
  39. >::value,
  40. "2-bit packed_dynamic_channel_reference should be recognized as integral");
  41. static_assert(gil::detail::is_channel_integral
  42. <
  43. gil::packed_dynamic_channel_reference
  44. <
  45. std::uint16_t, 15, true
  46. >
  47. >::value,
  48. "15-bit packed_dynamic_channel_reference should be recognized as integral");
  49. struct int_minus_value { static std::int8_t apply() { return -64; } };
  50. struct int_plus_value { static std::int8_t apply() { return 64; } };
  51. static_assert(gil::detail::is_channel_integral
  52. <
  53. gil::scoped_channel_value
  54. <
  55. std::uint8_t, int_minus_value, int_plus_value
  56. >
  57. >::value,
  58. "integer-based scoped_channel_value should be recognized as integral");
  59. static_assert(!gil::detail::is_channel_integral<gil::float32_t>::value,
  60. "float-based packed_channel_value should not be recognized as integral");
  61. static_assert(!gil::detail::is_channel_integral<gil::float64_t>::value,
  62. "float-based packed_channel_value should not be recognized as integral");
  63. }