]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/23_containers/unordered_set/insert/set_single.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 23_containers / unordered_set / insert / set_single.cc
1 // { dg-do run { target c++11 } }
2
3 // Copyright (C) 2010-2022 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
9 // any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING3. If not see
18 // <http://www.gnu.org/licenses/>.
19
20 // Single-element insert
21
22 #include <string>
23 #include <iterator>
24 #include <unordered_set>
25 #include <testsuite_hooks.h>
26
27 void test01()
28 {
29 typedef std::unordered_set<std::string> Set;
30 Set s;
31 VERIFY(s.empty());
32
33 std::pair<Set::iterator, bool> p = s.insert("abcde");
34 VERIFY(p.second);
35 VERIFY(s.size() == 1);
36 VERIFY(std::distance(s.begin(), s.end()) == 1);
37 VERIFY(p.first == s.begin());
38 VERIFY(*p.first == "abcde");
39 }
40
41 void test02()
42 {
43 typedef std::unordered_set<std::string> Set;
44 Set s;
45 VERIFY(s.empty());
46
47 std::pair<Set::iterator, bool> p1 = s.insert("abcde");
48 std::pair<Set::iterator, bool> p2 = s.insert("abcde");
49 VERIFY(p1.second);
50 VERIFY(!p2.second);
51 VERIFY(s.size() == 1);
52 VERIFY(p1.first == p2.first);
53 VERIFY(*p1.first == "abcde");
54 }
55
56 int main()
57 {
58 test01();
59 test02();
60 return 0;
61 }