vector_adaptor.hpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. // Boost.Bimap
  2. //
  3. // Copyright (c) 2006-2007 Matias Capeletto
  4. //
  5. // Distributed under the Boost Software License, Version 1.0.
  6. // (See accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. /// \file container_adaptor/vector_adaptor.hpp
  9. /// \brief Container adaptor to easily build a std::vector signature compatible container.
  10. #ifndef BOOST_BIMAP_CONTAINER_ADAPTOR_VECTOR_ADAPTOR_HPP
  11. #define BOOST_BIMAP_CONTAINER_ADAPTOR_VECTOR_ADAPTOR_HPP
  12. #if defined(_MSC_VER)
  13. #pragma once
  14. #endif
  15. #include <boost/config.hpp>
  16. #include <boost/bimap/container_adaptor/sequence_container_adaptor.hpp>
  17. #include <boost/mpl/aux_/na.hpp>
  18. #include <boost/mpl/vector.hpp>
  19. namespace boost {
  20. namespace bimaps {
  21. namespace container_adaptor {
  22. /// \brief Container adaptor to easily build a std::vector signature compatible container.
  23. template
  24. <
  25. class Base,
  26. class Iterator,
  27. class ConstIterator,
  28. class ReverseIterator,
  29. class ConstReverseIterator,
  30. class IteratorToBaseConverter = ::boost::mpl::na,
  31. class IteratorFromBaseConverter = ::boost::mpl::na,
  32. class ReverseIteratorFromBaseConverter = ::boost::mpl::na,
  33. class ValueToBaseConverter = ::boost::mpl::na,
  34. class ValueFromBaseConverter = ::boost::mpl::na,
  35. class FunctorsFromDerivedClasses = mpl::vector<>
  36. >
  37. class vector_adaptor :
  38. public ::boost::bimaps::container_adaptor::sequence_container_adaptor
  39. <
  40. Base,
  41. Iterator, ConstIterator, ReverseIterator, ConstReverseIterator,
  42. IteratorToBaseConverter, IteratorFromBaseConverter,
  43. ReverseIteratorFromBaseConverter,
  44. ValueToBaseConverter, ValueFromBaseConverter,
  45. FunctorsFromDerivedClasses
  46. >
  47. {
  48. typedef ::boost::bimaps::container_adaptor::sequence_container_adaptor
  49. <
  50. Base,
  51. Iterator, ConstIterator, ReverseIterator, ConstReverseIterator,
  52. IteratorToBaseConverter, IteratorFromBaseConverter,
  53. ReverseIteratorFromBaseConverter,
  54. ValueToBaseConverter, ValueFromBaseConverter,
  55. FunctorsFromDerivedClasses
  56. > base_;
  57. // Access -----------------------------------------------------------------
  58. public:
  59. vector_adaptor() {}
  60. explicit vector_adaptor(Base & c) :
  61. base_(c) {}
  62. protected:
  63. typedef vector_adaptor vector_adaptor_;
  64. // Interface --------------------------------------------------------------
  65. public:
  66. BOOST_DEDUCED_TYPENAME base_::size_type capacity() const
  67. {
  68. return this->base().capacity();
  69. }
  70. void reserve(BOOST_DEDUCED_TYPENAME base_::size_type m)
  71. {
  72. this->base().resize(m);
  73. }
  74. void resize(BOOST_DEDUCED_TYPENAME base_::size_type n,
  75. BOOST_DEDUCED_TYPENAME ::boost::call_traits<
  76. BOOST_DEDUCED_TYPENAME base_::value_type >::param_type x =
  77. BOOST_DEDUCED_TYPENAME base_::value_type())
  78. {
  79. this->base().resize(n,
  80. this->template functor<BOOST_DEDUCED_TYPENAME base_::value_to_base>()(x)
  81. );
  82. }
  83. BOOST_DEDUCED_TYPENAME base_::const_reference
  84. operator[](BOOST_DEDUCED_TYPENAME base_::size_type n) const
  85. {
  86. return this->template functor<BOOST_DEDUCED_TYPENAME base_::value_from_base>()(
  87. this->base().operator[](n)
  88. );
  89. }
  90. BOOST_DEDUCED_TYPENAME base_::const_reference
  91. at(BOOST_DEDUCED_TYPENAME base_::size_type n) const
  92. {
  93. return this->template functor<BOOST_DEDUCED_TYPENAME base_::value_from_base>()(
  94. this->base().at(n)
  95. );
  96. }
  97. BOOST_DEDUCED_TYPENAME base_::reference
  98. operator[](BOOST_DEDUCED_TYPENAME base_::size_type n)
  99. {
  100. return this->template functor<BOOST_DEDUCED_TYPENAME base_::value_from_base>()(
  101. this->base().operator[](n)
  102. );
  103. }
  104. BOOST_DEDUCED_TYPENAME base_::reference
  105. at(BOOST_DEDUCED_TYPENAME base_::size_type n)
  106. {
  107. return this->template functor<BOOST_DEDUCED_TYPENAME base_::value_from_base>()(
  108. this->base().at(n)
  109. );
  110. }
  111. };
  112. } // namespace container_adaptor
  113. } // namespace bimaps
  114. } // namespace boost
  115. #endif // BOOST_BIMAP_CONTAINER_ADAPTOR_VECTOR_ADAPTOR_HPP