Merge from mainline (165734:167278).
[official-gcc/graphite-test-results.git] / libstdc++-v3 / testsuite / 23_containers / unordered_set / insert / set_single_move.cc
blob0b9ad173b0f7a1885cb130e7e98878c49a65c4f7
1 // { dg-options "-std=gnu++0x" }
3 // 2010-10-27 Paolo Carlini <paolo.carlini@oracle.com>
4 //
5 // Copyright (C) 2010 Free Software Foundation, Inc.
6 //
7 // This file is part of the GNU ISO C++ Library. This library is free
8 // software; you can redistribute it and/or modify it under the
9 // terms of the GNU General Public License as published by the
10 // Free Software Foundation; either version 3, or (at your option)
11 // any later version.
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License along
19 // with this library; see the file COPYING3. If not see
20 // <http://www.gnu.org/licenses/>.
22 // Single-element insert
24 #include <iterator>
25 #include <unordered_set>
26 #include <testsuite_hooks.h>
27 #include <testsuite_rvalref.h>
29 void test01()
31 bool test __attribute__((unused)) = true;
32 using __gnu_test::rvalstruct;
34 typedef std::unordered_set<rvalstruct> Set;
35 Set s;
36 VERIFY( s.empty() );
38 std::pair<Set::iterator, bool> p = s.insert(rvalstruct(1));
39 VERIFY( p.second );
40 VERIFY( s.size() == 1 );
41 VERIFY( std::distance(s.begin(), s.end()) == 1 );
42 VERIFY( p.first == s.begin() );
43 VERIFY( (*p.first).val == 1 );
46 void test02()
48 bool test __attribute__((unused)) = true;
49 using __gnu_test::rvalstruct;
51 typedef std::unordered_set<rvalstruct> Set;
52 Set s;
53 VERIFY( s.empty() );
55 std::pair<Set::iterator, bool> p1 = s.insert(rvalstruct(2));
56 std::pair<Set::iterator, bool> p2 = s.insert(rvalstruct(2));
57 VERIFY( p1.second );
58 VERIFY( !p2.second );
59 VERIFY( s.size() == 1 );
60 VERIFY( p1.first == p2.first );
61 VERIFY( (*p1.first).val == 2 );
64 int main()
66 test01();
67 test02();
68 return 0;