concepts.rst 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. Concepts
  2. ========
  3. All constructs in GIL are models of GIL concepts. A *concept* is a set of
  4. requirements that a type (or a set of related types) must fulfill to be used
  5. correctly in generic algorithms. The requirements include syntactic and
  6. algorithmic guarantees. For example, GIL class ``pixel`` is a model of GIL
  7. ``PixelConcept``. The user may substitute the pixel class with one of their
  8. own, and, as long as it satisfies the requirements of ``PixelConcept``,
  9. all other GIL classes and algorithms can be used with it.
  10. See more about concepts is avaialble at
  11. `Generic Programming in ConceptC++ <https://web.archive.org/web/20160324115943/http://www.generic-programming.org/languages/conceptcpp/>`_
  12. In this document we will use a syntax for defining concepts that is described
  13. in the C++ standard proposal paper
  14. `[N2081] Concepts <http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2081.pdf>`_.
  15. Here are some common concepts that will be used in GIL.
  16. Most of them are defined at the
  17. `ConceptC++ Concept Web <https://web.archive.org/web/20160326060858/http://www.generic-programming.org/languages/conceptcpp/concept_web.php>`_:
  18. .. code-block:: cpp
  19. auto concept DefaultConstructible<typename T>
  20. {
  21. T::T();
  22. };
  23. auto concept CopyConstructible<typename T>
  24. {
  25. T::T(T);
  26. T::~T();
  27. };
  28. auto concept Assignable<typename T, typename U = T>
  29. {
  30. typename result_type;
  31. result_type operator=(T&, U);
  32. };
  33. auto concept EqualityComparable<typename T, typename U = T>
  34. {
  35. bool operator==(T x, T y);
  36. bool operator!=(T x, T y) { return !(x==y); }
  37. };
  38. concept SameType<typename T, typename U> { /* unspecified */ };
  39. template<typename T> concept_map SameType<T, T> { /* unspecified */ };
  40. auto concept Swappable<typename T>
  41. {
  42. void swap(T& t, T& u);
  43. };
  44. Here are some additional basic concepts that GIL needs:
  45. .. code-block:: cpp
  46. auto concept Regular<typename T> :
  47. DefaultConstructible<T>,
  48. CopyConstructible<T>,
  49. EqualityComparable<T>,
  50. Assignable<T>,
  51. Swappable<T>
  52. {};
  53. auto concept Metafunction<typename T>
  54. {
  55. typename type;
  56. };