]>
Commit | Line | Data |
---|---|---|
7c673cae | 1 | // |
b32b8144 | 2 | // Copyright (c) 2016-2017 Vinnie Falco (vinnie dot falco at gmail dot com) |
7c673cae FG |
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 | // | |
b32b8144 FG |
7 | // Official repository: https://github.com/boostorg/beast |
8 | // | |
7c673cae | 9 | |
b32b8144 FG |
10 | #ifndef BOOST_BEAST_UNIT_TEST_DETAIL_CONST_CONTAINER_HPP |
11 | #define BOOST_BEAST_UNIT_TEST_DETAIL_CONST_CONTAINER_HPP | |
7c673cae | 12 | |
b32b8144 | 13 | namespace boost { |
7c673cae FG |
14 | namespace beast { |
15 | namespace unit_test { | |
16 | namespace detail { | |
17 | ||
18 | /** Adapter to constrain a container interface. | |
19 | The interface allows for limited read only operations. Derived classes | |
20 | provide additional behavior. | |
21 | */ | |
22 | template<class Container> | |
23 | class const_container | |
24 | { | |
25 | private: | |
26 | using cont_type = Container; | |
27 | ||
28 | cont_type m_cont; | |
29 | ||
30 | protected: | |
31 | cont_type& cont() | |
32 | { | |
33 | return m_cont; | |
34 | } | |
35 | ||
36 | cont_type const& cont() const | |
37 | { | |
38 | return m_cont; | |
39 | } | |
40 | ||
41 | public: | |
42 | using value_type = typename cont_type::value_type; | |
43 | using size_type = typename cont_type::size_type; | |
44 | using difference_type = typename cont_type::difference_type; | |
45 | using iterator = typename cont_type::const_iterator; | |
46 | using const_iterator = typename cont_type::const_iterator; | |
47 | ||
48 | /** Returns `true` if the container is empty. */ | |
49 | bool | |
50 | empty() const | |
51 | { | |
52 | return m_cont.empty(); | |
53 | } | |
54 | ||
55 | /** Returns the number of items in the container. */ | |
56 | size_type | |
57 | size() const | |
58 | { | |
59 | return m_cont.size(); | |
60 | } | |
61 | ||
62 | /** Returns forward iterators for traversal. */ | |
63 | /** @{ */ | |
64 | const_iterator | |
65 | begin() const | |
66 | { | |
67 | return m_cont.cbegin(); | |
68 | } | |
69 | ||
70 | const_iterator | |
71 | cbegin() const | |
72 | { | |
73 | return m_cont.cbegin(); | |
74 | } | |
75 | ||
76 | const_iterator | |
77 | end() const | |
78 | { | |
79 | return m_cont.cend(); | |
80 | } | |
81 | ||
82 | const_iterator | |
83 | cend() const | |
84 | { | |
85 | return m_cont.cend(); | |
86 | } | |
87 | /** @} */ | |
88 | }; | |
89 | ||
90 | } // detail | |
91 | } // unit_test | |
92 | } // beast | |
b32b8144 | 93 | } // boost |
7c673cae FG |
94 | |
95 | #endif |