ref_problem.rst 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2. Problem with ``reference`` and old/new iterator category correspondance
  3. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  4. .. _N1550: http://www.boost-consulting.com/writing/n1550.html
  5. .. _N1530: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2003/n1530.html
  6. :Author: David Abrahams and Jeremy Siek
  7. :Contact: dave@boost-consulting.com, jsiek@osl.iu.edu
  8. :Organization: `Boost Consulting`_, Indiana University Bloomington
  9. :date: $Date$
  10. :Copyright: Copyright David Abrahams, Jeremy Siek 2003. Use, modification and
  11. distribution is subject to the Boost Software License,
  12. Version 1.0. (See accompanying file LICENSE_1_0.txt or copy
  13. at http://www.boost.org/LICENSE_1_0.txt)
  14. .. _`Boost Consulting`: http://www.boost-consulting.com
  15. ==============
  16. Introduction
  17. ==============
  18. The new iterator categories are intended to correspond to the old
  19. iterator categories, as specified in a diagram in N1550_. For example,
  20. an iterator categorized as a mutable Forward Iterator under the old
  21. scheme is now a Writable, Lvalue, and Foward Traversal iterator.
  22. However, there is a problem with this correspondance, the new iterator
  23. categories place requirements on the ``iterator_traits<X>::reference``
  24. type whereas the standard iterator requirements say nothing about the
  25. ``reference`` type . In particular, the new Readable Iterator
  26. requirements say that the return type of ``*a`` must be
  27. ``iterator_traits<X>::reference`` and the Lvalue Iterator requirements
  28. says that ``iterator_traits<X>::reference`` must be ``T&`` or ``const
  29. T&``.
  30. ====================
  31. Proposed Resolution
  32. ====================
  33. Change the standard requirements to match the requirements of the new
  34. iterators. (more details to come)
  35. ==========
  36. Rationale
  37. ==========
  38. The lack of specification in the standard of the ``reference`` type is
  39. certainly a defect. Without specification, it is entirely useless in a
  40. generic function. The current practice in the community is generally
  41. to assume there are requirements on the ``reference`` type, such as
  42. those proposed in the new iterator categories.
  43. There is some danger in *adding* requirements to existing concepts.
  44. This will mean that some existing iterator types will no longer meet
  45. the iterator requirements. However, we feel that the impact of this is
  46. small enough to warrant going ahead with this change.
  47. An alternative solution would be to leave the standard requirements as
  48. is, and to remove the requirements for the ``reference`` type in the
  49. new iterator concepts. We are not in favor of this approach because it
  50. extends what we see as a defect further into the future.