39static int rw_opt_no_exceptions;
43typedef std::vector<UserClass, std::allocator<UserClass> >
Vector;
52 const Vector::size_type cap =
v.capacity ();
53 const Vector::size_type
size =
v.size ();
54 Vector::const_pointer begin =
size ? &
v [0] : 0;
63 "vector<UserClass>(%zu).reserve(%zu); capacity() == %zu, "
64 "got %zu", nelems, cap / 2, cap,
v.capacity ());
69 "vector<UserClass>(%zu).reserve(%zu) unexpectedly "
70 "reallocated", nelems, cap / 2);
78 "vector<UserClass>(%zu).reserve(%zu); capacity() == %zu, "
79 "got %zu", nelems, cap / 2, cap,
v.capacity ());
84 "vector<UserClass>(%zu).reserve(%zu) unexpectedly "
85 "reallocated", nelems, cap / 2);
93 rw_assert (
v.capacity () >= cap + 1, 0, __LINE__,
94 "vector<UserClass>(%zu).reserve(%zu); capacity() > %zu, got %zu",
95 nelems, cap + 1, cap,
v.capacity ());
99 "vector<UserClass>(%zu).reserve(); size() == %zu, got %zu",
100 nelems,
size,
v.size ());
104 "vector<UserClass>(%zu).reserve(%zu) complexity: "
105 "copy ctor called %zu times when size() = %zu",
113 for (Vector::size_type
i = 0;
i !=
v.capacity () -
size; ++
i) {
117 "vector<UserClass>(%zu).reserve(%zu); insertion of "
118 "element %zu unexpectedly reallocated; size() = %zu",
119 nelems, cap + 1,
v.size ());
123 if (rw_opt_no_exceptions)
126#ifndef _RWSTD_NO_EXCEPTIONS
131 Vector::size_type too_much =
v.max_size () + 1;
134 too_much =
v.max_size ();
137 v.reserve (too_much);
139 catch (std::length_error) {
143 caught =
"unknown exception";
147 "vector<UserClass>(%zu).reserve(%zu) "
148 "expected exception not thrown",
153 "vector<UserClass>(%zu).reserve(%zu) "
154 "expected length_error, got %s",
155 nelems, too_much,
caught);
166 rw_info (0, 0, 0,
"std::vector<UserClass>::capacity() const");
167 rw_info (0, 0, 0,
"std::vector<UserClass>::reserve(size_type)");
169 const Vector::size_type max_elems = Vector::size_type (rw_opt_nloops);
171 rw_note (0 == rw_opt_no_exceptions, 0, 0,
"exception test disabled");
173 for (Vector::size_type
i = 0;
i < max_elems; ++
i) {
182int main (
int argc,
char** argv)
184 return rw_test (argc, argv, __FILE__,
185 "lib.vector.capacity",
190 &rw_opt_no_exceptions,
std::vector< UserClass, std::allocator< UserClass > > Vector
void test_capacity(Vector::size_type nelems)
void run_test(const ForwardIterator &dummy, T *, Predicate *pred)
_TEST_EXPORT int rw_test(int argc, char *argv[], const char *filename, const char *clause, const char *comment, int(*testfun)(int, char **), const char *optspec,...)
_TEST_EXPORT int rw_info(int, const char *, int, const char *,...)
_TEST_EXPORT int rw_note(int, const char *, int, const char *,...)
_TEST_EXPORT int rw_assert(int, const char *, int, const char *,...)
static void reset_totals()
static _RWSTD_SIZE_T n_total_copy_ctor_