Imported Upstream version 1.72.0
[platform/upstream/boost.git] / boost / gil / extension / toolbox / metafunctions / is_homogeneous.hpp
1 //
2 // Copyright 2012 Christian Henning, Andreas Pokorny, Lubomir Bourdev
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 #ifndef BOOST_GIL_EXTENSION_TOOLBOX_METAFUNCTIONS_IS_HOMOGENEOUS_HPP
9 #define BOOST_GIL_EXTENSION_TOOLBOX_METAFUNCTIONS_IS_HOMOGENEOUS_HPP
10
11 #include <boost/gil/pixel.hpp>
12 #include <boost/gil/detail/mp11.hpp>
13
14 #include <type_traits>
15
16 namespace boost{ namespace gil {
17
18 /// is_homogeneous metafunctions
19 /// \brief Determines if a pixel types are homogeneous.
20
21 template<typename C,typename CMP, int Next, int Last>
22 struct is_homogeneous_impl;
23
24 template<typename C, typename CMP, int Last>
25 struct is_homogeneous_impl<C, CMP, Last, Last> : std::true_type {};
26
27 template<typename C, typename CMP, int Next, int Last>
28 struct is_homogeneous_impl
29     : mp11::mp_and
30         <
31             is_homogeneous_impl<C, CMP, Next + 1, Last>,
32             std::is_same<CMP, mp11::mp_at_c<C, Next>>
33         >
34 {};
35
36 template <typename P>
37 struct is_homogeneous : std::false_type {};
38
39 // pixel
40 template <typename C, typename L>
41 struct is_homogeneous<pixel<C, L>> : std::true_type {};
42
43 template <typename C, typename L >
44 struct is_homogeneous<pixel<C, L> const> : std::true_type {};
45
46 template <typename C, typename L>
47 struct is_homogeneous<pixel<C, L>&> : std::true_type {};
48
49 template <typename C, typename L>
50 struct is_homogeneous<pixel<C, L> const&> : std::true_type {};
51
52 // planar pixel reference
53 template <typename Channel, typename ColorSpace>
54 struct is_homogeneous<planar_pixel_reference<Channel, ColorSpace>> : std::true_type {};
55
56 template <typename Channel, typename ColorSpace>
57 struct is_homogeneous<planar_pixel_reference<Channel, ColorSpace> const> : std::true_type {};
58
59 template<typename C, typename CMP, int I, int Last>
60 struct is_homogeneous_impl_p {};
61
62 // for packed_pixel
63 template <typename B, typename C, typename L>
64 struct is_homogeneous<packed_pixel<B, C, L>>
65     : is_homogeneous_impl_p
66     <
67         C,
68         mp11::mp_at_c<C, 0>,
69         1,
70         mp11::mp_size<C>::value
71     > {};
72
73 template< typename B
74         , typename C
75         , typename L
76         >
77 struct is_homogeneous<packed_pixel<B, C, L> const>
78     : is_homogeneous_impl_p
79     <
80         C,
81         mp11::mp_at_c<C, 0>,
82         1,
83         mp11::mp_size<C>::value
84     > {};
85
86 // for bit_aligned_pixel_reference
87 template <typename B, typename C, typename L, bool M>
88 struct is_homogeneous<bit_aligned_pixel_reference<B, C, L, M>>
89     : is_homogeneous_impl<C, mp11::mp_at_c<C, 0>, 1, mp11::mp_size<C>::value>
90 {};
91
92 template <typename B, typename C, typename L, bool M>
93 struct is_homogeneous<const bit_aligned_pixel_reference<B, C, L, M> >
94     : is_homogeneous_impl<C, mp11::mp_at_c<C, 0>, 1, mp11::mp_size<C>::value>
95 {};
96
97 }} // namespace boost::gil
98
99 #endif