1*0a6a1f1dSLionel Sambuc //===----------------------------------------------------------------------===//
2*0a6a1f1dSLionel Sambuc //
3*0a6a1f1dSLionel Sambuc //                     The LLVM Compiler Infrastructure
4*0a6a1f1dSLionel Sambuc //
5*0a6a1f1dSLionel Sambuc // This file is dual licensed under the MIT and the University of Illinois Open
6*0a6a1f1dSLionel Sambuc // Source Licenses. See LICENSE.TXT for details.
7*0a6a1f1dSLionel Sambuc //
8*0a6a1f1dSLionel Sambuc //===----------------------------------------------------------------------===//
9*0a6a1f1dSLionel Sambuc 
10*0a6a1f1dSLionel Sambuc // <string>
11*0a6a1f1dSLionel Sambuc 
12*0a6a1f1dSLionel Sambuc // iterator insert(const_iterator p, charT c);
13*0a6a1f1dSLionel Sambuc 
14*0a6a1f1dSLionel Sambuc #if _LIBCPP_DEBUG >= 1
15*0a6a1f1dSLionel Sambuc #define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
16*0a6a1f1dSLionel Sambuc #endif
17*0a6a1f1dSLionel Sambuc 
18*0a6a1f1dSLionel Sambuc #include <string>
19*0a6a1f1dSLionel Sambuc #include <stdexcept>
20*0a6a1f1dSLionel Sambuc #include <cassert>
21*0a6a1f1dSLionel Sambuc 
22*0a6a1f1dSLionel Sambuc #include "min_allocator.h"
23*0a6a1f1dSLionel Sambuc 
24*0a6a1f1dSLionel Sambuc template <class S>
25*0a6a1f1dSLionel Sambuc void
test(S & s,typename S::const_iterator p,typename S::value_type c,S expected)26*0a6a1f1dSLionel Sambuc test(S& s, typename S::const_iterator p, typename S::value_type c, S expected)
27*0a6a1f1dSLionel Sambuc {
28*0a6a1f1dSLionel Sambuc     bool sufficient_cap = s.size() < s.capacity();
29*0a6a1f1dSLionel Sambuc     typename S::difference_type pos = p - s.begin();
30*0a6a1f1dSLionel Sambuc     typename S::iterator i = s.insert(p, c);
31*0a6a1f1dSLionel Sambuc     assert(s.__invariants());
32*0a6a1f1dSLionel Sambuc     assert(s == expected);
33*0a6a1f1dSLionel Sambuc     assert(i - s.begin() == pos);
34*0a6a1f1dSLionel Sambuc     assert(*i == c);
35*0a6a1f1dSLionel Sambuc     if (sufficient_cap)
36*0a6a1f1dSLionel Sambuc         assert(i == p);
37*0a6a1f1dSLionel Sambuc }
38*0a6a1f1dSLionel Sambuc 
main()39*0a6a1f1dSLionel Sambuc int main()
40*0a6a1f1dSLionel Sambuc {
41*0a6a1f1dSLionel Sambuc     {
42*0a6a1f1dSLionel Sambuc     typedef std::string S;
43*0a6a1f1dSLionel Sambuc     S s;
44*0a6a1f1dSLionel Sambuc     test(s, s.begin(), '1', S("1"));
45*0a6a1f1dSLionel Sambuc     test(s, s.begin(), 'a', S("a1"));
46*0a6a1f1dSLionel Sambuc     test(s, s.end(), 'b', S("a1b"));
47*0a6a1f1dSLionel Sambuc     test(s, s.end()-1, 'c', S("a1cb"));
48*0a6a1f1dSLionel Sambuc     test(s, s.end()-2, 'd', S("a1dcb"));
49*0a6a1f1dSLionel Sambuc     test(s, s.end()-3, '2', S("a12dcb"));
50*0a6a1f1dSLionel Sambuc     test(s, s.end()-4, '3', S("a132dcb"));
51*0a6a1f1dSLionel Sambuc     test(s, s.end()-5, '4', S("a1432dcb"));
52*0a6a1f1dSLionel Sambuc     test(s, s.begin()+1, '5', S("a51432dcb"));
53*0a6a1f1dSLionel Sambuc     test(s, s.begin()+2, '6', S("a561432dcb"));
54*0a6a1f1dSLionel Sambuc     test(s, s.begin()+3, '7', S("a5671432dcb"));
55*0a6a1f1dSLionel Sambuc     test(s, s.begin()+4, 'A', S("a567A1432dcb"));
56*0a6a1f1dSLionel Sambuc     test(s, s.begin()+5, 'B', S("a567AB1432dcb"));
57*0a6a1f1dSLionel Sambuc     test(s, s.begin()+6, 'C', S("a567ABC1432dcb"));
58*0a6a1f1dSLionel Sambuc     }
59*0a6a1f1dSLionel Sambuc #if __cplusplus >= 201103L
60*0a6a1f1dSLionel Sambuc     {
61*0a6a1f1dSLionel Sambuc     typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
62*0a6a1f1dSLionel Sambuc     S s;
63*0a6a1f1dSLionel Sambuc     test(s, s.begin(), '1', S("1"));
64*0a6a1f1dSLionel Sambuc     test(s, s.begin(), 'a', S("a1"));
65*0a6a1f1dSLionel Sambuc     test(s, s.end(), 'b', S("a1b"));
66*0a6a1f1dSLionel Sambuc     test(s, s.end()-1, 'c', S("a1cb"));
67*0a6a1f1dSLionel Sambuc     test(s, s.end()-2, 'd', S("a1dcb"));
68*0a6a1f1dSLionel Sambuc     test(s, s.end()-3, '2', S("a12dcb"));
69*0a6a1f1dSLionel Sambuc     test(s, s.end()-4, '3', S("a132dcb"));
70*0a6a1f1dSLionel Sambuc     test(s, s.end()-5, '4', S("a1432dcb"));
71*0a6a1f1dSLionel Sambuc     test(s, s.begin()+1, '5', S("a51432dcb"));
72*0a6a1f1dSLionel Sambuc     test(s, s.begin()+2, '6', S("a561432dcb"));
73*0a6a1f1dSLionel Sambuc     test(s, s.begin()+3, '7', S("a5671432dcb"));
74*0a6a1f1dSLionel Sambuc     test(s, s.begin()+4, 'A', S("a567A1432dcb"));
75*0a6a1f1dSLionel Sambuc     test(s, s.begin()+5, 'B', S("a567AB1432dcb"));
76*0a6a1f1dSLionel Sambuc     test(s, s.begin()+6, 'C', S("a567ABC1432dcb"));
77*0a6a1f1dSLionel Sambuc     }
78*0a6a1f1dSLionel Sambuc #endif
79*0a6a1f1dSLionel Sambuc #if _LIBCPP_DEBUG >= 1
80*0a6a1f1dSLionel Sambuc     {
81*0a6a1f1dSLionel Sambuc         typedef std::string S;
82*0a6a1f1dSLionel Sambuc         S s;
83*0a6a1f1dSLionel Sambuc         S s2;
84*0a6a1f1dSLionel Sambuc         s.insert(s2.begin(), '1');
85*0a6a1f1dSLionel Sambuc         assert(false);
86*0a6a1f1dSLionel Sambuc     }
87*0a6a1f1dSLionel Sambuc #endif
88*0a6a1f1dSLionel Sambuc }
89