1119381Sjake// Copyright (C) 2013-2015 Free Software Foundation, Inc.
2146480Smarius//
3146480Smarius// This file is part of the GNU ISO C++ Library.  This library is free
4146480Smarius// software; you can redistribute it and/or modify it under the
5146480Smarius// terms of the GNU General Public License as published by the
6146480Smarius// Free Software Foundation; either version 3, or (at your option)
7146480Smarius// any later version.
8146480Smarius
9146480Smarius// This library is distributed in the hope that it will be useful,
10146480Smarius// but WITHOUT ANY WARRANTY; without even the implied warranty of
11146480Smarius// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12146480Smarius// GNU General Public License for more details.
13146480Smarius
14146480Smarius// You should have received a copy of the GNU General Public License along
15146480Smarius// with this library; see the file COPYING3.  If not see
16146480Smarius// <http://www.gnu.org/licenses/>.
17146480Smarius
18146480Smarius// { dg-options "-std=gnu++11" }
19146480Smarius
20146480Smarius#include <unordered_map>
21146480Smarius#include <testsuite_hooks.h>
22146480Smarius#include <testsuite_allocator.h>
23146480Smarius#include <testsuite_counter_type.h>
24119381Sjake
25119381Sjakeusing __gnu_test::propagating_allocator;
26119381Sjakeusing __gnu_test::counter_type;
27119381Sjake
28119381Sjakevoid test01()
29119381Sjake{
30119381Sjake  bool test __attribute__((unused)) = true;
31119381Sjake  typedef propagating_allocator<counter_type, false> alloc_type;
32119381Sjake  typedef __gnu_test::counter_type_hasher hash;
33119381Sjake  typedef std::unordered_multimap<counter_type, counter_type, hash,
34119381Sjake				  std::equal_to<counter_type>,
35119381Sjake				  alloc_type> test_type;
36119381Sjake
37119381Sjake  test_type v1(alloc_type(1));
38119381Sjake  v1.emplace(std::piecewise_construct,
39119381Sjake	     std::make_tuple(1), std::make_tuple(1));
40119381Sjake
41119381Sjake  test_type v2(alloc_type(2));
42119381Sjake  v2.emplace(std::piecewise_construct,
43119381Sjake	     std::make_tuple(2), std::make_tuple(2));
44119381Sjake
45119381Sjake  counter_type::reset();
46119381Sjake
47119381Sjake  v2 = std::move(v1);
48119381Sjake
49119381Sjake  VERIFY( 1 == v1.get_allocator().get_personality() );
50119381Sjake  VERIFY( 2 == v2.get_allocator().get_personality() );
51166059Smarius
52166059Smarius  // No move because key is const.
53119381Sjake  VERIFY( counter_type::move_assign_count == 0  );
54119381Sjake}
55119381Sjake
56166059Smariusvoid test02()
57119381Sjake{
58166059Smarius  bool test __attribute__((unused)) = true;
59166059Smarius  typedef propagating_allocator<counter_type, true> alloc_type;
60166059Smarius  typedef __gnu_test::counter_type_hasher hash;
61166059Smarius  typedef std::unordered_multimap<counter_type, counter_type, hash,
62166059Smarius				  std::equal_to<counter_type>,
63166059Smarius				  alloc_type> test_type;
64166059Smarius
65166059Smarius  test_type v1(alloc_type(1));
66166059Smarius  v1.emplace(std::piecewise_construct,
67166059Smarius	     std::make_tuple(1), std::make_tuple(1));
68166059Smarius
69166059Smarius  auto it = v1.begin();
70166059Smarius
71166059Smarius  test_type v2(alloc_type(2));
72166059Smarius  v2.emplace(std::piecewise_construct,
73119381Sjake	     std::make_tuple(2), std::make_tuple(2));
74119381Sjake
75119381Sjake  counter_type::reset();
76119381Sjake
77119381Sjake  v2 = std::move(v1);
78146480Smarius
79146480Smarius  VERIFY(0 == v1.get_allocator().get_personality());
80146480Smarius  VERIFY(1 == v2.get_allocator().get_personality());
81146480Smarius
82146480Smarius  VERIFY( counter_type::move_assign_count == 0 );
83146480Smarius  VERIFY( counter_type::destructor_count == 2 );
84146480Smarius
85146480Smarius  VERIFY( it == v2.begin() );
86146480Smarius}
87146480Smarius
88146480Smariusint main()
89146480Smarius{
90146480Smarius  test01();
91146480Smarius  test02();
92146480Smarius  return 0;
93146480Smarius}
94146480Smarius