]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/ext/vstring/init-list.cc
Add initializer_list support as per N2679.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / ext / vstring / init-list.cc
1 // Copyright (C) 2008 Free Software Foundation, Inc.
2 //
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 2, or (at your option)
7 // any later version.
8 //
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING. If not, write to the Free
16 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
17 // USA.
18 //
19 // As a special exception, you may use this file as part of a free software
20 // library without restriction. Specifically, if other files instantiate
21 // templates or use macros or inline functions from this file, or you compile
22 // this file and link it with other files to produce an executable, this
23 // file does not by itself cause the resulting executable to be covered by
24 // the GNU General Public License. This exception does not however
25 // invalidate any other reasons why the executable file might be covered by
26 // the GNU General Public License.
27
28 // { dg-options "-std=gnu++0x" }
29
30 #include <ext/vstring.h>
31 #include <testsuite_hooks.h>
32
33 int test01(void)
34 {
35 bool test = true;
36
37 __gnu_cxx::__vstring s1 = { 'a', 'b', 'c' };
38 VERIFY(s1 == "abc");
39
40 s1 = { 'd', 'e', 'f' };
41 VERIFY(s1 == "def");
42
43 s1 += { 'g', 'h', 'i' };
44 VERIFY(s1 == "defghi");
45
46 s1.append({ 'j', 'k', 'l' });
47 VERIFY(s1 == "defghijkl");
48
49 s1.assign({ 'm', 'n', 'o' });
50 VERIFY(s1 == "mno");
51
52 // There aren't actually overloads of insert and replace taking size_type
53 // and initializer_list, but test the usage anyway.
54 s1.insert(2, { 'p', 'q', 'r' });
55 VERIFY(s1 == "mnpqro");
56
57 s1.replace(2, 3, { 's', 't', 'u' });
58 VERIFY(s1 == "mnstuo");
59
60 __gnu_cxx::__vstring::iterator i1, i2;
61
62 i1 = s1.begin()+2;
63 s1.insert(i1, { 'v', 'w', 'x' });
64 VERIFY(s1 == "mnvwxstuo");
65
66 i1 = s1.begin()+2;
67 i2 = i1+6;
68 s1.replace(i1, i2, { 'y', 'z' });
69 VERIFY(s1 == "mnyzo");
70
71 return test;
72 }
73
74 int main()
75 {
76 __gnu_test::set_memory_limits();
77 test01();
78 return 0;
79 }