basic.hpp 4.1 KB

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