const_container.hpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. //
  2. // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. // Official repository: https://github.com/boostorg/beast
  8. //
  9. #ifndef BOOST_BEAST_UNIT_TEST_DETAIL_CONST_CONTAINER_HPP
  10. #define BOOST_BEAST_UNIT_TEST_DETAIL_CONST_CONTAINER_HPP
  11. namespace boost {
  12. namespace beast {
  13. namespace unit_test {
  14. namespace detail {
  15. /** Adapter to constrain a container interface.
  16. The interface allows for limited read only operations. Derived classes
  17. provide additional behavior.
  18. */
  19. template<class Container>
  20. class const_container
  21. {
  22. private:
  23. using cont_type = Container;
  24. cont_type m_cont;
  25. protected:
  26. cont_type& cont()
  27. {
  28. return m_cont;
  29. }
  30. cont_type const& cont() const
  31. {
  32. return m_cont;
  33. }
  34. public:
  35. using value_type = typename cont_type::value_type;
  36. using size_type = typename cont_type::size_type;
  37. using difference_type = typename cont_type::difference_type;
  38. using iterator = typename cont_type::const_iterator;
  39. using const_iterator = typename cont_type::const_iterator;
  40. /** Returns `true` if the container is empty. */
  41. bool
  42. empty() const
  43. {
  44. return m_cont.empty();
  45. }
  46. /** Returns the number of items in the container. */
  47. size_type
  48. size() const
  49. {
  50. return m_cont.size();
  51. }
  52. /** Returns forward iterators for traversal. */
  53. /** @{ */
  54. const_iterator
  55. begin() const
  56. {
  57. return m_cont.cbegin();
  58. }
  59. const_iterator
  60. cbegin() const
  61. {
  62. return m_cont.cbegin();
  63. }
  64. const_iterator
  65. end() const
  66. {
  67. return m_cont.cend();
  68. }
  69. const_iterator
  70. cend() const
  71. {
  72. return m_cont.cend();
  73. }
  74. /** @} */
  75. };
  76. } // detail
  77. } // unit_test
  78. } // beast
  79. } // boost
  80. #endif