2010-05-11 19:42:16 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
//
|
2019-01-19 10:56:40 +00:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2010-05-11 19:42:16 +00:00
|
|
|
//
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
|
|
// <string>
|
|
|
|
|
|
|
|
|
|
// size_type capacity() const;
|
|
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <cassert>
|
|
|
|
|
|
2013-12-03 00:18:10 +00:00
|
|
|
#include "test_allocator.h"
|
2013-11-26 20:58:02 +00:00
|
|
|
#include "min_allocator.h"
|
2010-05-11 19:42:16 +00:00
|
|
|
|
2016-11-29 16:40:19 +00:00
|
|
|
#include "test_macros.h"
|
|
|
|
|
|
2010-05-11 19:42:16 +00:00
|
|
|
template <class S>
|
|
|
|
|
void
|
|
|
|
|
test(S s)
|
|
|
|
|
{
|
|
|
|
|
S::allocator_type::throw_after = 0;
|
2016-11-29 16:40:19 +00:00
|
|
|
#ifndef TEST_HAS_NO_EXCEPTIONS
|
2010-05-11 19:42:16 +00:00
|
|
|
try
|
2016-11-29 16:40:19 +00:00
|
|
|
#endif
|
2010-05-11 19:42:16 +00:00
|
|
|
{
|
|
|
|
|
while (s.size() < s.capacity())
|
|
|
|
|
s.push_back(typename S::value_type());
|
|
|
|
|
assert(s.size() == s.capacity());
|
|
|
|
|
}
|
2016-11-29 16:40:19 +00:00
|
|
|
#ifndef TEST_HAS_NO_EXCEPTIONS
|
2010-05-11 19:42:16 +00:00
|
|
|
catch (...)
|
|
|
|
|
{
|
|
|
|
|
assert(false);
|
|
|
|
|
}
|
2016-11-29 16:40:19 +00:00
|
|
|
#endif
|
2010-05-11 19:42:16 +00:00
|
|
|
S::allocator_type::throw_after = INT_MAX;
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-04 20:31:13 +00:00
|
|
|
int main(int, char**)
|
2010-05-11 19:42:16 +00:00
|
|
|
{
|
2013-06-28 16:59:19 +00:00
|
|
|
{
|
2010-05-11 19:42:16 +00:00
|
|
|
typedef std::basic_string<char, std::char_traits<char>, test_allocator<char> > S;
|
|
|
|
|
S s;
|
|
|
|
|
test(s);
|
|
|
|
|
s.assign(10, 'a');
|
|
|
|
|
s.erase(5);
|
|
|
|
|
test(s);
|
|
|
|
|
s.assign(100, 'a');
|
|
|
|
|
s.erase(50);
|
|
|
|
|
test(s);
|
2013-06-28 16:59:19 +00:00
|
|
|
}
|
2016-06-14 21:31:42 +00:00
|
|
|
#if TEST_STD_VER >= 11
|
2013-06-28 16:59:19 +00:00
|
|
|
{
|
|
|
|
|
typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
|
|
|
|
|
S s;
|
|
|
|
|
assert(s.capacity() > 0);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2019-02-04 20:31:13 +00:00
|
|
|
|
|
|
|
|
return 0;
|
2010-05-11 19:42:16 +00:00
|
|
|
}
|