Daily bump.
[gcc.git] / libstdc++-v3 / testsuite / 23_containers / deque / modifiers / emplace / 1.cc
blobc6b0318e5ea2f8026f2d440f8c8c197442840195
1 // { dg-do run { target c++11 } }
3 #include <deque>
4 #include <testsuite_hooks.h>
6 void
7 test01()
9 std::deque<int> c;
10 std::deque<int>::iterator pos;
12 // libstdc++/52799
13 pos = c.emplace(c.begin());
14 VERIFY( c.size() == 1 );
15 VERIFY( c[0] == 0 );
16 VERIFY( pos == c.begin() );
17 pos = c.emplace(c.begin(), 2);
18 VERIFY( c.size() == 2 );
19 VERIFY( c[0] == 2 );
20 VERIFY( c[1] == 0 );
21 VERIFY( pos == c.begin() );
22 pos = c.emplace(c.end(), 3);
23 VERIFY( c.size() == 3 );
24 VERIFY( c[0] == 2 );
25 VERIFY( c[1] == 0 );
26 VERIFY( c[2] == 3 );
27 VERIFY( pos == --c.end() );
29 // const_iterator
30 pos = c.emplace(c.cbegin());
31 VERIFY( c.size() == 4 );
32 VERIFY( c[0] == 0 );
33 VERIFY( c[1] == 2 );
34 VERIFY( pos == c.cbegin() );
35 pos = c.emplace(c.cbegin() + 2, 22);
36 VERIFY( c.size() == 5 );
37 VERIFY( c[0] == 0 );
38 VERIFY( c[1] == 2 );
39 VERIFY( c[2] == 22 );
40 VERIFY( pos == c.cbegin() + 2 );
43 struct V
45 explicit V(int a, int b = 0) : val(a+b) { }
46 int val;
49 void
50 test02()
52 std::deque<V> c;
53 std::deque<V>::iterator pos;
55 pos = c.emplace(c.end(), 1);
56 VERIFY( c.size() == 1 );
57 VERIFY( c[0].val == 1 );
58 VERIFY( pos == --c.end() );
59 pos = c.emplace(c.cend(), 2, 3);
60 VERIFY( c.size() == 2 );
61 VERIFY( c[0].val == 1 );
62 VERIFY( c[1].val == 5 );
63 VERIFY( pos == --c.cend() );
66 int main()
68 test01();
69 test02();