basic.hpp 4.1 KB

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