InteroperableIterator.rst 4.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. .. Copyright David Abrahams 2006. Distributed under the Boost
  2. .. Software License, Version 1.0. (See accompanying
  3. .. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  4. Interoperable Iterator Concept
  5. ..............................
  6. A class or built-in type ``X`` that models Single Pass Iterator is
  7. *interoperable with* a class or built-in type ``Y`` that also models
  8. Single Pass Iterator if the following expressions are valid and
  9. respect the stated semantics. In the tables below, ``x`` is an object
  10. of type ``X``, ``y`` is an object of type ``Y``, ``Distance`` is
  11. ``iterator_traits<Y>::difference_type``, and ``n`` represents a
  12. constant object of type ``Distance``.
  13. +-----------+-----------------------+---------------------------------------------------+
  14. |Expression |Return Type |Assertion/Precondition/Postcondition |
  15. +===========+=======================+===================================================+
  16. |``y = x`` |``Y`` |post: ``y == x`` |
  17. +-----------+-----------------------+---------------------------------------------------+
  18. |``Y(x)`` |``Y`` |post: ``Y(x) == x`` |
  19. +-----------+-----------------------+---------------------------------------------------+
  20. |``x == y`` |convertible to ``bool``|``==`` is an equivalence relation over its domain. |
  21. +-----------+-----------------------+---------------------------------------------------+
  22. |``y == x`` |convertible to ``bool``|``==`` is an equivalence relation over its domain. |
  23. +-----------+-----------------------+---------------------------------------------------+
  24. |``x != y`` |convertible to ``bool``|``bool(a==b) != bool(a!=b)`` over its domain. |
  25. +-----------+-----------------------+---------------------------------------------------+
  26. |``y != x`` |convertible to ``bool``|``bool(a==b) != bool(a!=b)`` over its domain. |
  27. +-----------+-----------------------+---------------------------------------------------+
  28. If ``X`` and ``Y`` both model Random Access Traversal Iterator then
  29. the following additional requirements must be met.
  30. +-----------+-----------------------+---------------------+--------------------------------------+
  31. |Expression |Return Type |Operational Semantics|Assertion/ Precondition |
  32. +===========+=======================+=====================+======================================+
  33. |``x < y`` |convertible to ``bool``|``y - x > 0`` |``<`` is a total ordering relation |
  34. +-----------+-----------------------+---------------------+--------------------------------------+
  35. |``y < x`` |convertible to ``bool``|``x - y > 0`` |``<`` is a total ordering relation |
  36. +-----------+-----------------------+---------------------+--------------------------------------+
  37. |``x > y`` |convertible to ``bool``|``y < x`` |``>`` is a total ordering relation |
  38. +-----------+-----------------------+---------------------+--------------------------------------+
  39. |``y > x`` |convertible to ``bool``|``x < y`` |``>`` is a total ordering relation |
  40. +-----------+-----------------------+---------------------+--------------------------------------+
  41. |``x >= y`` |convertible to ``bool``|``!(x < y)`` | |
  42. +-----------+-----------------------+---------------------+--------------------------------------+
  43. |``y >= x`` |convertible to ``bool``|``!(y < x)`` | |
  44. +-----------+-----------------------+---------------------+--------------------------------------+
  45. |``x <= y`` |convertible to ``bool``|``!(x > y)`` | |
  46. +-----------+-----------------------+---------------------+--------------------------------------+
  47. |``y <= x`` |convertible to ``bool``|``!(y > x)`` | |
  48. +-----------+-----------------------+---------------------+--------------------------------------+
  49. |``y - x`` |``Distance`` |``distance(Y(x),y)`` |pre: there exists a value ``n`` of |
  50. | | | |``Distance`` such that ``x + n == y``.|
  51. | | | |``y == x + (y - x)``. |
  52. +-----------+-----------------------+---------------------+--------------------------------------+
  53. |``x - y`` |``Distance`` |``distance(y,Y(x))`` |pre: there exists a value ``n`` of |
  54. | | | |``Distance`` such that ``y + n == x``.|
  55. | | | |``x == y + (x - y)``. |
  56. +-----------+-----------------------+---------------------+--------------------------------------+