Imported Upstream version 1.72.0
[platform/upstream/boost.git] / libs / gil / test / core / pixel / concepts.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 // FIXME: Avoid Clang's flooding of non-disableable warnings like:
9 // "T does not declare any constructor to initialize its non-modifiable members"
10 // when compiling with concepts check enabled.
11 // See https://bugs.llvm.org/show_bug.cgi?id=41759
12 #if !defined(BOOST_GIL_USE_CONCEPT_CHECK) && !defined(__clang__)
13 #error Compile with BOOST_GIL_USE_CONCEPT_CHECK defined
14 #endif
15 #include <boost/gil.hpp>
16
17 #include <boost/concept_check.hpp>
18 #include <boost/mp11.hpp>
19
20 #include "test_fixture.hpp"
21
22 namespace gil = boost::gil;
23 namespace mp11 = boost::mp11;
24 using boost::function_requires;
25
26 template <template<typename> class Concept>
27 struct assert_concept
28 {
29     template <typename Pixel>
30     void operator()(Pixel&&)
31     {
32         function_requires<Concept<Pixel>>();
33     }
34 };
35
36 template <template<typename> class Concept, typename... Pixels>
37 void test_concept()
38 {
39     mp11::mp_for_each<Pixels...>(assert_concept<Concept>());
40 }
41
42 int main()
43 {
44     test_concept<gil::PixelConcept, gil::test::fixture::pixel_typedefs>();
45     test_concept<gil::MutablePixelConcept, gil::test::fixture::pixel_typedefs>();
46
47     using rgb565_pixel_t = gil::packed_pixel_type
48         <
49             std::uint16_t,
50             mp11::mp_list_c<unsigned, 5, 6, 5>,
51             gil::rgb_layout_t
52         >::type;
53     function_requires<gil::PixelConcept<rgb565_pixel_t>>();
54     function_requires<gil::PixelValueConcept<rgb565_pixel_t>>();
55
56     using bgr556_pixel_t = gil::packed_pixel_type
57         <
58             std::uint16_t,
59             mp11::mp_list_c<unsigned, 5, 6, 5>,
60             gil::bgr_layout_t>::type;
61     function_requires<gil::PixelConcept<bgr556_pixel_t>>();
62     function_requires<gil::PixelValueConcept<bgr556_pixel_t>>();
63
64     function_requires<gil::PixelsCompatibleConcept<rgb565_pixel_t, bgr556_pixel_t>>();
65
66     return 0;
67 }