Imported Upstream version 1.72.0
[platform/upstream/boost.git] / boost / gil / concepts / basic.hpp
1 //
2 // Copyright 2005-2007 Adobe Systems Incorporated
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_CONCEPTS_BASIC_HPP
9 #define BOOST_GIL_CONCEPTS_BASIC_HPP
10
11 #include <boost/config.hpp>
12
13 #if defined(BOOST_CLANG)
14 #pragma clang diagnostic push
15 #pragma clang diagnostic ignored "-Wunused-local-typedefs"
16 #pragma clang diagnostic ignored "-Wuninitialized"
17 #endif
18
19 #if defined(BOOST_GCC) && (BOOST_GCC >= 40900)
20 #pragma GCC diagnostic push
21 #pragma GCC diagnostic ignored "-Wunused-local-typedefs"
22 #pragma GCC diagnostic ignored "-Wuninitialized"
23 #endif
24
25 #include <boost/gil/concepts/concept_check.hpp>
26
27 #include <type_traits>
28 #include <utility> // std::swap
29
30 namespace boost { namespace gil {
31
32 /// \brief Concept of default construction requirement.
33 /// \code
34 /// auto concept DefaultConstructible<typename T>
35 /// {
36 ///     T::T();
37 /// };
38 /// \endcode
39 /// \ingroup BasicConcepts
40 ///
41 template <typename T>
42 struct DefaultConstructible
43 {
44     void constraints()
45     {
46         function_requires<boost::DefaultConstructibleConcept<T>>();
47     }
48 };
49
50 /// \brief Concept of copy construction requirement.
51 /// \code
52 /// auto concept CopyConstructible<typename T>
53 /// {
54 ///     T::T(T);
55 ///     T::~T();
56 /// };
57 /// \endcode
58 /// \ingroup BasicConcepts
59 ///
60 template <typename T>
61 struct CopyConstructible
62 {
63     void constraints()
64     {
65         function_requires<boost::CopyConstructibleConcept<T>>();
66     }
67 };
68
69 /// \brief Concept of copy assignment requirement.
70 /// \code
71 /// auto concept Assignable<typename T, typename U = T>
72 /// {
73 ///     typename result_type;
74 ///     result_type operator=(T&, U);
75 /// };
76 /// \endcode
77 /// \ingroup BasicConcepts
78 ///
79 template <typename T>
80 struct Assignable
81 {
82     void constraints()
83     {
84         function_requires<boost::AssignableConcept<T>>();
85     }
86 };
87
88 /// \brief Concept of == and != comparability requirement.
89 /// \code
90 /// auto concept EqualityComparable<typename T, typename U = T>
91 /// {
92 ///     bool operator==(T x, T y);
93 ///     bool operator!=(T x, T y) { return !(x==y); }
94 /// };
95 /// \endcode
96 /// \ingroup BasicConcepts
97 ///
98 template <typename T>
99 struct EqualityComparable
100 {
101     void constraints()
102     {
103         function_requires<boost::EqualityComparableConcept<T>>();
104     }
105 };
106
107 /// \brief Concept of swap operation requirement.
108 /// \code
109 /// auto concept Swappable<typename T>
110 /// {
111 ///     void swap(T&,T&);
112 /// };
113 /// \endcode
114 /// \ingroup BasicConcepts
115 ///
116 template <typename T>
117 struct Swappable
118 {
119     void constraints()
120     {
121         using std::swap;
122         swap(x,y);
123     }
124     T x,y;
125 };
126
127 /// \brief Concept for type regularity requirement.
128 /// \code
129 /// auto concept Regular<typename T>
130 ///     : DefaultConstructible<T>
131 ///     , CopyConstructible<T>
132 ///     , EqualityComparable<T>
133 ///     , Assignable<T>
134 ///     , Swappable<T>
135 /// {};
136 /// \endcode
137 /// \ingroup BasicConcepts
138 ///
139 template <typename T>
140 struct Regular
141 {
142     void constraints()
143     {
144         gil_function_requires< boost::DefaultConstructibleConcept<T>>();
145         gil_function_requires< boost::CopyConstructibleConcept<T>>();
146         gil_function_requires< boost::EqualityComparableConcept<T>>(); // ==, !=
147         gil_function_requires< boost::AssignableConcept<T>>();
148         gil_function_requires< Swappable<T>>();
149     }
150 };
151
152 /// \brief Concept for type as metafunction requirement.
153 /// \code
154 /// auto concept Metafunction<typename T>
155 /// {
156 ///     typename type;
157 /// };
158 /// \endcode
159 /// \ingroup BasicConcepts
160 ///
161 template <typename T>
162 struct Metafunction
163 {
164     void constraints()
165     {
166         using type = typename T::type;
167     }
168 };
169
170 /// \brief Concept of types equivalence requirement.
171 /// \code
172 /// auto concept SameType<typename T, typename U>; // unspecified
173 /// \endcode
174 /// \ingroup BasicConcepts
175 ///
176 template <typename T, typename U>
177 struct SameType
178 {
179     void constraints()
180     {
181         static_assert(std::is_same<T, U>::value, "");
182     }
183 };
184
185 }} // namespace boost::gil
186
187 #if defined(BOOST_CLANG)
188 #pragma clang diagnostic pop
189 #endif
190
191 #if defined(BOOST_GCC) && (BOOST_GCC >= 40900)
192 #pragma GCC diagnostic pop
193 #endif
194
195 #endif