|
8 | 8 | //
|
9 | 9 | //////////////////////////////////////////////////////////////////////////////
|
10 | 10 | #include <boost/container/small_vector.hpp>
|
| 11 | +#include <boost/container/allocator.hpp> |
11 | 12 | #include <boost/core/lightweight_test.hpp>
|
12 | 13 | #include <boost/assert.hpp>
|
13 | 14 | using namespace boost::container;
|
@@ -100,11 +101,58 @@ void test_growth_factor_100()
|
100 | 101 | BOOST_TEST(new_capacity == 2*old_capacity);
|
101 | 102 | }
|
102 | 103 |
|
| 104 | +template<class Unsigned, class VectorType> |
| 105 | +void test_stored_size_type_impl() |
| 106 | +{ |
| 107 | + #ifndef BOOST_NO_EXCEPTIONS |
| 108 | + VectorType v; |
| 109 | + typedef typename VectorType::size_type size_type; |
| 110 | + typedef typename VectorType::value_type value_type; |
| 111 | + size_type const max = Unsigned(-1); |
| 112 | + v.resize(5); |
| 113 | + v.resize(max); |
| 114 | + BOOST_TEST_THROWS(v.resize(max+1), std::exception); |
| 115 | + BOOST_TEST_THROWS(v.push_back(value_type(1)), std::exception); |
| 116 | + BOOST_TEST_THROWS(v.insert(v.begin(), value_type(1)), std::exception); |
| 117 | + BOOST_TEST_THROWS(v.emplace(v.begin(), value_type(1)),std::exception); |
| 118 | + BOOST_TEST_THROWS(v.reserve(max+1), std::exception); |
| 119 | + BOOST_TEST_THROWS(VectorType v2(max+1), std::exception); |
| 120 | + #endif |
| 121 | +} |
| 122 | + |
| 123 | +template<class Unsigned> |
| 124 | +void test_stored_size_type() |
| 125 | +{ |
| 126 | + #if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES) |
| 127 | + using options_t = small_vector_options_t< stored_size<Unsigned> >; |
| 128 | + #else |
| 129 | + typedef typename small_vector_options |
| 130 | + < stored_size<Unsigned> >::type options_t; |
| 131 | + #endif |
| 132 | + |
| 133 | + typedef small_vector<unsigned char, Unsigned(-1)> normal_small_vector_t; |
| 134 | + |
| 135 | + //Test first with a typical allocator |
| 136 | + { |
| 137 | + typedef small_vector<unsigned char, Unsigned(-1), new_allocator<unsigned char>, options_t> small_vector_t; |
| 138 | + test_stored_size_type_impl<Unsigned, small_vector_t>(); |
| 139 | + BOOST_CONTAINER_STATIC_ASSERT(sizeof(normal_small_vector_t) > sizeof(small_vector_t)); |
| 140 | + } |
| 141 | + //Test with a V2 allocator |
| 142 | + { |
| 143 | + typedef small_vector<unsigned char, Unsigned(-1), allocator<unsigned char>, options_t> small_vector_t; |
| 144 | + test_stored_size_type_impl<Unsigned, small_vector_t>(); |
| 145 | + BOOST_CONTAINER_STATIC_ASSERT(sizeof(normal_small_vector_t) > sizeof(small_vector_t)); |
| 146 | + } |
| 147 | +} |
| 148 | + |
103 | 149 | int main()
|
104 | 150 | {
|
105 | 151 | test_alignment();
|
106 | 152 | test_growth_factor_50();
|
107 | 153 | test_growth_factor_60();
|
108 | 154 | test_growth_factor_100();
|
| 155 | + test_stored_size_type<unsigned char>(); |
| 156 | + test_stored_size_type<unsigned short>(); |
109 | 157 | return ::boost::report_errors();
|
110 | 158 | }
|
0 commit comments