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