14684ddb6SLionel Sambuc //===----------------------------------------------------------------------===//
24684ddb6SLionel Sambuc //
34684ddb6SLionel Sambuc // The LLVM Compiler Infrastructure
44684ddb6SLionel Sambuc //
54684ddb6SLionel Sambuc // This file is dual licensed under the MIT and the University of Illinois Open
64684ddb6SLionel Sambuc // Source Licenses. See LICENSE.TXT for details.
74684ddb6SLionel Sambuc //
84684ddb6SLionel Sambuc //===----------------------------------------------------------------------===//
94684ddb6SLionel Sambuc
104684ddb6SLionel Sambuc // <string>
114684ddb6SLionel Sambuc
124684ddb6SLionel Sambuc // void reserve(size_type res_arg=0);
134684ddb6SLionel Sambuc
144684ddb6SLionel Sambuc #include <string>
154684ddb6SLionel Sambuc #include <stdexcept>
164684ddb6SLionel Sambuc #include <cassert>
174684ddb6SLionel Sambuc
18*0a6a1f1dSLionel Sambuc #include "min_allocator.h"
194684ddb6SLionel Sambuc
204684ddb6SLionel Sambuc template <class S>
214684ddb6SLionel Sambuc void
test(S s)224684ddb6SLionel Sambuc test(S s)
234684ddb6SLionel Sambuc {
244684ddb6SLionel Sambuc typename S::size_type old_cap = s.capacity();
254684ddb6SLionel Sambuc S s0 = s;
264684ddb6SLionel Sambuc s.reserve();
274684ddb6SLionel Sambuc assert(s.__invariants());
284684ddb6SLionel Sambuc assert(s == s0);
294684ddb6SLionel Sambuc assert(s.capacity() <= old_cap);
304684ddb6SLionel Sambuc assert(s.capacity() >= s.size());
314684ddb6SLionel Sambuc }
324684ddb6SLionel Sambuc
334684ddb6SLionel Sambuc template <class S>
344684ddb6SLionel Sambuc void
test(S s,typename S::size_type res_arg)354684ddb6SLionel Sambuc test(S s, typename S::size_type res_arg)
364684ddb6SLionel Sambuc {
374684ddb6SLionel Sambuc typename S::size_type old_cap = s.capacity();
384684ddb6SLionel Sambuc S s0 = s;
394684ddb6SLionel Sambuc try
404684ddb6SLionel Sambuc {
414684ddb6SLionel Sambuc s.reserve(res_arg);
424684ddb6SLionel Sambuc assert(res_arg <= s.max_size());
434684ddb6SLionel Sambuc assert(s == s0);
444684ddb6SLionel Sambuc assert(s.capacity() >= res_arg);
454684ddb6SLionel Sambuc assert(s.capacity() >= s.size());
464684ddb6SLionel Sambuc }
474684ddb6SLionel Sambuc catch (std::length_error&)
484684ddb6SLionel Sambuc {
494684ddb6SLionel Sambuc assert(res_arg > s.max_size());
504684ddb6SLionel Sambuc }
514684ddb6SLionel Sambuc }
524684ddb6SLionel Sambuc
main()534684ddb6SLionel Sambuc int main()
544684ddb6SLionel Sambuc {
554684ddb6SLionel Sambuc {
564684ddb6SLionel Sambuc typedef std::string S;
574684ddb6SLionel Sambuc {
584684ddb6SLionel Sambuc S s;
594684ddb6SLionel Sambuc test(s);
604684ddb6SLionel Sambuc
614684ddb6SLionel Sambuc s.assign(10, 'a');
624684ddb6SLionel Sambuc s.erase(5);
634684ddb6SLionel Sambuc test(s);
644684ddb6SLionel Sambuc
654684ddb6SLionel Sambuc s.assign(100, 'a');
664684ddb6SLionel Sambuc s.erase(50);
674684ddb6SLionel Sambuc test(s);
684684ddb6SLionel Sambuc }
694684ddb6SLionel Sambuc {
704684ddb6SLionel Sambuc S s;
714684ddb6SLionel Sambuc test(s, 5);
724684ddb6SLionel Sambuc test(s, 10);
734684ddb6SLionel Sambuc test(s, 50);
744684ddb6SLionel Sambuc }
754684ddb6SLionel Sambuc {
764684ddb6SLionel Sambuc S s(100, 'a');
774684ddb6SLionel Sambuc s.erase(50);
784684ddb6SLionel Sambuc test(s, 5);
794684ddb6SLionel Sambuc test(s, 10);
804684ddb6SLionel Sambuc test(s, 50);
814684ddb6SLionel Sambuc test(s, 100);
824684ddb6SLionel Sambuc test(s, S::npos);
834684ddb6SLionel Sambuc }
844684ddb6SLionel Sambuc }
854684ddb6SLionel Sambuc #if __cplusplus >= 201103L
864684ddb6SLionel Sambuc {
874684ddb6SLionel Sambuc typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
884684ddb6SLionel Sambuc {
894684ddb6SLionel Sambuc S s;
904684ddb6SLionel Sambuc test(s);
914684ddb6SLionel Sambuc
924684ddb6SLionel Sambuc s.assign(10, 'a');
934684ddb6SLionel Sambuc s.erase(5);
944684ddb6SLionel Sambuc test(s);
954684ddb6SLionel Sambuc
964684ddb6SLionel Sambuc s.assign(100, 'a');
974684ddb6SLionel Sambuc s.erase(50);
984684ddb6SLionel Sambuc test(s);
994684ddb6SLionel Sambuc }
1004684ddb6SLionel Sambuc {
1014684ddb6SLionel Sambuc S s;
1024684ddb6SLionel Sambuc test(s, 5);
1034684ddb6SLionel Sambuc test(s, 10);
1044684ddb6SLionel Sambuc test(s, 50);
1054684ddb6SLionel Sambuc }
1064684ddb6SLionel Sambuc {
1074684ddb6SLionel Sambuc S s(100, 'a');
1084684ddb6SLionel Sambuc s.erase(50);
1094684ddb6SLionel Sambuc test(s, 5);
1104684ddb6SLionel Sambuc test(s, 10);
1114684ddb6SLionel Sambuc test(s, 50);
1124684ddb6SLionel Sambuc test(s, 100);
1134684ddb6SLionel Sambuc test(s, S::npos);
1144684ddb6SLionel Sambuc }
1154684ddb6SLionel Sambuc }
1164684ddb6SLionel Sambuc #endif
1174684ddb6SLionel Sambuc }
118