compressed_pair.qbk 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. [/
  2. Copyright 2000 Beman Dawes & John Maddock.
  3. Distributed under the Boost Software License, Version 1.0.
  4. See accompanying file LICENSE_1_0.txt
  5. or copy at http://boost.org/LICENSE_1_0.txt
  6. ]
  7. [article Compressed_Pair
  8. [quickbook 1.5]
  9. [authors [Cleary, Steve]]
  10. [authors [Dawes, Beman]]
  11. [authors [Hinnant, Howard]]
  12. [authors [Maddock, John]]
  13. [copyright 2000 Steve Cleary, Beman Dawes, Howard Hinnant & John Maddock]
  14. [license
  15. Distributed under the Boost Software License, Version 1.0.
  16. (See accompanying file LICENSE_1_0.txt or copy at
  17. [@http://www.boost.org/LICENSE_1_0.txt])
  18. ]
  19. ]
  20. [section Overview]
  21. All of the contents of `<boost/compressed_pair.hpp>` are defined inside
  22. `namespace boost`.
  23. The class `compressed_pair` is very similar to `std::pair`, but if either of
  24. the template arguments are empty classes, then the ['empty base-class
  25. optimisation] is applied to compress the size of the pair.
  26. [endsect]
  27. [section Synopsis]
  28. template <class T1, class T2>
  29. class compressed_pair
  30. {
  31. public:
  32. typedef T1 first_type;
  33. typedef T2 second_type;
  34. typedef typename call_traits<first_type>::param_type first_param_type;
  35. typedef typename call_traits<second_type>::param_type second_param_type;
  36. typedef typename call_traits<first_type>::reference first_reference;
  37. typedef typename call_traits<second_type>::reference second_reference;
  38. typedef typename call_traits<first_type>::const_reference first_const_reference;
  39. typedef typename call_traits<second_type>::const_reference second_const_reference;
  40. compressed_pair() : base() {}
  41. compressed_pair(first_param_type x, second_param_type y);
  42. explicit compressed_pair(first_param_type x);
  43. explicit compressed_pair(second_param_type y);
  44. compressed_pair& operator=(const compressed_pair&);
  45. first_reference first();
  46. first_const_reference first() const;
  47. second_reference second();
  48. second_const_reference second() const;
  49. void swap(compressed_pair& y);
  50. };
  51. The two members of the pair can be accessed using the member functions
  52. `first()` and `second()`. Note that not all member functions can be
  53. instantiated for all template parameter types. In particular
  54. `compressed_pair` can be instantiated for reference and array types,
  55. however in these cases the range of constructors that can be used are
  56. limited. If types `T1` and `T2` are the same type, then there is only
  57. one version of the single-argument constructor, and this constructor
  58. initialises both values in the pair to the passed value.
  59. Note that if either member is a POD type, then that member is not
  60. zero-initialized by the `compressed_pair` default constructor: it's up
  61. to you to supply an initial value for these types if you want them to have
  62. a default value.
  63. Note that `compressed_pair` can not be instantiated if either of the
  64. template arguments is a union type, unless there is compiler support for
  65. `boost::is_union`, or if `boost::is_union` is specialised for the union
  66. type.
  67. Finally, a word of caution for Visual C++ 6 users: if either argument is an
  68. empty type, then assigning to that member will produce memory corruption,
  69. unless the empty type has a "do nothing" assignment operator defined. This
  70. is due to a bug in the way VC6 generates implicit assignment operators.
  71. [endsect]
  72. [section Acknowledgments]
  73. Based on contributions by Steve Cleary, Beman Dawes, Howard Hinnant and
  74. John Maddock.
  75. Maintained by [@mailto:john@johnmaddock.co.uk John Maddock].
  76. [endsect]