pointee.rst 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. .. 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. ++++++++++++++++++++++++++++++++++++++++
  5. ``pointee`` and ``indirect_reference``
  6. ++++++++++++++++++++++++++++++++++++++++
  7. :Author: David Abrahams
  8. :Contact: dave@boost-consulting.com
  9. :organization: `Boost Consulting`_
  10. :date: $Date$
  11. :copyright: Copyright David Abrahams 2004.
  12. .. _`Boost Consulting`: http://www.boost-consulting.com
  13. :abstract: Provides the capability to deduce the referent types of
  14. pointers, smart pointers and iterators in generic code.
  15. Overview
  16. ========
  17. Have you ever wanted to write a generic function that can operate
  18. on any kind of dereferenceable object? If you have, you've
  19. probably run into the problem of how to determine the type that the
  20. object "points at":
  21. .. parsed-literal::
  22. template <class Dereferenceable>
  23. void f(Dereferenceable p)
  24. {
  25. *what-goes-here?* value = \*p;
  26. ...
  27. }
  28. ``pointee``
  29. -----------
  30. It turns out to be impossible to come up with a fully-general
  31. algorithm to do determine *what-goes-here* directly, but it is
  32. possible to require that ``pointee<Dereferenceable>::type`` is
  33. correct. Naturally, ``pointee`` has the same difficulty: it can't
  34. determine the appropriate ``::type`` reliably for all
  35. ``Dereferenceable``\ s, but it makes very good guesses (it works
  36. for all pointers, standard and boost smart pointers, and
  37. iterators), and when it guesses wrongly, it can be specialized as
  38. necessary::
  39. namespace boost
  40. {
  41. template <class T>
  42. struct pointee<third_party_lib::smart_pointer<T> >
  43. {
  44. typedef T type;
  45. };
  46. }
  47. ``indirect_reference``
  48. ----------------------
  49. ``indirect_reference<T>::type`` is rather more specialized than
  50. ``pointee``, and is meant to be used to forward the result of
  51. dereferencing an object of its argument type. Most dereferenceable
  52. types just return a reference to their pointee, but some return
  53. proxy references or return the pointee by value. When that
  54. information is needed, call on ``indirect_reference``.
  55. Both of these templates are essential to the correct functioning of
  56. |indirect_iterator|_.
  57. .. |indirect_iterator| replace:: ``indirect_iterator``
  58. .. _indirect_iterator: indirect_iterator.html
  59. Reference
  60. =========
  61. ``pointee``
  62. -----------
  63. .. include:: pointee_ref.rst
  64. ``indirect_reference``
  65. ----------------------
  66. .. include:: indirect_reference_ref.rst