]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // Boost.Container static_vector |
2 | // Unit Test | |
3 | ||
4 | // Copyright (c) 2012-2013 Adam Wulkiewicz, Lodz, Poland. | |
5 | // Copyright (c) 2012-2013 Andrew Hundt. | |
6 | ||
7 | // Use, modification and distribution is subject to the Boost Software License, | |
8 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at | |
9 | // http://www.boost.org/LICENSE_1_0.txt) | |
10 | ||
11 | #ifndef BOOST_CONTAINER_TEST_STATIC_VECTOR_TEST_HPP | |
12 | #define BOOST_CONTAINER_TEST_STATIC_VECTOR_TEST_HPP | |
13 | ||
14 | #include <boost/container/static_vector.hpp> | |
15 | ||
7c673cae FG |
16 | #include "movable_int.hpp" |
17 | ||
18 | using namespace boost::container; | |
19 | ||
20 | class value_ndc | |
21 | { | |
22 | public: | |
23 | explicit value_ndc(int a) : aa(a) {} | |
24 | ~value_ndc() {} | |
25 | bool operator==(value_ndc const& v) const { return aa == v.aa; } | |
26 | bool operator<(value_ndc const& v) const { return aa < v.aa; } | |
27 | private: | |
28 | value_ndc(value_ndc const&) {} | |
29 | value_ndc & operator=(value_ndc const&) { return *this; } | |
30 | int aa; | |
31 | }; | |
32 | ||
33 | class value_nd | |
34 | { | |
35 | public: | |
36 | explicit value_nd(int a) : aa(a) {} | |
37 | ~value_nd() {} | |
38 | bool operator==(value_nd const& v) const { return aa == v.aa; } | |
39 | bool operator<(value_nd const& v) const { return aa < v.aa; } | |
40 | private: | |
41 | int aa; | |
42 | }; | |
43 | ||
44 | class value_nc | |
45 | { | |
46 | public: | |
47 | explicit value_nc(int a = 0) : aa(a) {} | |
48 | ~value_nc() {} | |
20effc67 | 49 | value_nc & operator=(int a){ aa = a; return *this; } |
7c673cae FG |
50 | bool operator==(value_nc const& v) const { return aa == v.aa; } |
51 | bool operator<(value_nc const& v) const { return aa < v.aa; } | |
52 | private: | |
53 | value_nc(value_nc const&) {} | |
20effc67 | 54 | value_nc & operator=(value_nc const&) { return *this; } |
7c673cae FG |
55 | int aa; |
56 | }; | |
57 | ||
58 | class counting_value | |
59 | { | |
60 | BOOST_COPYABLE_AND_MOVABLE(counting_value) | |
61 | ||
62 | public: | |
63 | explicit counting_value(int a = 0, int b = 0) : aa(a), bb(b) { ++c(); } | |
64 | counting_value(counting_value const& v) : aa(v.aa), bb(v.bb) { ++c(); } | |
65 | counting_value(BOOST_RV_REF(counting_value) p) : aa(p.aa), bb(p.bb) { p.aa = 0; p.bb = 0; ++c(); } // Move constructor | |
66 | counting_value& operator=(BOOST_RV_REF(counting_value) p) { aa = p.aa; p.aa = 0; bb = p.bb; p.bb = 0; return *this; } // Move assignment | |
67 | counting_value& operator=(BOOST_COPY_ASSIGN_REF(counting_value) p) { aa = p.aa; bb = p.bb; return *this; } // Copy assignment | |
20effc67 | 68 | counting_value& operator=(int a) { aa =a; return *this; } // Copy assignment |
7c673cae FG |
69 | ~counting_value() { --c(); } |
70 | bool operator==(counting_value const& v) const { return aa == v.aa && bb == v.bb; } | |
71 | bool operator<(counting_value const& v) const { return aa < v.aa || ( aa == v.aa && bb < v.bb ); } | |
72 | static size_t count() { return c(); } | |
73 | ||
74 | private: | |
75 | static size_t & c() { static size_t co = 0; return co; } | |
76 | int aa, bb; | |
77 | }; | |
78 | ||
79 | namespace boost { | |
80 | ||
81 | template <class T> | |
82 | struct has_nothrow_move; | |
83 | ||
84 | template <> | |
85 | struct has_nothrow_move<counting_value> | |
86 | { | |
87 | static const bool value = true; | |
88 | }; | |
89 | ||
90 | } | |
91 | ||
7c673cae | 92 | #endif // BOOST_CONTAINER_TEST_STATIC_VECTOR_TEST_HPP |