OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libstdc++-v3/] [testsuite/] [23_containers/] [unordered_multimap/] [insert/] [51866.cc] - Blame information for rev 749

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 742 jeremybenn
// { dg-options "-std=gnu++0x" }
2
//
3
// Copyright (C) 2012 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
#include <unordered_map>
21
#include <testsuite_hooks.h>
22
 
23
struct num
24
{
25
  int value;
26
  num(int n)                 : value(n) {}
27
  num(num const&)            = default;
28
  num& operator=(num const&) = default;
29
  num(num&& o)               : value(o.value)
30
  { o.value = -1; }
31
  num& operator=(num&& o)
32
  {
33
    if (this != &o)
34
      {
35
        value = o.value;
36
        o.value = -1;
37
      }
38
    return *this;
39
  }
40
};
41
 
42
struct num_hash
43
{
44
  size_t operator()(num const& a) const
45
  { return a.value; }
46
};
47
 
48
struct num_equal
49
{
50
  static bool _S_called_on_moved_instance;
51
  bool operator()(num const& a, num const& b) const
52
  {
53
    if (a.value == -1 || b.value == -1)
54
      _S_called_on_moved_instance = true;
55
    return a.value == b.value;
56
  }
57
};
58
 
59
bool num_equal::_S_called_on_moved_instance = false;
60
 
61
// libstdc++/51866
62
void test01()
63
{
64
  bool test __attribute__((unused)) = true;
65
 
66
  std::unordered_multimap<num, int, num_hash, num_equal> mmap;
67
  mmap.insert(std::make_pair(num(1), 1));
68
  mmap.insert(std::make_pair(num(2), 2));
69
  mmap.insert(std::make_pair(num(1), 3));
70
  mmap.insert(std::make_pair(num(2), 4));
71
  VERIFY( mmap.size() == 4 );
72
  auto iter = mmap.cbegin();
73
  auto x0 = (iter++)->first.value;
74
  auto x1 = (iter++)->first.value;
75
  auto x2 = (iter++)->first.value;
76
  auto x3 = (iter++)->first.value;
77
  VERIFY( iter == mmap.cend() );
78
  VERIFY( (x0 == 1 && x1 == 1 && x2 == 2 && x3 == 2)
79
          || (x0 == 2 && x1 == 2 && x2 == 1 && x3 == 1) );
80
  VERIFY( !num_equal::_S_called_on_moved_instance );
81
}
82
 
83
int main()
84
{
85
  test01();
86
  return 0;
87
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.