3 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2011
4 // Free Software Foundation, Inc.
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 terms
8 // of the GNU General Public License as published by the Free Software
9 // Foundation; either version 3, or (at your option) any later
12 // This library is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // Under Section 7 of GPL version 3, you are granted additional
18 // permissions described in the GCC Runtime Library Exception, version
19 // 3.1, as published by the Free Software Foundation.
21 // You should have received a copy of the GNU General Public License and
22 // a copy of the GCC Runtime Library Exception along with this program;
23 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 // <http://www.gnu.org/licenses/>.
26 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
28 // Permission to use, copy, modify, sell, and distribute this software
29 // is hereby granted without fee, provided that the above copyright
30 // notice appears in all copies, and that both that copyright notice
31 // and this permission notice appear in supporting documentation. None
32 // of the above authors, nor IBM Haifa Research Laboratories, make any
33 // representation about the suitability of this software for any
34 // purpose. It is provided "as is" without express or implied
38 * @file binary_heap_/constructors_destructor_fn_imps.hpp
39 * Contains an implementation class for binary_heap_.
43 typename PB_DS_CLASS_C_DEC::entry_allocator
44 PB_DS_CLASS_C_DEC::s_entry_allocator;
47 typename PB_DS_CLASS_C_DEC::value_allocator
48 PB_DS_CLASS_C_DEC::s_value_allocator;
51 typename PB_DS_CLASS_C_DEC::no_throw_copies_t
52 PB_DS_CLASS_C_DEC::s_no_throw_copies_ind;
58 copy_from_range(It first_it, It last_it)
60 while (first_it != last_it)
62 insert_value(*first_it, s_no_throw_copies_ind);
66 PB_DS_ASSERT_VALID((*this))
72 : m_size(0), m_actual_size(resize_policy::min_size),
73 m_a_entries(s_entry_allocator.allocate(m_actual_size))
74 { PB_DS_ASSERT_VALID((*this)) }
78 binary_heap(const Cmp_Fn& r_cmp_fn)
79 : entry_cmp(r_cmp_fn), m_size(0), m_actual_size(resize_policy::min_size),
80 m_a_entries(s_entry_allocator.allocate(m_actual_size))
81 { PB_DS_ASSERT_VALID((*this)) }
85 binary_heap(const PB_DS_CLASS_C_DEC& other)
86 : entry_cmp(other), resize_policy(other), m_size(0),
87 m_actual_size(other.m_actual_size),
88 m_a_entries(s_entry_allocator.allocate(m_actual_size))
90 PB_DS_ASSERT_VALID(other)
91 _GLIBCXX_DEBUG_ASSERT(m_a_entries != other.m_a_entries);
95 copy_from_range(other.begin(), other.end());
99 for (size_type i = 0; i < m_size; ++i)
100 erase_at(m_a_entries, i, s_no_throw_copies_ind);
102 s_entry_allocator.deallocate(m_a_entries, m_actual_size);
103 __throw_exception_again;
105 PB_DS_ASSERT_VALID((*this))
111 swap(PB_DS_CLASS_C_DEC& other)
113 PB_DS_ASSERT_VALID((*this))
114 PB_DS_ASSERT_VALID(other)
115 _GLIBCXX_DEBUG_ASSERT(m_a_entries != other.m_a_entries);
117 std::swap((entry_cmp&)(*this), (entry_cmp&)other);
118 PB_DS_ASSERT_VALID((*this))
119 PB_DS_ASSERT_VALID(other)
125 value_swap(PB_DS_CLASS_C_DEC& other)
127 std::swap(m_a_entries, other.m_a_entries);
128 std::swap(m_size, other.m_size);
129 std::swap(m_actual_size, other.m_actual_size);
130 static_cast<resize_policy*>(this)->swap(other);
137 for (size_type i = 0; i < m_size; ++i)
138 erase_at(m_a_entries, i, s_no_throw_copies_ind);
139 s_entry_allocator.deallocate(m_a_entries, m_actual_size);