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