Make printers use singular noun for a single element
[official-gcc.git] / libstdc++-v3 / testsuite / libstdc++-prettyprinters / cxx11.cc
blobe02997a5f798ce11f021360bb1cf73fd81dfade6
1 // { dg-do run { target c++11 } }
2 // { dg-options "-g -O0" }
4 // Copyright (C) 2011-2016 Free Software Foundation, Inc.
5 //
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 3, or (at your option)
10 // any later version.
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING3. If not see
19 // <http://www.gnu.org/licenses/>.
21 #include <forward_list>
22 #include <unordered_map>
23 #include <unordered_set>
24 #include <string>
25 #include <memory>
26 #include <iostream>
28 typedef std::tuple<int, int> ExTuple;
30 template<class T>
31 void
32 placeholder(const T &s)
34 std::cout << s;
37 template<class T, class S>
38 void
39 placeholder(const std::pair<T,S> &s)
41 std::cout << s.first;
44 template<class T>
45 void
46 use(const T &container)
48 for (typename T::const_iterator i = container.begin();
49 i != container.end();
50 ++i)
51 placeholder(*i);
54 struct datum
56 std::string s;
57 int i;
60 std::unique_ptr<datum> global;
62 int
63 main()
65 std::forward_list<int> efl;
66 // { dg-final { note-test efl "empty std::forward_list" } }
68 std::forward_list<int> &refl = efl;
69 // { dg-final { note-test refl "empty std::forward_list" } }
71 std::forward_list<int> fl;
72 fl.push_front(2);
73 fl.push_front(1);
74 // { dg-final { note-test fl {std::forward_list = {[0] = 1, [1] = 2}} } }
76 std::forward_list<int> &rfl = fl;
77 // { dg-final { note-test rfl {std::forward_list = {[0] = 1, [1] = 2}} } }
79 std::unordered_map<int, std::string> eum;
80 // { dg-final { note-test eum "std::unordered_map with 0 elements" } }
81 std::unordered_map<int, std::string> &reum = eum;
82 // { dg-final { note-test reum "std::unordered_map with 0 elements" } }
84 std::unordered_multimap<int, std::string> eumm;
85 // { dg-final { note-test eumm "std::unordered_multimap with 0 elements" } }
86 std::unordered_multimap<int, std::string> &reumm = eumm;
87 // { dg-final { note-test reumm "std::unordered_multimap with 0 elements" } }
89 std::unordered_set<int> eus;
90 // { dg-final { note-test eus "std::unordered_set with 0 elements" } }
91 std::unordered_set<int> &reus = eus;
92 // { dg-final { note-test reus "std::unordered_set with 0 elements" } }
94 std::unordered_multiset<int> eums;
95 // { dg-final { note-test eums "std::unordered_multiset with 0 elements" } }
96 std::unordered_multiset<int> &reums = eums;
97 // { dg-final { note-test reums "std::unordered_multiset with 0 elements" } }
99 std::unordered_map<int, std::string> uom;
100 uom[5] = "three";
101 uom[3] = "seven";
102 // { dg-final { note-test uom {std::unordered_map with 2 elements = {[3] = "seven", [5] = "three"}} } }
104 std::unordered_map<int, std::string> &ruom = uom;
105 // { dg-final { note-test ruom {std::unordered_map with 2 elements = {[3] = "seven", [5] = "three"}} } }
107 std::unordered_multimap<int, std::string> uomm;
108 uomm.insert(std::pair<int, std::string> (5, "three"));
109 uomm.insert(std::pair<int, std::string> (5, "seven"));
110 // { dg-final { note-test uomm {std::unordered_multimap with 2 elements = {[5] = "seven", [5] = "three"}} } }
111 std::unordered_multimap<int, std::string> &ruomm = uomm;
112 // { dg-final { note-test ruomm {std::unordered_multimap with 2 elements = {[5] = "seven", [5] = "three"}} } }
114 std::unordered_set<int> uos;
115 uos.insert(5);
116 // { dg-final { note-test uos {std::unordered_set with 1 element = {[0] = 5}} } }
117 std::unordered_set<int> &ruos = uos;
118 // { dg-final { note-test ruos {std::unordered_set with 1 element = {[0] = 5}} } }
120 std::unordered_multiset<int> uoms;
121 uoms.insert(5);
122 // { dg-final { note-test uoms {std::unordered_multiset with 1 element = {[0] = 5}} } }
123 std::unordered_multiset<int> &ruoms = uoms;
124 // { dg-final { note-test ruoms {std::unordered_multiset with 1 element = {[0] = 5}} } }
126 std::unique_ptr<datum> uptr (new datum);
127 uptr->s = "hi bob";
128 uptr->i = 23;
129 // { dg-final { regexp-test uptr {std::unique_ptr.datum. containing 0x.*} } }
130 std::unique_ptr<datum> &ruptr = uptr;
131 // { dg-final { regexp-test ruptr {std::unique_ptr.datum. containing 0x.*} } }
133 ExTuple tpl(6,7);
134 // { dg-final { note-test tpl {std::tuple containing = {[1] = 6, [2] = 7}} } }
135 ExTuple &rtpl = tpl;
136 // { dg-final { note-test rtpl {std::tuple containing = {[1] = 6, [2] = 7}} } }
137 placeholder(""); // Mark SPOT
138 use(efl);
139 use(fl);
140 use(eum);
141 use(eumm);
142 use(eus);
143 use(eums);
144 use(uoms);
145 use(uptr->s);
147 std::cout << "\n";
148 return 0;
151 // { dg-final { gdb-test SPOT } }