pixels_are_compatible.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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/pixel.hpp>
  9. #include <boost/gil/concepts/pixel.hpp>
  10. #include <boost/gil/typedefs.hpp>
  11. #include <boost/mp11.hpp>
  12. #include <type_traits>
  13. namespace gil = boost::gil;
  14. using namespace boost::mp11;
  15. template <typename Pixel>
  16. struct assert_compatible
  17. {
  18. template <typename CompatiblePixel>
  19. void operator()(CompatiblePixel&&)
  20. {
  21. using result_t = typename gil::pixels_are_compatible<Pixel, CompatiblePixel>::type;
  22. static_assert(result_t::value, "pixels should be compatible");
  23. // TODO: Refine after MPL -> MP11 switch
  24. static_assert(
  25. std::is_same<result_t, std::true_type>::value,
  26. "pixels_are_compatible result type should be std::true_type");
  27. static_assert(
  28. !std::is_same<result_t, std::false_type>::value,
  29. "pixels_are_compatible result type should no be std::false_type");
  30. }
  31. };
  32. template <typename Pixel>
  33. struct assert_not_compatible
  34. {
  35. template <typename NotCompatiblePixel>
  36. void operator()(NotCompatiblePixel&&)
  37. {
  38. static_assert(
  39. !gil::pixels_are_compatible<Pixel, NotCompatiblePixel>::value,
  40. "pixels should not be compatible");
  41. }
  42. };
  43. template <typename Pixel, typename... CompatiblePixels>
  44. void test_compatible()
  45. {
  46. mp_for_each<CompatiblePixels...>(assert_compatible<Pixel>());
  47. }
  48. template <typename Pixel, typename... CompatiblePixels>
  49. void test_not_compatible()
  50. {
  51. mp_for_each<CompatiblePixels...>(assert_not_compatible<Pixel>());
  52. }
  53. int main()
  54. {
  55. test_compatible<gil::gray8_pixel_t, mp_list<
  56. gil::gray8_pixel_t,
  57. gil::gray8c_pixel_t>>();
  58. test_compatible<gil::gray8s_pixel_t, mp_list<
  59. gil::gray8s_pixel_t,
  60. gil::gray8sc_pixel_t>>();
  61. test_not_compatible<gil::gray8_pixel_t, mp_list<
  62. gil::gray8s_pixel_t,
  63. gil::gray8sc_pixel_t>>();
  64. test_compatible<gil::gray16_pixel_t, mp_list<
  65. gil::gray16_pixel_t,
  66. gil::gray16c_pixel_t>>();
  67. test_compatible<gil::gray16s_pixel_t, mp_list<
  68. gil::gray16s_pixel_t,
  69. gil::gray16sc_pixel_t>>();
  70. test_not_compatible<gil::gray16_pixel_t, mp_list<
  71. gil::gray16s_pixel_t,
  72. gil::gray16sc_pixel_t>>();
  73. test_compatible<gil::rgb8_pixel_t, mp_list<
  74. gil::bgr8_pixel_t,
  75. gil::bgr8c_pixel_t,
  76. gil::rgb8_pixel_t,
  77. gil::rgb8c_pixel_t>>();
  78. test_compatible<gil::rgb8s_pixel_t, mp_list<
  79. gil::bgr8s_pixel_t,
  80. gil::bgr8sc_pixel_t,
  81. gil::rgb8s_pixel_t,
  82. gil::rgb8sc_pixel_t>>();
  83. test_not_compatible<gil::rgb8_pixel_t, mp_list<
  84. gil::argb8_pixel_t,
  85. gil::abgr8_pixel_t,
  86. gil::rgba8_pixel_t,
  87. gil::bgr8s_pixel_t,
  88. gil::bgr8sc_pixel_t,
  89. gil::rgb8s_pixel_t,
  90. gil::rgb8sc_pixel_t>>();
  91. test_compatible<gil::rgba8_pixel_t, mp_list<
  92. gil::abgr8_pixel_t,
  93. gil::argb8_pixel_t,
  94. gil::bgra8_pixel_t,
  95. gil::bgra8c_pixel_t,
  96. gil::rgba8_pixel_t,
  97. gil::rgba8c_pixel_t>>();
  98. test_not_compatible<gil::rgba8_pixel_t, mp_list<
  99. gil::rgb8_pixel_t,
  100. gil::rgb16_pixel_t,
  101. gil::rgba16_pixel_t,
  102. gil::cmyk8_pixel_t,
  103. gil::cmyk16_pixel_t>>();
  104. test_compatible<gil::cmyk8_pixel_t, mp_list<
  105. gil::cmyk8_pixel_t,
  106. gil::cmyk8c_pixel_t>>();
  107. test_compatible<gil::cmyk8s_pixel_t, mp_list<
  108. gil::cmyk8s_pixel_t,
  109. gil::cmyk8sc_pixel_t>>();
  110. test_not_compatible<gil::cmyk8_pixel_t, mp_list<
  111. gil::cmyk8s_pixel_t,
  112. gil::cmyk8sc_pixel_t>>();
  113. test_compatible<gil::cmyk32f_pixel_t, mp_list<
  114. gil::cmyk32f_pixel_t,
  115. gil::cmyk32fc_pixel_t>>();
  116. }