Commit f6592a9e by Paolo Carlini Committed by Paolo Carlini

deque.tcc: Wrap overlong lines...

2004-02-01  Paolo Carlini  <pcarlini@suse.de>

	* include/bits/deque.tcc: Wrap overlong lines, constify
	a few variables, reformat according to the coding standards.
	* include/bits/list.tcc: Likewise.
	* include/bits/stl_deque.h: Likewise.
	* include/bits/stl_function.h: Likewise.
	* include/bits/stl_iterator.h: Likewise.
	* include/bits/stl_iterator_base_funcs.h: Likewise.
	* include/bits/stl_iterator_base_types.h: Likewise.
	* include/bits/stl_list.h: Likewise.
	* include/bits/stl_map.h: Likewise.
	* include/bits/stl_multimap.h: Likewise.
	* include/bits/stl_multiset.h: Likewise.
	* include/bits/stl_relops.h: Likewise.
	* include/bits/stl_set.h: Likewise.

From-SVN: r77077
parent e0a24727
2004-02-01 Paolo Carlini <pcarlini@suse.de> 2004-02-01 Paolo Carlini <pcarlini@suse.de>
* include/bits/deque.tcc: Wrap overlong lines, constify
a few variables, reformat according to the coding standards.
* include/bits/list.tcc: Likewise.
* include/bits/stl_deque.h: Likewise.
* include/bits/stl_function.h: Likewise.
* include/bits/stl_iterator.h: Likewise.
* include/bits/stl_iterator_base_funcs.h: Likewise.
* include/bits/stl_iterator_base_types.h: Likewise.
* include/bits/stl_list.h: Likewise.
* include/bits/stl_map.h: Likewise.
* include/bits/stl_multimap.h: Likewise.
* include/bits/stl_multiset.h: Likewise.
* include/bits/stl_relops.h: Likewise.
* include/bits/stl_set.h: Likewise.
2004-02-01 Paolo Carlini <pcarlini@suse.de>
* include/bits/stl_bvector.h: Wrap overlong lines, constify * include/bits/stl_bvector.h: Wrap overlong lines, constify
a few variables, reformat according to the coding standards. a few variables, reformat according to the coding standards.
* include/bits/stl_tree.h: Likewise. * include/bits/stl_tree.h: Likewise.
......
// Deque implementation (out of line) -*- C++ -*- // Deque implementation (out of line) -*- C++ -*-
// Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. // Copyright (C) 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the // software; you can redistribute it and/or modify it under the
...@@ -70,16 +70,17 @@ namespace __gnu_norm ...@@ -70,16 +70,17 @@ namespace __gnu_norm
{ {
const size_type __len = size(); const size_type __len = size();
if (&__x != this) if (&__x != this)
{ {
if (__len >= __x.size()) if (__len >= __x.size())
erase(std::copy(__x.begin(), __x.end(), this->_M_start), this->_M_finish); erase(std::copy(__x.begin(), __x.end(), this->_M_start),
else this->_M_finish);
{ else
const_iterator __mid = __x.begin() + difference_type(__len); {
std::copy(__x.begin(), __mid, this->_M_start); const_iterator __mid = __x.begin() + difference_type(__len);
insert(this->_M_finish, __mid, __x.end()); std::copy(__x.begin(), __mid, this->_M_start);
} insert(this->_M_finish, __mid, __x.end());
} }
}
return *this; return *this;
} }
...@@ -89,17 +90,17 @@ namespace __gnu_norm ...@@ -89,17 +90,17 @@ namespace __gnu_norm
insert(iterator position, const value_type& __x) insert(iterator position, const value_type& __x)
{ {
if (position._M_cur == this->_M_start._M_cur) if (position._M_cur == this->_M_start._M_cur)
{ {
push_front(__x); push_front(__x);
return this->_M_start; return this->_M_start;
} }
else if (position._M_cur == this->_M_finish._M_cur) else if (position._M_cur == this->_M_finish._M_cur)
{ {
push_back(__x); push_back(__x);
iterator __tmp = this->_M_finish; iterator __tmp = this->_M_finish;
--__tmp; --__tmp;
return __tmp; return __tmp;
} }
else else
return _M_insert_aux(position, __x); return _M_insert_aux(position, __x);
} }
...@@ -113,15 +114,15 @@ namespace __gnu_norm ...@@ -113,15 +114,15 @@ namespace __gnu_norm
++__next; ++__next;
size_type __index = __position - this->_M_start; size_type __index = __position - this->_M_start;
if (__index < (size() >> 1)) if (__index < (size() >> 1))
{ {
std::copy_backward(this->_M_start, __position, __next); std::copy_backward(this->_M_start, __position, __next);
pop_front(); pop_front();
} }
else else
{ {
std::copy(__next, this->_M_finish, __position); std::copy(__next, this->_M_finish, __position);
pop_back(); pop_back();
} }
return this->_M_start + __index; return this->_M_start + __index;
} }
...@@ -131,33 +132,33 @@ namespace __gnu_norm ...@@ -131,33 +132,33 @@ namespace __gnu_norm
erase(iterator __first, iterator __last) erase(iterator __first, iterator __last)
{ {
if (__first == this->_M_start && __last == this->_M_finish) if (__first == this->_M_start && __last == this->_M_finish)
{ {
clear(); clear();
return this->_M_finish; return this->_M_finish;
} }
else else
{ {
difference_type __n = __last - __first; const difference_type __n = __last - __first;
difference_type __elems_before = __first - this->_M_start; const difference_type __elems_before = __first - this->_M_start;
if (static_cast<size_type>(__elems_before) < (size() - __n) / 2) if (static_cast<size_type>(__elems_before) < (size() - __n) / 2)
{ {
std::copy_backward(this->_M_start, __first, __last); std::copy_backward(this->_M_start, __first, __last);
iterator __new_start = this->_M_start + __n; iterator __new_start = this->_M_start + __n;
std::_Destroy(this->_M_start, __new_start); std::_Destroy(this->_M_start, __new_start);
_M_destroy_nodes(this->_M_start._M_node, __new_start._M_node); _M_destroy_nodes(this->_M_start._M_node, __new_start._M_node);
this->_M_start = __new_start; this->_M_start = __new_start;
} }
else else
{ {
std::copy(__last, this->_M_finish, __first); std::copy(__last, this->_M_finish, __first);
iterator __new_finish = this->_M_finish - __n; iterator __new_finish = this->_M_finish - __n;
std::_Destroy(__new_finish, this->_M_finish); std::_Destroy(__new_finish, this->_M_finish);
_M_destroy_nodes(__new_finish._M_node + 1, _M_destroy_nodes(__new_finish._M_node + 1,
this->_M_finish._M_node + 1); this->_M_finish._M_node + 1);
this->_M_finish = __new_finish; this->_M_finish = __new_finish;
} }
return this->_M_start + __elems_before; return this->_M_start + __elems_before;
} }
} }
template <typename _Tp, typename _Alloc> template <typename _Tp, typename _Alloc>
...@@ -168,20 +169,20 @@ namespace __gnu_norm ...@@ -168,20 +169,20 @@ namespace __gnu_norm
for (_Map_pointer __node = this->_M_start._M_node + 1; for (_Map_pointer __node = this->_M_start._M_node + 1;
__node < this->_M_finish._M_node; __node < this->_M_finish._M_node;
++__node) ++__node)
{ {
std::_Destroy(*__node, *__node + _S_buffer_size()); std::_Destroy(*__node, *__node + _S_buffer_size());
_M_deallocate_node(*__node); _M_deallocate_node(*__node);
} }
if (this->_M_start._M_node != this->_M_finish._M_node) if (this->_M_start._M_node != this->_M_finish._M_node)
{ {
std::_Destroy(this->_M_start._M_cur, this->_M_start._M_last); std::_Destroy(this->_M_start._M_cur, this->_M_start._M_last);
std::_Destroy(this->_M_finish._M_first, this->_M_finish._M_cur); std::_Destroy(this->_M_finish._M_first, this->_M_finish._M_cur);
_M_deallocate_node(this->_M_finish._M_first); _M_deallocate_node(this->_M_finish._M_first);
} }
else else
std::_Destroy(this->_M_start._M_cur, this->_M_finish._M_cur); std::_Destroy(this->_M_start._M_cur, this->_M_finish._M_cur);
this->_M_finish = this->_M_start; this->_M_finish = this->_M_start;
} }
...@@ -189,7 +190,8 @@ namespace __gnu_norm ...@@ -189,7 +190,8 @@ namespace __gnu_norm
template <typename _InputIterator> template <typename _InputIterator>
void void
deque<_Tp,_Alloc> deque<_Tp,_Alloc>
::_M_assign_aux(_InputIterator __first, _InputIterator __last, input_iterator_tag) ::_M_assign_aux(_InputIterator __first, _InputIterator __last,
input_iterator_tag)
{ {
iterator __cur = begin(); iterator __cur = begin();
for ( ; __first != __last && __cur != end(); ++__cur, ++__first) for ( ; __first != __last && __cur != end(); ++__cur, ++__first)
...@@ -206,34 +208,34 @@ namespace __gnu_norm ...@@ -206,34 +208,34 @@ namespace __gnu_norm
_M_fill_insert(iterator __pos, size_type __n, const value_type& __x) _M_fill_insert(iterator __pos, size_type __n, const value_type& __x)
{ {
if (__pos._M_cur == this->_M_start._M_cur) if (__pos._M_cur == this->_M_start._M_cur)
{ {
iterator __new_start = _M_reserve_elements_at_front(__n); iterator __new_start = _M_reserve_elements_at_front(__n);
try try
{ {
std::uninitialized_fill(__new_start, this->_M_start, __x); std::uninitialized_fill(__new_start, this->_M_start, __x);
this->_M_start = __new_start; this->_M_start = __new_start;
} }
catch(...) catch(...)
{ {
_M_destroy_nodes(__new_start._M_node, this->_M_start._M_node); _M_destroy_nodes(__new_start._M_node, this->_M_start._M_node);
__throw_exception_again; __throw_exception_again;
} }
} }
else if (__pos._M_cur == this->_M_finish._M_cur) else if (__pos._M_cur == this->_M_finish._M_cur)
{ {
iterator __new_finish = _M_reserve_elements_at_back(__n); iterator __new_finish = _M_reserve_elements_at_back(__n);
try try
{ {
std::uninitialized_fill(this->_M_finish, __new_finish, __x); std::uninitialized_fill(this->_M_finish, __new_finish, __x);
this->_M_finish = __new_finish; this->_M_finish = __new_finish;
} }
catch(...) catch(...)
{ {
_M_destroy_nodes(this->_M_finish._M_node + 1, _M_destroy_nodes(this->_M_finish._M_node + 1,
__new_finish._M_node + 1); __new_finish._M_node + 1);
__throw_exception_again; __throw_exception_again;
} }
} }
else else
_M_insert_aux(__pos, __n, __x); _M_insert_aux(__pos, __n, __x);
} }
...@@ -288,7 +290,7 @@ namespace __gnu_norm ...@@ -288,7 +290,7 @@ namespace __gnu_norm
_M_range_initialize(_ForwardIterator __first, _ForwardIterator __last, _M_range_initialize(_ForwardIterator __first, _ForwardIterator __last,
forward_iterator_tag) forward_iterator_tag)
{ {
size_type __n = std::distance(__first, __last); const size_type __n = std::distance(__first, __last);
this->_M_initialize_map(__n); this->_M_initialize_map(__n);
_Map_pointer __cur_node; _Map_pointer __cur_node;
...@@ -389,9 +391,7 @@ namespace __gnu_norm ...@@ -389,9 +391,7 @@ namespace __gnu_norm
_M_range_insert_aux(iterator __pos, _M_range_insert_aux(iterator __pos,
_InputIterator __first, _InputIterator __last, _InputIterator __first, _InputIterator __last,
input_iterator_tag) input_iterator_tag)
{ { std::copy(__first, __last, std::inserter(*this, __pos)); }
std::copy(__first, __last, std::inserter(*this, __pos));
}
template <typename _Tp, typename _Alloc> template <typename _Tp, typename _Alloc>
template <typename _ForwardIterator> template <typename _ForwardIterator>
...@@ -403,34 +403,34 @@ namespace __gnu_norm ...@@ -403,34 +403,34 @@ namespace __gnu_norm
{ {
size_type __n = std::distance(__first, __last); size_type __n = std::distance(__first, __last);
if (__pos._M_cur == this->_M_start._M_cur) if (__pos._M_cur == this->_M_start._M_cur)
{ {
iterator __new_start = _M_reserve_elements_at_front(__n); iterator __new_start = _M_reserve_elements_at_front(__n);
try try
{ {
std::uninitialized_copy(__first, __last, __new_start); std::uninitialized_copy(__first, __last, __new_start);
this->_M_start = __new_start; this->_M_start = __new_start;
} }
catch(...) catch(...)
{ {
_M_destroy_nodes(__new_start._M_node, this->_M_start._M_node); _M_destroy_nodes(__new_start._M_node, this->_M_start._M_node);
__throw_exception_again; __throw_exception_again;
} }
} }
else if (__pos._M_cur == this->_M_finish._M_cur) else if (__pos._M_cur == this->_M_finish._M_cur)
{ {
iterator __new_finish = _M_reserve_elements_at_back(__n); iterator __new_finish = _M_reserve_elements_at_back(__n);
try try
{ {
std::uninitialized_copy(__first, __last, this->_M_finish); std::uninitialized_copy(__first, __last, this->_M_finish);
this->_M_finish = __new_finish; this->_M_finish = __new_finish;
} }
catch(...) catch(...)
{ {
_M_destroy_nodes(this->_M_finish._M_node + 1, _M_destroy_nodes(this->_M_finish._M_node + 1,
__new_finish._M_node + 1); __new_finish._M_node + 1);
__throw_exception_again; __throw_exception_again;
} }
} }
else else
_M_insert_aux(__pos, __first, __last, __n); _M_insert_aux(__pos, __first, __last, __n);
} }
...@@ -443,27 +443,27 @@ namespace __gnu_norm ...@@ -443,27 +443,27 @@ namespace __gnu_norm
difference_type __index = __pos - this->_M_start; difference_type __index = __pos - this->_M_start;
value_type __x_copy = __x; // XXX copy value_type __x_copy = __x; // XXX copy
if (static_cast<size_type>(__index) < size() / 2) if (static_cast<size_type>(__index) < size() / 2)
{ {
push_front(front()); push_front(front());
iterator __front1 = this->_M_start; iterator __front1 = this->_M_start;
++__front1; ++__front1;
iterator __front2 = __front1; iterator __front2 = __front1;
++__front2; ++__front2;
__pos = this->_M_start + __index; __pos = this->_M_start + __index;
iterator __pos1 = __pos; iterator __pos1 = __pos;
++__pos1; ++__pos1;
std::copy(__front2, __pos1, __front1); std::copy(__front2, __pos1, __front1);
} }
else else
{ {
push_back(back()); push_back(back());
iterator __back1 = this->_M_finish; iterator __back1 = this->_M_finish;
--__back1; --__back1;
iterator __back2 = __back1; iterator __back2 = __back1;
--__back2; --__back2;
__pos = this->_M_start + __index; __pos = this->_M_start + __index;
std::copy_backward(__pos, __back2, __back1); std::copy_backward(__pos, __back2, __back1);
} }
*__pos = __x_copy; *__pos = __x_copy;
return __pos; return __pos;
} }
...@@ -477,69 +477,73 @@ namespace __gnu_norm ...@@ -477,69 +477,73 @@ namespace __gnu_norm
size_type __length = this->size(); size_type __length = this->size();
value_type __x_copy = __x; value_type __x_copy = __x;
if (__elems_before < difference_type(__length / 2)) if (__elems_before < difference_type(__length / 2))
{ {
iterator __new_start = _M_reserve_elements_at_front(__n); iterator __new_start = _M_reserve_elements_at_front(__n);
iterator __old_start = this->_M_start; iterator __old_start = this->_M_start;
__pos = this->_M_start + __elems_before; __pos = this->_M_start + __elems_before;
try try
{ {
if (__elems_before >= difference_type(__n)) if (__elems_before >= difference_type(__n))
{ {
iterator __start_n = this->_M_start + difference_type(__n); iterator __start_n = this->_M_start + difference_type(__n);
std::uninitialized_copy(this->_M_start, __start_n, __new_start); std::uninitialized_copy(this->_M_start, __start_n,
this->_M_start = __new_start; __new_start);
std::copy(__start_n, __pos, __old_start); this->_M_start = __new_start;
fill(__pos - difference_type(__n), __pos, __x_copy); std::copy(__start_n, __pos, __old_start);
} fill(__pos - difference_type(__n), __pos, __x_copy);
else }
{ else
std::__uninitialized_copy_fill(this->_M_start, __pos, __new_start, {
this->_M_start, __x_copy); std::__uninitialized_copy_fill(this->_M_start, __pos,
this->_M_start = __new_start; __new_start,
std::fill(__old_start, __pos, __x_copy); this->_M_start, __x_copy);
} this->_M_start = __new_start;
} std::fill(__old_start, __pos, __x_copy);
catch(...) }
{ }
_M_destroy_nodes(__new_start._M_node, this->_M_start._M_node); catch(...)
__throw_exception_again; {
} _M_destroy_nodes(__new_start._M_node, this->_M_start._M_node);
} __throw_exception_again;
}
}
else else
{ {
iterator __new_finish = _M_reserve_elements_at_back(__n); iterator __new_finish = _M_reserve_elements_at_back(__n);
iterator __old_finish = this->_M_finish; iterator __old_finish = this->_M_finish;
const difference_type __elems_after = const difference_type __elems_after =
difference_type(__length) - __elems_before; difference_type(__length) - __elems_before;
__pos = this->_M_finish - __elems_after; __pos = this->_M_finish - __elems_after;
try try
{ {
if (__elems_after > difference_type(__n)) if (__elems_after > difference_type(__n))
{ {
iterator __finish_n = this->_M_finish - difference_type(__n); iterator __finish_n = this->_M_finish - difference_type(__n);
std::uninitialized_copy(__finish_n, this->_M_finish, this->_M_finish); std::uninitialized_copy(__finish_n, this->_M_finish,
this->_M_finish = __new_finish; this->_M_finish);
std::copy_backward(__pos, __finish_n, __old_finish); this->_M_finish = __new_finish;
std::fill(__pos, __pos + difference_type(__n), __x_copy); std::copy_backward(__pos, __finish_n, __old_finish);
} std::fill(__pos, __pos + difference_type(__n), __x_copy);
else }
{ else
std::__uninitialized_fill_copy(this->_M_finish, {
__pos + difference_type(__n), std::__uninitialized_fill_copy(this->_M_finish,
__x_copy, __pos, this->_M_finish); __pos + difference_type(__n),
this->_M_finish = __new_finish; __x_copy, __pos,
std::fill(__pos, __old_finish, __x_copy); this->_M_finish);
} this->_M_finish = __new_finish;
} std::fill(__pos, __old_finish, __x_copy);
catch(...) }
{ }
_M_destroy_nodes(this->_M_finish._M_node + 1, catch(...)
__new_finish._M_node + 1); {
__throw_exception_again; _M_destroy_nodes(this->_M_finish._M_node + 1,
} __new_finish._M_node + 1);
} __throw_exception_again;
}
}
} }
template <typename _Tp, typename _Alloc> template <typename _Tp, typename _Alloc>
template <typename _ForwardIterator> template <typename _ForwardIterator>
void void
...@@ -551,36 +555,37 @@ namespace __gnu_norm ...@@ -551,36 +555,37 @@ namespace __gnu_norm
const difference_type __elemsbefore = __pos - this->_M_start; const difference_type __elemsbefore = __pos - this->_M_start;
size_type __length = size(); size_type __length = size();
if (static_cast<size_type>(__elemsbefore) < __length / 2) if (static_cast<size_type>(__elemsbefore) < __length / 2)
{ {
iterator __new_start = _M_reserve_elements_at_front(__n); iterator __new_start = _M_reserve_elements_at_front(__n);
iterator __old_start = this->_M_start; iterator __old_start = this->_M_start;
__pos = this->_M_start + __elemsbefore; __pos = this->_M_start + __elemsbefore;
try try
{ {
if (__elemsbefore >= difference_type(__n)) if (__elemsbefore >= difference_type(__n))
{ {
iterator __start_n = this->_M_start + difference_type(__n); iterator __start_n = this->_M_start + difference_type(__n);
std::uninitialized_copy(this->_M_start, __start_n, __new_start); std::uninitialized_copy(this->_M_start, __start_n,
this->_M_start = __new_start; __new_start);
std::copy(__start_n, __pos, __old_start); this->_M_start = __new_start;
std::copy(__first, __last, __pos - difference_type(__n)); std::copy(__start_n, __pos, __old_start);
} std::copy(__first, __last, __pos - difference_type(__n));
else }
{ else
_ForwardIterator __mid = __first; {
std::advance(__mid, difference_type(__n) - __elemsbefore); _ForwardIterator __mid = __first;
std::__uninitialized_copy_copy(this->_M_start, __pos, std::advance(__mid, difference_type(__n) - __elemsbefore);
__first, __mid, __new_start); std::__uninitialized_copy_copy(this->_M_start, __pos,
this->_M_start = __new_start; __first, __mid, __new_start);
std::copy(__mid, __last, __old_start); this->_M_start = __new_start;
} std::copy(__mid, __last, __old_start);
} }
catch(...) }
{ catch(...)
_M_destroy_nodes(__new_start._M_node, this->_M_start._M_node); {
__throw_exception_again; _M_destroy_nodes(__new_start._M_node, this->_M_start._M_node);
} __throw_exception_again;
} }
}
else else
{ {
iterator __new_finish = _M_reserve_elements_at_back(__n); iterator __new_finish = _M_reserve_elements_at_back(__n);
...@@ -591,24 +596,25 @@ namespace __gnu_norm ...@@ -591,24 +596,25 @@ namespace __gnu_norm
try try
{ {
if (__elemsafter > difference_type(__n)) if (__elemsafter > difference_type(__n))
{ {
iterator __finish_n = this->_M_finish - difference_type(__n); iterator __finish_n = this->_M_finish - difference_type(__n);
std::uninitialized_copy(__finish_n, std::uninitialized_copy(__finish_n,
this->_M_finish, this->_M_finish,
this->_M_finish); this->_M_finish);
this->_M_finish = __new_finish; this->_M_finish = __new_finish;
std::copy_backward(__pos, __finish_n, __old_finish); std::copy_backward(__pos, __finish_n, __old_finish);
std::copy(__first, __last, __pos); std::copy(__first, __last, __pos);
} }
else else
{ {
_ForwardIterator __mid = __first; _ForwardIterator __mid = __first;
std::advance(__mid, __elemsafter); std::advance(__mid, __elemsafter);
std::__uninitialized_copy_copy(__mid, __last, __pos, std::__uninitialized_copy_copy(__mid, __last, __pos,
this->_M_finish, this->_M_finish); this->_M_finish,
this->_M_finish = __new_finish; this->_M_finish);
std::copy(__first, __mid, __pos); this->_M_finish = __new_finish;
} std::copy(__first, __mid, __pos);
}
} }
catch(...) catch(...)
{ {
...@@ -625,7 +631,7 @@ namespace __gnu_norm ...@@ -625,7 +631,7 @@ namespace __gnu_norm
_M_new_elements_at_front(size_type __new_elems) _M_new_elements_at_front(size_type __new_elems)
{ {
size_type __new_nodes size_type __new_nodes
= (__new_elems + _S_buffer_size() - 1) / _S_buffer_size(); = (__new_elems + _S_buffer_size() - 1) / _S_buffer_size();
_M_reserve_map_at_front(__new_nodes); _M_reserve_map_at_front(__new_nodes);
size_type __i; size_type __i;
try try
...@@ -674,39 +680,40 @@ namespace __gnu_norm ...@@ -674,39 +680,40 @@ namespace __gnu_norm
_Map_pointer __new_nstart; _Map_pointer __new_nstart;
if (this->_M_map_size > 2 * __new_num_nodes) if (this->_M_map_size > 2 * __new_num_nodes)
{ {
__new_nstart __new_nstart = this->_M_map + (this->_M_map_size
= this->_M_map + (this->_M_map_size - __new_num_nodes) / 2 - __new_num_nodes) / 2
+ (__add_at_front ? __nodes_to_add : 0); + (__add_at_front ? __nodes_to_add : 0);
if (__new_nstart < this->_M_start._M_node) if (__new_nstart < this->_M_start._M_node)
std::copy(this->_M_start._M_node, std::copy(this->_M_start._M_node,
this->_M_finish._M_node + 1, this->_M_finish._M_node + 1,
__new_nstart); __new_nstart);
else else
std::copy_backward(this->_M_start._M_node, std::copy_backward(this->_M_start._M_node,
this->_M_finish._M_node + 1, this->_M_finish._M_node + 1,
__new_nstart + __old_num_nodes); __new_nstart + __old_num_nodes);
} }
else else
{ {
size_type __new_map_size = size_type __new_map_size = this->_M_map_size
this->_M_map_size + std::max(this->_M_map_size, __nodes_to_add) + 2; + std::max(this->_M_map_size,
__nodes_to_add) + 2;
_Map_pointer __new_map = this->_M_allocate_map(__new_map_size);
__new_nstart = __new_map + (__new_map_size - __new_num_nodes) / 2
+ (__add_at_front ? __nodes_to_add : 0);
std::copy(this->_M_start._M_node,
this->_M_finish._M_node + 1,
__new_nstart);
_M_deallocate_map(this->_M_map, this->_M_map_size);
this->_M_map = __new_map;
this->_M_map_size = __new_map_size;
}
_Map_pointer __new_map = this->_M_allocate_map(__new_map_size);
__new_nstart = __new_map + (__new_map_size - __new_num_nodes) / 2
+ (__add_at_front ? __nodes_to_add : 0);
std::copy(this->_M_start._M_node,
this->_M_finish._M_node + 1,
__new_nstart);
_M_deallocate_map(this->_M_map, this->_M_map_size);
this->_M_map = __new_map;
this->_M_map_size = __new_map_size;
}
this->_M_start._M_set_node(__new_nstart); this->_M_start._M_set_node(__new_nstart);
this->_M_finish._M_set_node(__new_nstart + __old_num_nodes - 1); this->_M_finish._M_set_node(__new_nstart + __old_num_nodes - 1);
} }
} // namespace __gnu_norm } // namespace __gnu_norm
#endif #endif
// List implementation (out of line) -*- C++ -*- // List implementation (out of line) -*- C++ -*-
// Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. // Copyright (C) 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the // software; you can redistribute it and/or modify it under the
...@@ -120,18 +120,18 @@ namespace __gnu_norm ...@@ -120,18 +120,18 @@ namespace __gnu_norm
operator=(const list& __x) operator=(const list& __x)
{ {
if (this != &__x) if (this != &__x)
{ {
iterator __first1 = begin(); iterator __first1 = begin();
iterator __last1 = end(); iterator __last1 = end();
const_iterator __first2 = __x.begin(); const_iterator __first2 = __x.begin();
const_iterator __last2 = __x.end(); const_iterator __last2 = __x.end();
while (__first1 != __last1 && __first2 != __last2) while (__first1 != __last1 && __first2 != __last2)
*__first1++ = *__first2++; *__first1++ = *__first2++;
if (__first2 == __last2) if (__first2 == __last2)
erase(__first1, __last1); erase(__first1, __last1);
else else
insert(__last1, __first2, __last2); insert(__last1, __first2, __last2);
} }
return *this; return *this;
} }
...@@ -191,7 +191,8 @@ namespace __gnu_norm ...@@ -191,7 +191,8 @@ namespace __gnu_norm
{ {
iterator __first = begin(); iterator __first = begin();
iterator __last = end(); iterator __last = end();
if (__first == __last) return; if (__first == __last)
return;
iterator __next = __first; iterator __next = __first;
while (++__next != __last) while (++__next != __last)
{ {
...@@ -245,19 +246,21 @@ namespace __gnu_norm ...@@ -245,19 +246,21 @@ namespace __gnu_norm
list * __counter; list * __counter;
do do
{ {
__carry.splice(__carry.begin(), *this, begin()); __carry.splice(__carry.begin(), *this, begin());
for(__counter = &__tmp[0]; for(__counter = &__tmp[0];
(__counter != __fill) && !__counter->empty(); (__counter != __fill) && !__counter->empty();
++__counter) ++__counter)
{ {
__counter->merge(__carry); __counter->merge(__carry);
__carry.swap(*__counter); __carry.swap(*__counter);
} }
__carry.swap(*__counter); __carry.swap(*__counter);
if (__counter == __fill) ++__fill; if (__counter == __fill)
} while ( !empty() ); ++__fill;
}
while ( !empty() );
for (__counter = &__tmp[1]; __counter != __fill; ++__counter) for (__counter = &__tmp[1]; __counter != __fill; ++__counter)
__counter->merge( *(__counter-1) ); __counter->merge( *(__counter-1) );
...@@ -277,7 +280,8 @@ namespace __gnu_norm ...@@ -277,7 +280,8 @@ namespace __gnu_norm
{ {
iterator __next = __first; iterator __next = __first;
++__next; ++__next;
if (__pred(*__first)) _M_erase(__first); if (__pred(*__first))
_M_erase(__first);
__first = __next; __first = __next;
} }
} }
...@@ -332,39 +336,41 @@ namespace __gnu_norm ...@@ -332,39 +336,41 @@ namespace __gnu_norm
template<typename _Tp, typename _Alloc> template<typename _Tp, typename _Alloc>
template <typename _StrictWeakOrdering> template <typename _StrictWeakOrdering>
void void
list<_Tp,_Alloc>:: list<_Tp,_Alloc>::
sort(_StrictWeakOrdering __comp) sort(_StrictWeakOrdering __comp)
{
// Do nothing if the list has length 0 or 1.
if (this->_M_node._M_next != &this->_M_node &&
this->_M_node._M_next->_M_next != &this->_M_node)
{ {
list __carry; // Do nothing if the list has length 0 or 1.
list __tmp[64]; if (this->_M_node._M_next != &this->_M_node
list * __fill = &__tmp[0]; && this->_M_node._M_next->_M_next != &this->_M_node)
list * __counter; {
list __carry;
do list __tmp[64];
{ list * __fill = &__tmp[0];
__carry.splice(__carry.begin(), *this, begin()); list * __counter;
for(__counter = &__tmp[0]; do
(__counter != __fill) && !__counter->empty(); {
++__counter) __carry.splice(__carry.begin(), *this, begin());
{
__counter->merge(__carry, __comp); for(__counter = &__tmp[0];
__carry.swap(*__counter); (__counter != __fill) && !__counter->empty();
} ++__counter)
__carry.swap(*__counter); {
if (__counter == __fill) ++__fill; __counter->merge(__carry, __comp);
} while ( !empty() ); __carry.swap(*__counter);
}
for (__counter = &__tmp[1]; __counter != __fill; ++__counter) __carry.swap(*__counter);
__counter->merge( *(__counter-1), __comp ); if (__counter == __fill)
swap( *(__fill-1) ); ++__fill;
}
while ( !empty() );
for (__counter = &__tmp[1]; __counter != __fill; ++__counter)
__counter->merge( *(__counter-1), __comp );
swap( *(__fill-1) );
}
} }
}
} // namespace __gnu_norm } // namespace __gnu_norm
#endif /* _LIST_TCC */ #endif /* _LIST_TCC */
......
// Deque implementation -*- C++ -*- // Deque implementation -*- C++ -*-
// Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. // Copyright (C) 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the // software; you can redistribute it and/or modify it under the
...@@ -98,239 +98,244 @@ namespace __gnu_norm ...@@ -98,239 +98,244 @@ namespace __gnu_norm
*/ */
template<typename _Tp, typename _Ref, typename _Ptr> template<typename _Tp, typename _Ref, typename _Ptr>
struct _Deque_iterator struct _Deque_iterator
{ {
typedef _Deque_iterator<_Tp, _Tp&, _Tp*> iterator; typedef _Deque_iterator<_Tp, _Tp&, _Tp*> iterator;
typedef _Deque_iterator<_Tp, const _Tp&, const _Tp*> const_iterator; typedef _Deque_iterator<_Tp, const _Tp&, const _Tp*> const_iterator;
static size_t _S_buffer_size() { return __deque_buf_size(sizeof(_Tp)); }
static size_t _S_buffer_size()
typedef random_access_iterator_tag iterator_category; { return __deque_buf_size(sizeof(_Tp)); }
typedef _Tp value_type;
typedef _Ptr pointer; typedef random_access_iterator_tag iterator_category;
typedef _Ref reference; typedef _Tp value_type;
typedef size_t size_type; typedef _Ptr pointer;
typedef ptrdiff_t difference_type; typedef _Ref reference;
typedef _Tp** _Map_pointer; typedef size_t size_type;
typedef _Deque_iterator _Self; typedef ptrdiff_t difference_type;
typedef _Tp** _Map_pointer;
_Tp* _M_cur; typedef _Deque_iterator _Self;
_Tp* _M_first;
_Tp* _M_last; _Tp* _M_cur;
_Map_pointer _M_node; _Tp* _M_first;
_Tp* _M_last;
_Deque_iterator(_Tp* __x, _Map_pointer __y) _Map_pointer _M_node;
_Deque_iterator(_Tp* __x, _Map_pointer __y)
: _M_cur(__x), _M_first(*__y), : _M_cur(__x), _M_first(*__y),
_M_last(*__y + _S_buffer_size()), _M_node(__y) {} _M_last(*__y + _S_buffer_size()), _M_node(__y) {}
_Deque_iterator() : _M_cur(0), _M_first(0), _M_last(0), _M_node(0) {}
_Deque_iterator(const iterator& __x) _Deque_iterator() : _M_cur(0), _M_first(0), _M_last(0), _M_node(0) {}
_Deque_iterator(const iterator& __x)
: _M_cur(__x._M_cur), _M_first(__x._M_first), : _M_cur(__x._M_cur), _M_first(__x._M_first),
_M_last(__x._M_last), _M_node(__x._M_node) {} _M_last(__x._M_last), _M_node(__x._M_node) {}
reference operator*() const { return *_M_cur; } reference
pointer operator->() const { return _M_cur; } operator*() const
{ return *_M_cur; }
_Self& operator++() {
++_M_cur; pointer
if (_M_cur == _M_last) { operator->() const
_M_set_node(_M_node + 1); { return _M_cur; }
_M_cur = _M_first;
_Self&
operator++()
{
++_M_cur;
if (_M_cur == _M_last)
{
_M_set_node(_M_node + 1);
_M_cur = _M_first;
}
return *this;
} }
return *this;
} _Self
_Self operator++(int) { operator++(int)
_Self __tmp = *this; {
++*this; _Self __tmp = *this;
return __tmp; ++*this;
} return __tmp;
_Self& operator--() {
if (_M_cur == _M_first) {
_M_set_node(_M_node - 1);
_M_cur = _M_last;
} }
--_M_cur;
return *this; _Self&
} operator--()
_Self operator--(int) { {
_Self __tmp = *this; if (_M_cur == _M_first)
--*this; {
return __tmp; _M_set_node(_M_node - 1);
} _M_cur = _M_last;
}
_Self& operator+=(difference_type __n) --_M_cur;
{ return *this;
difference_type __offset = __n + (_M_cur - _M_first); }
if (__offset >= 0 && __offset < difference_type(_S_buffer_size()))
_M_cur += __n; _Self
else { operator--(int)
difference_type __node_offset = {
__offset > 0 ? __offset / difference_type(_S_buffer_size()) _Self __tmp = *this;
: -difference_type((-__offset - 1) / _S_buffer_size()) - 1; --*this;
_M_set_node(_M_node + __node_offset); return __tmp;
_M_cur = _M_first + }
(__offset - __node_offset * difference_type(_S_buffer_size()));
_Self&
operator+=(difference_type __n)
{
const difference_type __offset = __n + (_M_cur - _M_first);
if (__offset >= 0 && __offset < difference_type(_S_buffer_size()))
_M_cur += __n;
else
{
const difference_type __node_offset =
__offset > 0 ? __offset / difference_type(_S_buffer_size())
: -difference_type((-__offset - 1)
/ _S_buffer_size()) - 1;
_M_set_node(_M_node + __node_offset);
_M_cur = _M_first + (__offset - __node_offset
* difference_type(_S_buffer_size()));
}
return *this;
} }
return *this;
}
_Self operator+(difference_type __n) const _Self
{ operator+(difference_type __n) const
_Self __tmp = *this; {
return __tmp += __n; _Self __tmp = *this;
} return __tmp += __n;
}
_Self& operator-=(difference_type __n) { return *this += -__n; } _Self&
operator-=(difference_type __n)
{ return *this += -__n; }
_Self operator-(difference_type __n) const { _Self
_Self __tmp = *this; operator-(difference_type __n) const
return __tmp -= __n; {
} _Self __tmp = *this;
return __tmp -= __n;
}
reference operator[](difference_type __n) const { return *(*this + __n); } reference
operator[](difference_type __n) const
{ return *(*this + __n); }
/** @if maint /** @if maint
* Prepares to traverse new_node. Sets everything except _M_cur, which * Prepares to traverse new_node. Sets everything except _M_cur, which
* should therefore be set by the caller immediately afterwards, based on * should therefore be set by the caller immediately afterwards, based on
* _M_first and _M_last. * _M_first and _M_last.
* @endif * @endif
*/ */
void void
_M_set_node(_Map_pointer __new_node) _M_set_node(_Map_pointer __new_node)
{ {
_M_node = __new_node; _M_node = __new_node;
_M_first = *__new_node; _M_first = *__new_node;
_M_last = _M_first + difference_type(_S_buffer_size()); _M_last = _M_first + difference_type(_S_buffer_size());
} }
}; };
// Note: we also provide overloads whose operands are of the same type in // Note: we also provide overloads whose operands are of the same type in
// order to avoid ambiguous overload resolution when std::rel_ops operators // order to avoid ambiguous overload resolution when std::rel_ops operators
// are in scope (for additional details, see libstdc++/3628) // are in scope (for additional details, see libstdc++/3628)
template<typename _Tp, typename _Ref, typename _Ptr> template<typename _Tp, typename _Ref, typename _Ptr>
inline bool inline bool
operator==(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x, operator==(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x,
const _Deque_iterator<_Tp, _Ref, _Ptr>& __y) const _Deque_iterator<_Tp, _Ref, _Ptr>& __y)
{ { return __x._M_cur == __y._M_cur; }
return __x._M_cur == __y._M_cur;
}
template<typename _Tp, typename _RefL, typename _PtrL, template<typename _Tp, typename _RefL, typename _PtrL,
typename _RefR, typename _PtrR> typename _RefR, typename _PtrR>
inline bool inline bool
operator==(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x, operator==(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x,
const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) const _Deque_iterator<_Tp, _RefR, _PtrR>& __y)
{ { return __x._M_cur == __y._M_cur; }
return __x._M_cur == __y._M_cur;
}
template<typename _Tp, typename _Ref, typename _Ptr> template<typename _Tp, typename _Ref, typename _Ptr>
inline bool inline bool
operator!=(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x, operator!=(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x,
const _Deque_iterator<_Tp, _Ref, _Ptr>& __y) const _Deque_iterator<_Tp, _Ref, _Ptr>& __y)
{ { return !(__x == __y); }
return !(__x == __y);
}
template<typename _Tp, typename _RefL, typename _PtrL, template<typename _Tp, typename _RefL, typename _PtrL,
typename _RefR, typename _PtrR> typename _RefR, typename _PtrR>
inline bool inline bool
operator!=(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x, operator!=(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x,
const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) const _Deque_iterator<_Tp, _RefR, _PtrR>& __y)
{ { return !(__x == __y); }
return !(__x == __y);
}
template<typename _Tp, typename _Ref, typename _Ptr> template<typename _Tp, typename _Ref, typename _Ptr>
inline bool inline bool
operator<(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x, operator<(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x,
const _Deque_iterator<_Tp, _Ref, _Ptr>& __y) const _Deque_iterator<_Tp, _Ref, _Ptr>& __y)
{ { return (__x._M_node == __y._M_node) ? (__x._M_cur < __y._M_cur)
return (__x._M_node == __y._M_node) ? : (__x._M_node < __y._M_node); }
(__x._M_cur < __y._M_cur) : (__x._M_node < __y._M_node);
}
template<typename _Tp, typename _RefL, typename _PtrL, template<typename _Tp, typename _RefL, typename _PtrL,
typename _RefR, typename _PtrR> typename _RefR, typename _PtrR>
inline bool inline bool
operator<(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x, operator<(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x,
const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) const _Deque_iterator<_Tp, _RefR, _PtrR>& __y)
{ { return (__x._M_node == __y._M_node) ? (__x._M_cur < __y._M_cur)
return (__x._M_node == __y._M_node) ? : (__x._M_node < __y._M_node); }
(__x._M_cur < __y._M_cur) : (__x._M_node < __y._M_node);
}
template<typename _Tp, typename _Ref, typename _Ptr> template<typename _Tp, typename _Ref, typename _Ptr>
inline bool inline bool
operator>(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x, operator>(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x,
const _Deque_iterator<_Tp, _Ref, _Ptr>& __y) const _Deque_iterator<_Tp, _Ref, _Ptr>& __y)
{ { return __y < __x; }
return __y < __x;
}
template<typename _Tp, typename _RefL, typename _PtrL, template<typename _Tp, typename _RefL, typename _PtrL,
typename _RefR, typename _PtrR> typename _RefR, typename _PtrR>
inline bool inline bool
operator>(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x, operator>(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x,
const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) const _Deque_iterator<_Tp, _RefR, _PtrR>& __y)
{ { return __y < __x; }
return __y < __x;
}
template<typename _Tp, typename _Ref, typename _Ptr> template<typename _Tp, typename _Ref, typename _Ptr>
inline bool inline bool
operator<=(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x, operator<=(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x,
const _Deque_iterator<_Tp, _Ref, _Ptr>& __y) const _Deque_iterator<_Tp, _Ref, _Ptr>& __y)
{ { return !(__y < __x); }
return !(__y < __x);
}
template<typename _Tp, typename _RefL, typename _PtrL, template<typename _Tp, typename _RefL, typename _PtrL,
typename _RefR, typename _PtrR> typename _RefR, typename _PtrR>
inline bool inline bool
operator<=(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x, operator<=(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x,
const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) const _Deque_iterator<_Tp, _RefR, _PtrR>& __y)
{ { return !(__y < __x); }
return !(__y < __x);
}
template<typename _Tp, typename _Ref, typename _Ptr> template<typename _Tp, typename _Ref, typename _Ptr>
inline bool inline bool
operator>=(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x, operator>=(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x,
const _Deque_iterator<_Tp, _Ref, _Ptr>& __y) const _Deque_iterator<_Tp, _Ref, _Ptr>& __y)
{ { return !(__x < __y); }
return !(__x < __y);
}
template<typename _Tp, typename _RefL, typename _PtrL, template<typename _Tp, typename _RefL, typename _PtrL,
typename _RefR, typename _PtrR> typename _RefR, typename _PtrR>
inline bool inline bool
operator>=(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x, operator>=(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x,
const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) const _Deque_iterator<_Tp, _RefR, _PtrR>& __y)
{ { return !(__x < __y); }
return !(__x < __y);
}
// _GLIBCXX_RESOLVE_LIB_DEFECTS // _GLIBCXX_RESOLVE_LIB_DEFECTS
// According to the resolution of DR179 not only the various comparison // According to the resolution of DR179 not only the various comparison
// operators but also operator- must accept mixed iterator/const_iterator // operators but also operator- must accept mixed iterator/const_iterator
// parameters. // parameters.
template<typename _Tp, typename _RefL, typename _PtrL, template<typename _Tp, typename _RefL, typename _PtrL,
typename _RefR, typename _PtrR> typename _RefR, typename _PtrR>
inline typename _Deque_iterator<_Tp, _RefL, _PtrL>::difference_type inline typename _Deque_iterator<_Tp, _RefL, _PtrL>::difference_type
operator-(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x, operator-(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x,
const _Deque_iterator<_Tp, _RefR, _PtrR>& __y) const _Deque_iterator<_Tp, _RefR, _PtrR>& __y)
{ {
return typename _Deque_iterator<_Tp, _RefL, _PtrL>::difference_type return typename _Deque_iterator<_Tp, _RefL, _PtrL>::difference_type
(_Deque_iterator<_Tp, _RefL, _PtrL>::_S_buffer_size()) * (_Deque_iterator<_Tp, _RefL, _PtrL>::_S_buffer_size())
(__x._M_node - __y._M_node - 1) + (__x._M_cur - __x._M_first) + * (__x._M_node - __y._M_node - 1) + (__x._M_cur - __x._M_first)
(__y._M_last - __y._M_cur); + (__y._M_last - __y._M_cur);
} }
template<typename _Tp, typename _Ref, typename _Ptr> template<typename _Tp, typename _Ref, typename _Ptr>
inline _Deque_iterator<_Tp, _Ref, _Ptr> inline _Deque_iterator<_Tp, _Ref, _Ptr>
operator+(ptrdiff_t __n, const _Deque_iterator<_Tp, _Ref, _Ptr>& __x) operator+(ptrdiff_t __n, const _Deque_iterator<_Tp, _Ref, _Ptr>& __x)
{ { return __x + __n; }
return __x + __n;
}
/** /**
* @if maint * @if maint
...@@ -347,59 +352,58 @@ namespace __gnu_norm ...@@ -347,59 +352,58 @@ namespace __gnu_norm
template<typename _Tp, typename _Alloc> template<typename _Tp, typename _Alloc>
class _Deque_base class _Deque_base
: public _Alloc : public _Alloc
{ {
public: public:
typedef _Alloc allocator_type; typedef _Alloc allocator_type;
allocator_type get_allocator() const
allocator_type
get_allocator() const
{ return *static_cast<const _Alloc*>(this); } { return *static_cast<const _Alloc*>(this); }
typedef _Deque_iterator<_Tp,_Tp&,_Tp*> iterator; typedef _Deque_iterator<_Tp,_Tp&,_Tp*> iterator;
typedef _Deque_iterator<_Tp,const _Tp&,const _Tp*> const_iterator; typedef _Deque_iterator<_Tp,const _Tp&,const _Tp*> const_iterator;
_Deque_base(const allocator_type& __a, size_t __num_elements) _Deque_base(const allocator_type& __a, size_t __num_elements)
: _Alloc(__a), _M_start(), _M_finish() : _Alloc(__a), _M_start(), _M_finish()
{ _M_initialize_map(__num_elements); } { _M_initialize_map(__num_elements); }
_Deque_base(const allocator_type& __a)
: _Alloc(__a), _M_start(), _M_finish() {}
~_Deque_base();
protected: _Deque_base(const allocator_type& __a)
typedef typename _Alloc::template rebind<_Tp*>::other _Map_alloc_type; : _Alloc(__a), _M_start(), _M_finish() { }
_Map_alloc_type _M_get_map_allocator() const
~_Deque_base();
protected:
typedef typename _Alloc::template rebind<_Tp*>::other _Map_alloc_type;
_Map_alloc_type _M_get_map_allocator() const
{ return _Map_alloc_type(this->get_allocator()); } { return _Map_alloc_type(this->get_allocator()); }
_Tp* _Tp*
_M_allocate_node() _M_allocate_node()
{ { return _Alloc::allocate(__deque_buf_size(sizeof(_Tp))); }
return _Alloc::allocate(__deque_buf_size(sizeof(_Tp)));
} void
_M_deallocate_node(_Tp* __p)
void { _Alloc::deallocate(__p, __deque_buf_size(sizeof(_Tp))); }
_M_deallocate_node(_Tp* __p)
{ _Tp**
_Alloc::deallocate(__p, __deque_buf_size(sizeof(_Tp))); _M_allocate_map(size_t __n)
}
_Tp**
_M_allocate_map(size_t __n)
{ return _M_get_map_allocator().allocate(__n); } { return _M_get_map_allocator().allocate(__n); }
void void
_M_deallocate_map(_Tp** __p, size_t __n) _M_deallocate_map(_Tp** __p, size_t __n)
{ _M_get_map_allocator().deallocate(__p, __n); } { _M_get_map_allocator().deallocate(__p, __n); }
protected: protected:
void _M_initialize_map(size_t); void _M_initialize_map(size_t);
void _M_create_nodes(_Tp** __nstart, _Tp** __nfinish); void _M_create_nodes(_Tp** __nstart, _Tp** __nfinish);
void _M_destroy_nodes(_Tp** __nstart, _Tp** __nfinish); void _M_destroy_nodes(_Tp** __nstart, _Tp** __nfinish);
enum { _S_initial_map_size = 8 }; enum { _S_initial_map_size = 8 };
_Tp** _M_map; _Tp** _M_map;
size_t _M_map_size; size_t _M_map_size;
iterator _M_start; iterator _M_start;
iterator _M_finish; iterator _M_finish;
}; };
template<typename _Tp, typename _Alloc> template<typename _Tp, typename _Alloc>
_Deque_base<_Tp,_Alloc>::~_Deque_base() _Deque_base<_Tp,_Alloc>::~_Deque_base()
...@@ -422,64 +426,64 @@ namespace __gnu_norm ...@@ -422,64 +426,64 @@ namespace __gnu_norm
* @endif * @endif
*/ */
template<typename _Tp, typename _Alloc> template<typename _Tp, typename _Alloc>
void void
_Deque_base<_Tp,_Alloc>::_M_initialize_map(size_t __num_elements) _Deque_base<_Tp,_Alloc>::_M_initialize_map(size_t __num_elements)
{ {
size_t __num_nodes = size_t __num_nodes = __num_elements / __deque_buf_size(sizeof(_Tp)) + 1;
__num_elements / __deque_buf_size(sizeof(_Tp)) + 1;
this->_M_map_size = std::max((size_t) _S_initial_map_size,
this->_M_map_size __num_nodes + 2);
= std::max((size_t) _S_initial_map_size, __num_nodes + 2); this->_M_map = _M_allocate_map(this->_M_map_size);
this->_M_map = _M_allocate_map(this->_M_map_size);
// For "small" maps (needing less than _M_map_size nodes), allocation // For "small" maps (needing less than _M_map_size nodes), allocation
// starts in the middle elements and grows outwards. So nstart may be the // starts in the middle elements and grows outwards. So nstart may be
// beginning of _M_map, but for small maps it may be as far in as _M_map+3. // the beginning of _M_map, but for small maps it may be as far in as
// _M_map+3.
_Tp** __nstart = this->_M_map + (this->_M_map_size - __num_nodes) / 2; _Tp** __nstart = this->_M_map + (this->_M_map_size - __num_nodes) / 2;
_Tp** __nfinish = __nstart + __num_nodes; _Tp** __nfinish = __nstart + __num_nodes;
try try
{ _M_create_nodes(__nstart, __nfinish); } { _M_create_nodes(__nstart, __nfinish); }
catch(...) catch(...)
{ {
_M_deallocate_map(this->_M_map, this->_M_map_size); _M_deallocate_map(this->_M_map, this->_M_map_size);
this->_M_map = 0; this->_M_map = 0;
this->_M_map_size = 0; this->_M_map_size = 0;
__throw_exception_again; __throw_exception_again;
} }
_M_start._M_set_node(__nstart); _M_start._M_set_node(__nstart);
_M_finish._M_set_node(__nfinish - 1); _M_finish._M_set_node(__nfinish - 1);
_M_start._M_cur = _M_start._M_first; _M_start._M_cur = _M_start._M_first;
_M_finish._M_cur = _M_finish._M_first + _M_finish._M_cur = _M_finish._M_first + __num_elements
__num_elements % __deque_buf_size(sizeof(_Tp)); % __deque_buf_size(sizeof(_Tp));
} }
template<typename _Tp, typename _Alloc> template<typename _Tp, typename _Alloc>
void _Deque_base<_Tp,_Alloc>::_M_create_nodes(_Tp** __nstart, _Tp** __nfinish) void
{ _Deque_base<_Tp,_Alloc>::_M_create_nodes(_Tp** __nstart, _Tp** __nfinish)
_Tp** __cur; {
try _Tp** __cur;
{ try
for (__cur = __nstart; __cur < __nfinish; ++__cur) {
*__cur = this->_M_allocate_node(); for (__cur = __nstart; __cur < __nfinish; ++__cur)
} *__cur = this->_M_allocate_node();
catch(...) }
{ catch(...)
_M_destroy_nodes(__nstart, __cur); {
__throw_exception_again; _M_destroy_nodes(__nstart, __cur);
} __throw_exception_again;
} }
}
template<typename _Tp, typename _Alloc> template<typename _Tp, typename _Alloc>
void void
_Deque_base<_Tp,_Alloc>::_M_destroy_nodes(_Tp** __nstart, _Tp** __nfinish) _Deque_base<_Tp,_Alloc>::_M_destroy_nodes(_Tp** __nstart, _Tp** __nfinish)
{ {
for (_Tp** __n = __nstart; __n < __nfinish; ++__n) for (_Tp** __n = __nstart; __n < __nfinish; ++__n)
_M_deallocate_node(*__n); _M_deallocate_node(*__n);
} }
/** /**
* @brief A standard container using fixed-size memory allocation and * @brief A standard container using fixed-size memory allocation and
...@@ -567,820 +571,851 @@ namespace __gnu_norm ...@@ -567,820 +571,851 @@ namespace __gnu_norm
*/ */
template<typename _Tp, typename _Alloc = allocator<_Tp> > template<typename _Tp, typename _Alloc = allocator<_Tp> >
class deque : protected _Deque_base<_Tp, _Alloc> class deque : protected _Deque_base<_Tp, _Alloc>
{ {
// concept requirements // concept requirements
__glibcxx_class_requires(_Tp, _SGIAssignableConcept) __glibcxx_class_requires(_Tp, _SGIAssignableConcept)
typedef _Deque_base<_Tp, _Alloc> _Base; typedef _Deque_base<_Tp, _Alloc> _Base;
public: public:
typedef _Tp value_type; typedef _Tp value_type;
typedef value_type* pointer; typedef value_type* pointer;
typedef const value_type* const_pointer; typedef const value_type* const_pointer;
typedef typename _Base::iterator iterator; typedef typename _Base::iterator iterator;
typedef typename _Base::const_iterator const_iterator; typedef typename _Base::const_iterator const_iterator;
typedef std::reverse_iterator<const_iterator> const_reverse_iterator; typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
typedef std::reverse_iterator<iterator> reverse_iterator; typedef std::reverse_iterator<iterator> reverse_iterator;
typedef value_type& reference; typedef value_type& reference;
typedef const value_type& const_reference; typedef const value_type& const_reference;
typedef size_t size_type; typedef size_t size_type;
typedef ptrdiff_t difference_type; typedef ptrdiff_t difference_type;
typedef typename _Base::allocator_type allocator_type; typedef typename _Base::allocator_type allocator_type;
protected: protected:
typedef pointer* _Map_pointer; typedef pointer* _Map_pointer;
static size_t _S_buffer_size() { return __deque_buf_size(sizeof(_Tp)); }
static size_t _S_buffer_size()
// Functions controlling memory layout, and nothing else. { return __deque_buf_size(sizeof(_Tp)); }
using _Base::_M_initialize_map;
using _Base::_M_create_nodes; // Functions controlling memory layout, and nothing else.
using _Base::_M_destroy_nodes; using _Base::_M_initialize_map;
using _Base::_M_allocate_node; using _Base::_M_create_nodes;
using _Base::_M_deallocate_node; using _Base::_M_destroy_nodes;
using _Base::_M_allocate_map; using _Base::_M_allocate_node;
using _Base::_M_deallocate_map; using _Base::_M_deallocate_node;
using _Base::_M_allocate_map;
/** @if maint using _Base::_M_deallocate_map;
* A total of four data members accumulated down the heirarchy.
* @endif /** @if maint
*/ * A total of four data members accumulated down the heirarchy.
using _Base::_M_map; * @endif
using _Base::_M_map_size; */
using _Base::_M_start; using _Base::_M_map;
using _Base::_M_finish; using _Base::_M_map_size;
using _Base::_M_start;
public: using _Base::_M_finish;
// [23.2.1.1] construct/copy/destroy
// (assign() and get_allocator() are also listed in this section) public:
/** // [23.2.1.1] construct/copy/destroy
* @brief Default constructor creates no elements. // (assign() and get_allocator() are also listed in this section)
*/ /**
explicit * @brief Default constructor creates no elements.
deque(const allocator_type& __a = allocator_type()) */
explicit
deque(const allocator_type& __a = allocator_type())
: _Base(__a, 0) {} : _Base(__a, 0) {}
/** /**
* @brief Create a %deque with copies of an exemplar element. * @brief Create a %deque with copies of an exemplar element.
* @param n The number of elements to initially create. * @param n The number of elements to initially create.
* @param value An element to copy. * @param value An element to copy.
* *
* This constructor fills the %deque with @a n copies of @a value. * This constructor fills the %deque with @a n copies of @a value.
*/ */
deque(size_type __n, const value_type& __value, deque(size_type __n, const value_type& __value,
const allocator_type& __a = allocator_type()) const allocator_type& __a = allocator_type())
: _Base(__a, __n) : _Base(__a, __n)
{ _M_fill_initialize(__value); } { _M_fill_initialize(__value); }
/** /**
* @brief Create a %deque with default elements. * @brief Create a %deque with default elements.
* @param n The number of elements to initially create. * @param n The number of elements to initially create.
* *
* This constructor fills the %deque with @a n copies of a * This constructor fills the %deque with @a n copies of a
* default-constructed element. * default-constructed element.
*/ */
explicit explicit
deque(size_type __n) deque(size_type __n)
: _Base(allocator_type(), __n) : _Base(allocator_type(), __n)
{ _M_fill_initialize(value_type()); } { _M_fill_initialize(value_type()); }
/** /**
* @brief %Deque copy constructor. * @brief %Deque copy constructor.
* @param x A %deque of identical element and allocator types. * @param x A %deque of identical element and allocator types.
* *
* The newly-created %deque uses a copy of the allocation object used * The newly-created %deque uses a copy of the allocation object used
* by @a x. * by @a x.
*/ */
deque(const deque& __x) deque(const deque& __x)
: _Base(__x.get_allocator(), __x.size()) : _Base(__x.get_allocator(), __x.size())
{ std::uninitialized_copy(__x.begin(), __x.end(), this->_M_start); } { std::uninitialized_copy(__x.begin(), __x.end(), this->_M_start); }
/** /**
* @brief Builds a %deque from a range. * @brief Builds a %deque from a range.
* @param first An input iterator. * @param first An input iterator.
* @param last An input iterator. * @param last An input iterator.
* *
* Create a %deque consisting of copies of the elements from [first,last). * Create a %deque consisting of copies of the elements from [first,
* * last).
* If the iterators are forward, bidirectional, or random-access, then *
* this will call the elements' copy constructor N times (where N is * If the iterators are forward, bidirectional, or random-access, then
* distance(first,last)) and do no memory reallocation. But if only * this will call the elements' copy constructor N times (where N is
* input iterators are used, then this will do at most 2N calls to the * distance(first,last)) and do no memory reallocation. But if only
* copy constructor, and logN memory reallocations. * input iterators are used, then this will do at most 2N calls to the
*/ * copy constructor, and logN memory reallocations.
template<typename _InputIterator> */
deque(_InputIterator __first, _InputIterator __last, template<typename _InputIterator>
const allocator_type& __a = allocator_type()) deque(_InputIterator __first, _InputIterator __last,
: _Base(__a) const allocator_type& __a = allocator_type())
: _Base(__a)
{
// Check whether it's an integral type. If so, it's not an iterator.
typedef typename _Is_integer<_InputIterator>::_Integral _Integral;
_M_initialize_dispatch(__first, __last, _Integral());
}
/**
* The dtor only erases the elements, and note that if the elements
* themselves are pointers, the pointed-to memory is not touched in any
* way. Managing the pointer is the user's responsibilty.
*/
~deque()
{ std::_Destroy(this->_M_start, this->_M_finish); }
/**
* @brief %Deque assignment operator.
* @param x A %deque of identical element and allocator types.
*
* All the elements of @a x are copied, but unlike the copy constructor,
* the allocator object is not copied.
*/
deque&
operator=(const deque& __x);
/**
* @brief Assigns a given value to a %deque.
* @param n Number of elements to be assigned.
* @param val Value to be assigned.
*
* This function fills a %deque with @a n copies of the given value.
* Note that the assignment completely changes the %deque and that the
* resulting %deque's size is the same as the number of elements assigned.
* Old data may be lost.
*/
void
assign(size_type __n, const value_type& __val)
{ _M_fill_assign(__n, __val); }
/**
* @brief Assigns a range to a %deque.
* @param first An input iterator.
* @param last An input iterator.
*
* This function fills a %deque with copies of the elements in the
* range [first,last).
*
* Note that the assignment completely changes the %deque and that the
* resulting %deque's size is the same as the number of elements
* assigned. Old data may be lost.
*/
template<typename _InputIterator>
void
assign(_InputIterator __first, _InputIterator __last)
{
typedef typename _Is_integer<_InputIterator>::_Integral _Integral;
_M_assign_dispatch(__first, __last, _Integral());
}
/// Get a copy of the memory allocation object.
allocator_type
get_allocator() const
{ return _Base::get_allocator(); }
// iterators
/**
* Returns a read/write iterator that points to the first element in the
* %deque. Iteration is done in ordinary element order.
*/
iterator
begin()
{ return this->_M_start; }
/**
* Returns a read-only (constant) iterator that points to the first
* element in the %deque. Iteration is done in ordinary element order.
*/
const_iterator
begin() const
{ return this->_M_start; }
/**
* Returns a read/write iterator that points one past the last element in
* the %deque. Iteration is done in ordinary element order.
*/
iterator
end()
{ return this->_M_finish; }
/**
* Returns a read-only (constant) iterator that points one past the last
* element in the %deque. Iteration is done in ordinary element order.
*/
const_iterator
end() const
{ return this->_M_finish; }
/**
* Returns a read/write reverse iterator that points to the last element
* in the %deque. Iteration is done in reverse element order.
*/
reverse_iterator
rbegin()
{ return reverse_iterator(this->_M_finish); }
/**
* Returns a read-only (constant) reverse iterator that points to the
* last element in the %deque. Iteration is done in reverse element
* order.
*/
const_reverse_iterator
rbegin() const
{ return const_reverse_iterator(this->_M_finish); }
/**
* Returns a read/write reverse iterator that points to one before the
* first element in the %deque. Iteration is done in reverse element
* order.
*/
reverse_iterator
rend() { return reverse_iterator(this->_M_start); }
/**
* Returns a read-only (constant) reverse iterator that points to one
* before the first element in the %deque. Iteration is done in reverse
* element order.
*/
const_reverse_iterator
rend() const
{ return const_reverse_iterator(this->_M_start); }
// [23.2.1.2] capacity
/** Returns the number of elements in the %deque. */
size_type
size() const
{ return this->_M_finish - this->_M_start; }
/** Returns the size() of the largest possible %deque. */
size_type
max_size() const
{ return size_type(-1); }
/**
* @brief Resizes the %deque to the specified number of elements.
* @param new_size Number of elements the %deque should contain.
* @param x Data with which new elements should be populated.
*
* This function will %resize the %deque to the specified number of
* elements. If the number is smaller than the %deque's current size the
* %deque is truncated, otherwise the %deque is extended and new elements
* are populated with given data.
*/
void
resize(size_type __new_size, const value_type& __x)
{ {
// Check whether it's an integral type. If so, it's not an iterator. const size_type __len = size();
typedef typename _Is_integer<_InputIterator>::_Integral _Integral; if (__new_size < __len)
_M_initialize_dispatch(__first, __last, _Integral()); erase(this->_M_start + __new_size, this->_M_finish);
else
insert(this->_M_finish, __new_size - __len, __x);
} }
/** /**
* The dtor only erases the elements, and note that if the elements * @brief Resizes the %deque to the specified number of elements.
* themselves are pointers, the pointed-to memory is not touched in any * @param new_size Number of elements the %deque should contain.
* way. Managing the pointer is the user's responsibilty. *
*/ * This function will resize the %deque to the specified number of
~deque() { std::_Destroy(this->_M_start, this->_M_finish); } * elements. If the number is smaller than the %deque's current size the
* %deque is truncated, otherwise the %deque is extended and new elements
/** * are default-constructed.
* @brief %Deque assignment operator. */
* @param x A %deque of identical element and allocator types.
*
* All the elements of @a x are copied, but unlike the copy constructor,
* the allocator object is not copied.
*/
deque&
operator=(const deque& __x);
/**
* @brief Assigns a given value to a %deque.
* @param n Number of elements to be assigned.
* @param val Value to be assigned.
*
* This function fills a %deque with @a n copies of the given value.
* Note that the assignment completely changes the %deque and that the
* resulting %deque's size is the same as the number of elements assigned.
* Old data may be lost.
*/
void
assign(size_type __n, const value_type& __val) { _M_fill_assign(__n, __val); }
/**
* @brief Assigns a range to a %deque.
* @param first An input iterator.
* @param last An input iterator.
*
* This function fills a %deque with copies of the elements in the
* range [first,last).
*
* Note that the assignment completely changes the %deque and that the
* resulting %deque's size is the same as the number of elements assigned.
* Old data may be lost.
*/
template<typename _InputIterator>
void void
assign(_InputIterator __first, _InputIterator __last) resize(size_type new_size)
{ resize(new_size, value_type()); }
/**
* Returns true if the %deque is empty. (Thus begin() would equal end().)
*/
bool
empty() const
{ return this->_M_finish == this->_M_start; }
// element access
/**
* @brief Subscript access to the data contained in the %deque.
* @param n The index of the element for which data should be accessed.
* @return Read/write reference to data.
*
* This operator allows for easy, array-style, data access.
* Note that data access with this operator is unchecked and out_of_range
* lookups are not defined. (For checked lookups see at().)
*/
reference
operator[](size_type __n)
{ return this->_M_start[difference_type(__n)]; }
/**
* @brief Subscript access to the data contained in the %deque.
* @param n The index of the element for which data should be accessed.
* @return Read-only (constant) reference to data.
*
* This operator allows for easy, array-style, data access.
* Note that data access with this operator is unchecked and out_of_range
* lookups are not defined. (For checked lookups see at().)
*/
const_reference
operator[](size_type __n) const
{ return this->_M_start[difference_type(__n)]; }
protected:
/// @if maint Safety check used only from at(). @endif
void
_M_range_check(size_type __n) const
{ {
typedef typename _Is_integer<_InputIterator>::_Integral _Integral; if (__n >= this->size())
_M_assign_dispatch(__first, __last, _Integral()); __throw_out_of_range(__N("deque::_M_range_check"));
} }
/// Get a copy of the memory allocation object. public:
allocator_type /**
get_allocator() const { return _Base::get_allocator(); } * @brief Provides access to the data contained in the %deque.
* @param n The index of the element for which data should be accessed.
// iterators * @return Read/write reference to data.
/** * @throw std::out_of_range If @a n is an invalid index.
* Returns a read/write iterator that points to the first element in the *
* %deque. Iteration is done in ordinary element order. * This function provides for safer data access. The parameter is first
*/ * checked that it is in the range of the deque. The function throws
iterator * out_of_range if the check fails.
begin() { return this->_M_start; } */
reference
/** at(size_type __n)
* Returns a read-only (constant) iterator that points to the first element { _M_range_check(__n); return (*this)[__n]; }
* in the %deque. Iteration is done in ordinary element order.
*/ /**
const_iterator * @brief Provides access to the data contained in the %deque.
begin() const { return this->_M_start; } * @param n The index of the element for which data should be accessed.
* @return Read-only (constant) reference to data.
/** * @throw std::out_of_range If @a n is an invalid index.
* Returns a read/write iterator that points one past the last element in *
* the %deque. Iteration is done in ordinary element order. * This function provides for safer data access. The parameter is first
*/ * checked that it is in the range of the deque. The function throws
iterator * out_of_range if the check fails.
end() { return this->_M_finish; } */
const_reference
/** at(size_type __n) const
* Returns a read-only (constant) iterator that points one past the last {
* element in the %deque. Iteration is done in ordinary element order. _M_range_check(__n);
*/ return (*this)[__n];
const_iterator
end() const { return this->_M_finish; }
/**
* Returns a read/write reverse iterator that points to the last element in
* the %deque. Iteration is done in reverse element order.
*/
reverse_iterator
rbegin() { return reverse_iterator(this->_M_finish); }
/**
* Returns a read-only (constant) reverse iterator that points to the last
* element in the %deque. Iteration is done in reverse element order.
*/
const_reverse_iterator
rbegin() const { return const_reverse_iterator(this->_M_finish); }
/**
* Returns a read/write reverse iterator that points to one before the
* first element in the %deque. Iteration is done in reverse element
* order.
*/
reverse_iterator
rend() { return reverse_iterator(this->_M_start); }
/**
* Returns a read-only (constant) reverse iterator that points to one
* before the first element in the %deque. Iteration is done in reverse
* element order.
*/
const_reverse_iterator
rend() const { return const_reverse_iterator(this->_M_start); }
// [23.2.1.2] capacity
/** Returns the number of elements in the %deque. */
size_type
size() const { return this->_M_finish - this->_M_start; }
/** Returns the size() of the largest possible %deque. */
size_type
max_size() const { return size_type(-1); }
/**
* @brief Resizes the %deque to the specified number of elements.
* @param new_size Number of elements the %deque should contain.
* @param x Data with which new elements should be populated.
*
* This function will %resize the %deque to the specified number of
* elements. If the number is smaller than the %deque's current size the
* %deque is truncated, otherwise the %deque is extended and new elements
* are populated with given data.
*/
void
resize(size_type __new_size, const value_type& __x)
{
const size_type __len = size();
if (__new_size < __len)
erase(this->_M_start + __new_size, this->_M_finish);
else
insert(this->_M_finish, __new_size - __len, __x);
}
/**
* @brief Resizes the %deque to the specified number of elements.
* @param new_size Number of elements the %deque should contain.
*
* This function will resize the %deque to the specified number of
* elements. If the number is smaller than the %deque's current size the
* %deque is truncated, otherwise the %deque is extended and new elements
* are default-constructed.
*/
void
resize(size_type new_size) { resize(new_size, value_type()); }
/**
* Returns true if the %deque is empty. (Thus begin() would equal end().)
*/
bool empty() const { return this->_M_finish == this->_M_start; }
// element access
/**
* @brief Subscript access to the data contained in the %deque.
* @param n The index of the element for which data should be accessed.
* @return Read/write reference to data.
*
* This operator allows for easy, array-style, data access.
* Note that data access with this operator is unchecked and out_of_range
* lookups are not defined. (For checked lookups see at().)
*/
reference
operator[](size_type __n) { return this->_M_start[difference_type(__n)]; }
/**
* @brief Subscript access to the data contained in the %deque.
* @param n The index of the element for which data should be accessed.
* @return Read-only (constant) reference to data.
*
* This operator allows for easy, array-style, data access.
* Note that data access with this operator is unchecked and out_of_range
* lookups are not defined. (For checked lookups see at().)
*/
const_reference
operator[](size_type __n) const {
return this->_M_start[difference_type(__n)];
}
protected:
/// @if maint Safety check used only from at(). @endif
void
_M_range_check(size_type __n) const
{
if (__n >= this->size())
__throw_out_of_range(__N("deque::_M_range_check"));
}
public:
/**
* @brief Provides access to the data contained in the %deque.
* @param n The index of the element for which data should be accessed.
* @return Read/write reference to data.
* @throw std::out_of_range If @a n is an invalid index.
*
* This function provides for safer data access. The parameter is first
* checked that it is in the range of the deque. The function throws
* out_of_range if the check fails.
*/
reference
at(size_type __n) { _M_range_check(__n); return (*this)[__n]; }
/**
* @brief Provides access to the data contained in the %deque.
* @param n The index of the element for which data should be accessed.
* @return Read-only (constant) reference to data.
* @throw std::out_of_range If @a n is an invalid index.
*
* This function provides for safer data access. The parameter is first
* checked that it is in the range of the deque. The function throws
* out_of_range if the check fails.
*/
const_reference
at(size_type __n) const { _M_range_check(__n); return (*this)[__n]; }
/**
* Returns a read/write reference to the data at the first element of the
* %deque.
*/
reference
front() { return *this->_M_start; }
/**
* Returns a read-only (constant) reference to the data at the first
* element of the %deque.
*/
const_reference
front() const { return *this->_M_start; }
/**
* Returns a read/write reference to the data at the last element of the
* %deque.
*/
reference
back()
{
iterator __tmp = this->_M_finish;
--__tmp;
return *__tmp;
}
/**
* Returns a read-only (constant) reference to the data at the last
* element of the %deque.
*/
const_reference
back() const
{
const_iterator __tmp = this->_M_finish;
--__tmp;
return *__tmp;
}
// [23.2.1.2] modifiers
/**
* @brief Add data to the front of the %deque.
* @param x Data to be added.
*
* This is a typical stack operation. The function creates an element at
* the front of the %deque and assigns the given data to it. Due to the
* nature of a %deque this operation can be done in constant time.
*/
void
push_front(const value_type& __x)
{
if (this->_M_start._M_cur != this->_M_start._M_first) {
std::_Construct(this->_M_start._M_cur - 1, __x);
--this->_M_start._M_cur;
}
else
_M_push_front_aux(__x);
}
/**
* @brief Add data to the end of the %deque.
* @param x Data to be added.
*
* This is a typical stack operation. The function creates an element at
* the end of the %deque and assigns the given data to it. Due to the
* nature of a %deque this operation can be done in constant time.
*/
void
push_back(const value_type& __x)
{
if (this->_M_finish._M_cur != this->_M_finish._M_last - 1) {
std::_Construct(this->_M_finish._M_cur, __x);
++this->_M_finish._M_cur;
} }
else
_M_push_back_aux(__x); /**
} * Returns a read/write reference to the data at the first element of the
* %deque.
/** */
* @brief Removes first element. reference
* front()
* This is a typical stack operation. It shrinks the %deque by one. { return *this->_M_start; }
*
* Note that no data is returned, and if the first element's data is /**
* needed, it should be retrieved before pop_front() is called. * Returns a read-only (constant) reference to the data at the first
*/ * element of the %deque.
void */
pop_front() const_reference
{ front() const
if (this->_M_start._M_cur != this->_M_start._M_last - 1) { { return *this->_M_start; }
std::_Destroy(this->_M_start._M_cur);
++this->_M_start._M_cur; /**
* Returns a read/write reference to the data at the last element of the
* %deque.
*/
reference
back()
{
iterator __tmp = this->_M_finish;
--__tmp;
return *__tmp;
} }
else
_M_pop_front_aux(); /**
} * Returns a read-only (constant) reference to the data at the last
* element of the %deque.
/** */
* @brief Removes last element. const_reference
* back() const
* This is a typical stack operation. It shrinks the %deque by one. {
* const_iterator __tmp = this->_M_finish;
* Note that no data is returned, and if the last element's data is --__tmp;
* needed, it should be retrieved before pop_back() is called. return *__tmp;
*/
void
pop_back()
{
if (this->_M_finish._M_cur != this->_M_finish._M_first) {
--this->_M_finish._M_cur;
std::_Destroy(this->_M_finish._M_cur);
} }
else
_M_pop_back_aux(); // [23.2.1.2] modifiers
} /**
* @brief Add data to the front of the %deque.
/** * @param x Data to be added.
* @brief Inserts given value into %deque before specified iterator. *
* @param position An iterator into the %deque. * This is a typical stack operation. The function creates an element at
* @param x Data to be inserted. * the front of the %deque and assigns the given data to it. Due to the
* @return An iterator that points to the inserted data. * nature of a %deque this operation can be done in constant time.
* */
* This function will insert a copy of the given value before the specified
* location.
*/
iterator
insert(iterator position, const value_type& __x);
/**
* @brief Inserts a number of copies of given data into the %deque.
* @param position An iterator into the %deque.
* @param n Number of elements to be inserted.
* @param x Data to be inserted.
*
* This function will insert a specified number of copies of the given data
* before the location specified by @a position.
*/
void
insert(iterator __position, size_type __n, const value_type& __x)
{ _M_fill_insert(__position, __n, __x); }
/**
* @brief Inserts a range into the %deque.
* @param position An iterator into the %deque.
* @param first An input iterator.
* @param last An input iterator.
*
* This function will insert copies of the data in the range [first,last)
* into the %deque before the location specified by @a pos. This is
* known as "range insert."
*/
template<typename _InputIterator>
void void
insert(iterator __position, _InputIterator __first, _InputIterator __last) push_front(const value_type& __x)
{ {
// Check whether it's an integral type. If so, it's not an iterator. if (this->_M_start._M_cur != this->_M_start._M_first)
typedef typename _Is_integer<_InputIterator>::_Integral _Integral; {
_M_insert_dispatch(__position, __first, __last, _Integral()); std::_Construct(this->_M_start._M_cur - 1, __x);
--this->_M_start._M_cur;
}
else
_M_push_front_aux(__x);
} }
/** /**
* @brief Remove element at given position. * @brief Add data to the end of the %deque.
* @param position Iterator pointing to element to be erased. * @param x Data to be added.
* @return An iterator pointing to the next element (or end()). *
* * This is a typical stack operation. The function creates an element at
* This function will erase the element at the given position and thus * the end of the %deque and assigns the given data to it. Due to the
* shorten the %deque by one. * nature of a %deque this operation can be done in constant time.
* */
* The user is cautioned that
* this function only erases the element, and that if the element is itself
* a pointer, the pointed-to memory is not touched in any way. Managing
* the pointer is the user's responsibilty.
*/
iterator
erase(iterator __position);
/**
* @brief Remove a range of elements.
* @param first Iterator pointing to the first element to be erased.
* @param last Iterator pointing to one past the last element to be
* erased.
* @return An iterator pointing to the element pointed to by @a last
* prior to erasing (or end()).
*
* This function will erase the elements in the range [first,last) and
* shorten the %deque accordingly.
*
* The user is cautioned that
* this function only erases the elements, and that if the elements
* themselves are pointers, the pointed-to memory is not touched in any
* way. Managing the pointer is the user's responsibilty.
*/
iterator
erase(iterator __first, iterator __last);
/**
* @brief Swaps data with another %deque.
* @param x A %deque of the same element and allocator types.
*
* This exchanges the elements between two deques in constant time.
* (Four pointers, so it should be quite fast.)
* Note that the global std::swap() function is specialized such that
* std::swap(d1,d2) will feed to this function.
*/
void
swap(deque& __x)
{
std::swap(this->_M_start, __x._M_start);
std::swap(this->_M_finish, __x._M_finish);
std::swap(this->_M_map, __x._M_map);
std::swap(this->_M_map_size, __x._M_map_size);
}
/**
* Erases all the elements. Note that this function only erases the
* elements, and that if the elements themselves are pointers, the
* pointed-to memory is not touched in any way. Managing the pointer is
* the user's responsibilty.
*/
void clear();
protected:
// Internal constructor functions follow.
// called by the range constructor to implement [23.1.1]/9
template<typename _Integer>
void void
_M_initialize_dispatch(_Integer __n, _Integer __x, __true_type) push_back(const value_type& __x)
{ {
_M_initialize_map(__n); if (this->_M_finish._M_cur != this->_M_finish._M_last - 1)
_M_fill_initialize(__x); {
std::_Construct(this->_M_finish._M_cur, __x);
++this->_M_finish._M_cur;
}
else
_M_push_back_aux(__x);
} }
// called by the range constructor to implement [23.1.1]/9 /**
template<typename _InputIterator> * @brief Removes first element.
*
* This is a typical stack operation. It shrinks the %deque by one.
*
* Note that no data is returned, and if the first element's data is
* needed, it should be retrieved before pop_front() is called.
*/
void void
_M_initialize_dispatch(_InputIterator __first, _InputIterator __last, pop_front()
__false_type)
{ {
typedef typename iterator_traits<_InputIterator>::iterator_category if (this->_M_start._M_cur != this->_M_start._M_last - 1)
_IterCategory; {
_M_range_initialize(__first, __last, _IterCategory()); std::_Destroy(this->_M_start._M_cur);
++this->_M_start._M_cur;
}
else
_M_pop_front_aux();
} }
// called by the second initialize_dispatch above /**
//@{ * @brief Removes last element.
/** *
* @if maint * This is a typical stack operation. It shrinks the %deque by one.
* @brief Fills the deque with whatever is in [first,last). *
* @param first An input iterator. * Note that no data is returned, and if the last element's data is
* @param last An input iterator. * needed, it should be retrieved before pop_back() is called.
* @return Nothing. */
*
* If the iterators are actually forward iterators (or better), then the
* memory layout can be done all at once. Else we move forward using
* push_back on each value from the iterator.
* @endif
*/
template<typename _InputIterator>
void void
_M_range_initialize(_InputIterator __first, _InputIterator __last, pop_back()
input_iterator_tag); {
if (this->_M_finish._M_cur != this->_M_finish._M_first)
// called by the second initialize_dispatch above {
template<typename _ForwardIterator> --this->_M_finish._M_cur;
std::_Destroy(this->_M_finish._M_cur);
}
else
_M_pop_back_aux();
}
/**
* @brief Inserts given value into %deque before specified iterator.
* @param position An iterator into the %deque.
* @param x Data to be inserted.
* @return An iterator that points to the inserted data.
*
* This function will insert a copy of the given value before the
* specified location.
*/
iterator
insert(iterator position, const value_type& __x);
/**
* @brief Inserts a number of copies of given data into the %deque.
* @param position An iterator into the %deque.
* @param n Number of elements to be inserted.
* @param x Data to be inserted.
*
* This function will insert a specified number of copies of the given
* data before the location specified by @a position.
*/
void void
_M_range_initialize(_ForwardIterator __first, _ForwardIterator __last, insert(iterator __position, size_type __n, const value_type& __x)
forward_iterator_tag); { _M_fill_insert(__position, __n, __x); }
//@}
/**
/** * @brief Inserts a range into the %deque.
* @if maint * @param position An iterator into the %deque.
* @brief Fills the %deque with copies of value. * @param first An input iterator.
* @param value Initial value. * @param last An input iterator.
* @return Nothing. *
* @pre _M_start and _M_finish have already been initialized, but none of * This function will insert copies of the data in the range [first,last)
* the %deque's elements have yet been constructed. * into the %deque before the location specified by @a pos. This is
* * known as "range insert."
* This function is called only when the user provides an explicit size */
* (with or without an explicit exemplar value). template<typename _InputIterator>
* @endif void
*/ insert(iterator __position, _InputIterator __first,
void _InputIterator __last)
_M_fill_initialize(const value_type& __value); {
// Check whether it's an integral type. If so, it's not an iterator.
typedef typename _Is_integer<_InputIterator>::_Integral _Integral;
// Internal assign functions follow. The *_aux functions do the actual _M_insert_dispatch(__position, __first, __last, _Integral());
// assignment work for the range versions. }
// called by the range assign to implement [23.1.1]/9 /**
template<typename _Integer> * @brief Remove element at given position.
* @param position Iterator pointing to element to be erased.
* @return An iterator pointing to the next element (or end()).
*
* This function will erase the element at the given position and thus
* shorten the %deque by one.
*
* The user is cautioned that
* this function only erases the element, and that if the element is
* itself a pointer, the pointed-to memory is not touched in any way.
* Managing the pointer is the user's responsibilty.
*/
iterator
erase(iterator __position);
/**
* @brief Remove a range of elements.
* @param first Iterator pointing to the first element to be erased.
* @param last Iterator pointing to one past the last element to be
* erased.
* @return An iterator pointing to the element pointed to by @a last
* prior to erasing (or end()).
*
* This function will erase the elements in the range [first,last) and
* shorten the %deque accordingly.
*
* The user is cautioned that
* this function only erases the elements, and that if the elements
* themselves are pointers, the pointed-to memory is not touched in any
* way. Managing the pointer is the user's responsibilty.
*/
iterator
erase(iterator __first, iterator __last);
/**
* @brief Swaps data with another %deque.
* @param x A %deque of the same element and allocator types.
*
* This exchanges the elements between two deques in constant time.
* (Four pointers, so it should be quite fast.)
* Note that the global std::swap() function is specialized such that
* std::swap(d1,d2) will feed to this function.
*/
void void
_M_assign_dispatch(_Integer __n, _Integer __val, __true_type) swap(deque& __x)
{ {
_M_fill_assign(static_cast<size_type>(__n), std::swap(this->_M_start, __x._M_start);
static_cast<value_type>(__val)); std::swap(this->_M_finish, __x._M_finish);
std::swap(this->_M_map, __x._M_map);
std::swap(this->_M_map_size, __x._M_map_size);
} }
// called by the range assign to implement [23.1.1]/9 /**
template<typename _InputIterator> * Erases all the elements. Note that this function only erases the
* elements, and that if the elements themselves are pointers, the
* pointed-to memory is not touched in any way. Managing the pointer is
* the user's responsibilty.
*/
void clear();
protected:
// Internal constructor functions follow.
// called by the range constructor to implement [23.1.1]/9
template<typename _Integer>
void
_M_initialize_dispatch(_Integer __n, _Integer __x, __true_type)
{
_M_initialize_map(__n);
_M_fill_initialize(__x);
}
// called by the range constructor to implement [23.1.1]/9
template<typename _InputIterator>
void
_M_initialize_dispatch(_InputIterator __first, _InputIterator __last,
__false_type)
{
typedef typename iterator_traits<_InputIterator>::iterator_category
_IterCategory;
_M_range_initialize(__first, __last, _IterCategory());
}
// called by the second initialize_dispatch above
//@{
/**
* @if maint
* @brief Fills the deque with whatever is in [first,last).
* @param first An input iterator.
* @param last An input iterator.
* @return Nothing.
*
* If the iterators are actually forward iterators (or better), then the
* memory layout can be done all at once. Else we move forward using
* push_back on each value from the iterator.
* @endif
*/
template<typename _InputIterator>
void
_M_range_initialize(_InputIterator __first, _InputIterator __last,
input_iterator_tag);
// called by the second initialize_dispatch above
template<typename _ForwardIterator>
void
_M_range_initialize(_ForwardIterator __first, _ForwardIterator __last,
forward_iterator_tag);
//@}
/**
* @if maint
* @brief Fills the %deque with copies of value.
* @param value Initial value.
* @return Nothing.
* @pre _M_start and _M_finish have already been initialized, but none of
* the %deque's elements have yet been constructed.
*
* This function is called only when the user provides an explicit size
* (with or without an explicit exemplar value).
* @endif
*/
void void
_M_assign_dispatch(_InputIterator __first, _InputIterator __last, __false_type) _M_fill_initialize(const value_type& __value);
// Internal assign functions follow. The *_aux functions do the actual
// assignment work for the range versions.
// called by the range assign to implement [23.1.1]/9
template<typename _Integer>
void
_M_assign_dispatch(_Integer __n, _Integer __val, __true_type)
{
_M_fill_assign(static_cast<size_type>(__n),
static_cast<value_type>(__val));
}
// called by the range assign to implement [23.1.1]/9
template<typename _InputIterator>
void
_M_assign_dispatch(_InputIterator __first, _InputIterator __last,
__false_type)
{
typedef typename iterator_traits<_InputIterator>::iterator_category
_IterCategory;
_M_assign_aux(__first, __last, _IterCategory());
}
// called by the second assign_dispatch above
template<typename _InputIterator>
void
_M_assign_aux(_InputIterator __first, _InputIterator __last,
input_iterator_tag);
// called by the second assign_dispatch above
template<typename _ForwardIterator>
void
_M_assign_aux(_ForwardIterator __first, _ForwardIterator __last,
forward_iterator_tag)
{
const size_type __len = std::distance(__first, __last);
if (__len > size())
{
_ForwardIterator __mid = __first;
std::advance(__mid, size());
std::copy(__first, __mid, begin());
insert(end(), __mid, __last);
}
else
erase(std::copy(__first, __last, begin()), end());
}
// Called by assign(n,t), and the range assign when it turns out to be the
// same thing.
void
_M_fill_assign(size_type __n, const value_type& __val)
{ {
typedef typename iterator_traits<_InputIterator>::iterator_category if (__n > size())
_IterCategory; {
_M_assign_aux(__first, __last, _IterCategory()); std::fill(begin(), end(), __val);
insert(end(), __n - size(), __val);
}
else
{
erase(begin() + __n, end());
std::fill(begin(), end(), __val);
}
} }
// called by the second assign_dispatch above //@{
template<typename _InputIterator> /**
* @if maint
* @brief Helper functions for push_* and pop_*.
* @endif
*/
void _M_push_back_aux(const value_type&);
void _M_push_front_aux(const value_type&);
void _M_pop_back_aux();
void _M_pop_front_aux();
//@}
// Internal insert functions follow. The *_aux functions do the actual
// insertion work when all shortcuts fail.
// called by the range insert to implement [23.1.1]/9
template<typename _Integer>
void
_M_insert_dispatch(iterator __pos,
_Integer __n, _Integer __x, __true_type)
{
_M_fill_insert(__pos, static_cast<size_type>(__n),
static_cast<value_type>(__x));
}
// called by the range insert to implement [23.1.1]/9
template<typename _InputIterator>
void
_M_insert_dispatch(iterator __pos,
_InputIterator __first, _InputIterator __last,
__false_type)
{
typedef typename iterator_traits<_InputIterator>::iterator_category
_IterCategory;
_M_range_insert_aux(__pos, __first, __last, _IterCategory());
}
// called by the second insert_dispatch above
template<typename _InputIterator>
void
_M_range_insert_aux(iterator __pos, _InputIterator __first,
_InputIterator __last, input_iterator_tag);
// called by the second insert_dispatch above
template<typename _ForwardIterator>
void
_M_range_insert_aux(iterator __pos, _ForwardIterator __first,
_ForwardIterator __last, forward_iterator_tag);
// Called by insert(p,n,x), and the range insert when it turns out to be
// the same thing. Can use fill functions in optimal situations,
// otherwise passes off to insert_aux(p,n,x).
void void
_M_assign_aux(_InputIterator __first, _InputIterator __last, _M_fill_insert(iterator __pos, size_type __n, const value_type& __x);
input_iterator_tag);
// called by the second assign_dispatch above // called by insert(p,x)
template<typename _ForwardIterator> iterator
void _M_insert_aux(iterator __pos, const value_type& __x);
_M_assign_aux(_ForwardIterator __first, _ForwardIterator __last,
forward_iterator_tag)
{
size_type __len = std::distance(__first, __last);
if (__len > size()) {
_ForwardIterator __mid = __first;
std::advance(__mid, size());
std::copy(__first, __mid, begin());
insert(end(), __mid, __last);
}
else
erase(std::copy(__first, __last, begin()), end());
}
// Called by assign(n,t), and the range assign when it turns out to be the // called by insert(p,n,x) via fill_insert
// same thing. void
void _M_insert_aux(iterator __pos, size_type __n, const value_type& __x);
_M_fill_assign(size_type __n, const value_type& __val)
{ // called by range_insert_aux for forward iterators
if (__n > size()) template<typename _ForwardIterator>
void
_M_insert_aux(iterator __pos,
_ForwardIterator __first, _ForwardIterator __last,
size_type __n);
//@{
/**
* @if maint
* @brief Memory-handling helpers for the previous internal insert
* functions.
* @endif
*/
iterator
_M_reserve_elements_at_front(size_type __n)
{ {
std::fill(begin(), end(), __val); const size_type __vacancies = this->_M_start._M_cur
insert(end(), __n - size(), __val); - this->_M_start._M_first;
if (__n > __vacancies)
_M_new_elements_at_front(__n - __vacancies);
return this->_M_start - difference_type(__n);
} }
else
iterator
_M_reserve_elements_at_back(size_type __n)
{ {
erase(begin() + __n, end()); const size_type __vacancies = (this->_M_finish._M_last
std::fill(begin(), end(), __val); - this->_M_finish._M_cur) - 1;
if (__n > __vacancies)
_M_new_elements_at_back(__n - __vacancies);
return this->_M_finish + difference_type(__n);
} }
}
void
_M_new_elements_at_front(size_type __new_elements);
//@{
/** void
* @if maint _M_new_elements_at_back(size_type __new_elements);
* @brief Helper functions for push_* and pop_*. //@}
* @endif
*/
void _M_push_back_aux(const value_type&); //@{
void _M_push_front_aux(const value_type&); /**
void _M_pop_back_aux(); * @if maint
void _M_pop_front_aux(); * @brief Memory-handling helpers for the major %map.
//@} *
* Makes sure the _M_map has space for new nodes. Does not actually add
* the nodes. Can invalidate _M_map pointers. (And consequently, %deque
// Internal insert functions follow. The *_aux functions do the actual * iterators.)
// insertion work when all shortcuts fail. * @endif
*/
// called by the range insert to implement [23.1.1]/9
template<typename _Integer>
void void
_M_insert_dispatch(iterator __pos, _M_reserve_map_at_back (size_type __nodes_to_add = 1)
_Integer __n, _Integer __x, __true_type)
{ {
_M_fill_insert(__pos, static_cast<size_type>(__n), if (__nodes_to_add + 1 > this->_M_map_size
static_cast<value_type>(__x)); - (this->_M_finish._M_node - this->_M_map))
_M_reallocate_map(__nodes_to_add, false);
} }
// called by the range insert to implement [23.1.1]/9
template<typename _InputIterator>
void void
_M_insert_dispatch(iterator __pos, _M_reserve_map_at_front (size_type __nodes_to_add = 1)
_InputIterator __first, _InputIterator __last,
__false_type)
{ {
typedef typename iterator_traits<_InputIterator>::iterator_category if (__nodes_to_add > size_type(this->_M_start._M_node - this->_M_map))
_IterCategory; _M_reallocate_map(__nodes_to_add, true);
_M_range_insert_aux(__pos, __first, __last, _IterCategory());
} }
// called by the second insert_dispatch above
template<typename _InputIterator>
void
_M_range_insert_aux(iterator __pos, _InputIterator __first,
_InputIterator __last, input_iterator_tag);
// called by the second insert_dispatch above
template<typename _ForwardIterator>
void void
_M_range_insert_aux(iterator __pos, _ForwardIterator __first, _M_reallocate_map(size_type __nodes_to_add, bool __add_at_front);
_ForwardIterator __last, forward_iterator_tag); //@}
};
// Called by insert(p,n,x), and the range insert when it turns out to be
// the same thing. Can use fill functions in optimal situations, otherwise
// passes off to insert_aux(p,n,x).
void
_M_fill_insert(iterator __pos, size_type __n, const value_type& __x);
// called by insert(p,x)
iterator
_M_insert_aux(iterator __pos, const value_type& __x);
// called by insert(p,n,x) via fill_insert
void
_M_insert_aux(iterator __pos, size_type __n, const value_type& __x);
// called by range_insert_aux for forward iterators
template<typename _ForwardIterator>
void
_M_insert_aux(iterator __pos,
_ForwardIterator __first, _ForwardIterator __last,
size_type __n);
//@{
/**
* @if maint
* @brief Memory-handling helpers for the previous internal insert
* functions.
* @endif
*/
iterator
_M_reserve_elements_at_front(size_type __n)
{
size_type __vacancies = this->_M_start._M_cur - this->_M_start._M_first;
if (__n > __vacancies)
_M_new_elements_at_front(__n - __vacancies);
return this->_M_start - difference_type(__n);
}
iterator
_M_reserve_elements_at_back(size_type __n)
{
size_type __vacancies
= (this->_M_finish._M_last - this->_M_finish._M_cur) - 1;
if (__n > __vacancies)
_M_new_elements_at_back(__n - __vacancies);
return this->_M_finish + difference_type(__n);
}
void
_M_new_elements_at_front(size_type __new_elements);
void
_M_new_elements_at_back(size_type __new_elements);
//@}
//@{
/**
* @if maint
* @brief Memory-handling helpers for the major %map.
*
* Makes sure the _M_map has space for new nodes. Does not actually add
* the nodes. Can invalidate _M_map pointers. (And consequently, %deque
* iterators.)
* @endif
*/
void
_M_reserve_map_at_back (size_type __nodes_to_add = 1)
{
if (__nodes_to_add + 1
> this->_M_map_size - (this->_M_finish._M_node - this->_M_map))
_M_reallocate_map(__nodes_to_add, false);
}
void
_M_reserve_map_at_front (size_type __nodes_to_add = 1)
{
if (__nodes_to_add > size_type(this->_M_start._M_node - this->_M_map))
_M_reallocate_map(__nodes_to_add, true);
}
void
_M_reallocate_map(size_type __nodes_to_add, bool __add_at_front);
//@}
};
/** /**
...@@ -1394,12 +1429,11 @@ namespace __gnu_norm ...@@ -1394,12 +1429,11 @@ namespace __gnu_norm
* and if corresponding elements compare equal. * and if corresponding elements compare equal.
*/ */
template<typename _Tp, typename _Alloc> template<typename _Tp, typename _Alloc>
inline bool operator==(const deque<_Tp, _Alloc>& __x, inline bool
operator==(const deque<_Tp, _Alloc>& __x,
const deque<_Tp, _Alloc>& __y) const deque<_Tp, _Alloc>& __y)
{ { return __x.size() == __y.size()
return __x.size() == __y.size() && && std::equal(__x.begin(), __x.end(), __y.begin()); }
std::equal(__x.begin(), __x.end(), __y.begin());
}
/** /**
* @brief Deque ordering relation. * @brief Deque ordering relation.
...@@ -1413,47 +1447,45 @@ namespace __gnu_norm ...@@ -1413,47 +1447,45 @@ namespace __gnu_norm
* See std::lexicographical_compare() for how the determination is made. * See std::lexicographical_compare() for how the determination is made.
*/ */
template<typename _Tp, typename _Alloc> template<typename _Tp, typename _Alloc>
inline bool operator<(const deque<_Tp, _Alloc>& __x, inline bool
const deque<_Tp, _Alloc>& __y) operator<(const deque<_Tp, _Alloc>& __x,
{ const deque<_Tp, _Alloc>& __y)
return lexicographical_compare(__x.begin(), __x.end(), { return lexicographical_compare(__x.begin(), __x.end(),
__y.begin(), __y.end()); __y.begin(), __y.end()); }
}
/// Based on operator== /// Based on operator==
template<typename _Tp, typename _Alloc> template<typename _Tp, typename _Alloc>
inline bool operator!=(const deque<_Tp, _Alloc>& __x, inline bool
const deque<_Tp, _Alloc>& __y) { operator!=(const deque<_Tp, _Alloc>& __x,
return !(__x == __y); const deque<_Tp, _Alloc>& __y)
} { return !(__x == __y); }
/// Based on operator< /// Based on operator<
template<typename _Tp, typename _Alloc> template<typename _Tp, typename _Alloc>
inline bool operator>(const deque<_Tp, _Alloc>& __x, inline bool
const deque<_Tp, _Alloc>& __y) { operator>(const deque<_Tp, _Alloc>& __x,
return __y < __x; const deque<_Tp, _Alloc>& __y)
} { return __y < __x; }
/// Based on operator< /// Based on operator<
template<typename _Tp, typename _Alloc> template<typename _Tp, typename _Alloc>
inline bool operator<=(const deque<_Tp, _Alloc>& __x, inline bool
const deque<_Tp, _Alloc>& __y) { operator<=(const deque<_Tp, _Alloc>& __x,
return !(__y < __x); const deque<_Tp, _Alloc>& __y)
} { return !(__y < __x); }
/// Based on operator< /// Based on operator<
template<typename _Tp, typename _Alloc> template<typename _Tp, typename _Alloc>
inline bool operator>=(const deque<_Tp, _Alloc>& __x, inline bool
const deque<_Tp, _Alloc>& __y) { operator>=(const deque<_Tp, _Alloc>& __x,
return !(__x < __y); const deque<_Tp, _Alloc>& __y)
} { return !(__x < __y); }
/// See std::deque::swap(). /// See std::deque::swap().
template<typename _Tp, typename _Alloc> template<typename _Tp, typename _Alloc>
inline void swap(deque<_Tp,_Alloc>& __x, deque<_Tp,_Alloc>& __y) inline void
{ swap(deque<_Tp,_Alloc>& __x, deque<_Tp,_Alloc>& __y)
__x.swap(__y); { __x.swap(__y); }
}
} // namespace __gnu_norm } // namespace __gnu_norm
#endif /* _DEQUE_H */ #endif /* _DEQUE_H */
// Functor implementations -*- C++ -*- // Functor implementations -*- C++ -*-
// Copyright (C) 2001, 2002 Free Software Foundation, Inc. // Copyright (C) 2001, 2002, 2004 Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the // software; you can redistribute it and/or modify it under the
...@@ -63,668 +63,812 @@ ...@@ -63,668 +63,812 @@
namespace std namespace std
{ {
// 20.3.1 base classes // 20.3.1 base classes
/** @defgroup s20_3_1_base Functor Base Classes /** @defgroup s20_3_1_base Functor Base Classes
* Function objects, or @e functors, are objects with an @c operator() * Function objects, or @e functors, are objects with an @c operator()
* defined and accessible. They can be passed as arguments to algorithm * defined and accessible. They can be passed as arguments to algorithm
* templates and used in place of a function pointer. Not only is the * templates and used in place of a function pointer. Not only is the
* resulting expressiveness of the library increased, but the generated * resulting expressiveness of the library increased, but the generated
* code can be more efficient than what you might write by hand. When we * code can be more efficient than what you might write by hand. When we
* refer to "functors," then, generally we include function pointers in * refer to "functors," then, generally we include function pointers in
* the description as well. * the description as well.
* *
* Often, functors are only created as temporaries passed to algorithm * Often, functors are only created as temporaries passed to algorithm
* calls, rather than being created as named variables. * calls, rather than being created as named variables.
* *
* Two examples taken from the standard itself follow. To perform a * Two examples taken from the standard itself follow. To perform a
* by-element addition of two vectors @c a and @c b containing @c double, * by-element addition of two vectors @c a and @c b containing @c double,
* and put the result in @c a, use * and put the result in @c a, use
* \code * \code
* transform (a.begin(), a.end(), b.begin(), a.begin(), plus<double>()); * transform (a.begin(), a.end(), b.begin(), a.begin(), plus<double>());
* \endcode * \endcode
* To negate every element in @c a, use * To negate every element in @c a, use
* \code * \code
* transform(a.begin(), a.end(), a.begin(), negate<double>()); * transform(a.begin(), a.end(), a.begin(), negate<double>());
* \endcode * \endcode
* The addition and negation functions will be inlined directly. * The addition and negation functions will be inlined directly.
* *
* The standard functiors are derived from structs named @c unary_function * The standard functiors are derived from structs named @c unary_function
* and @c binary_function. These two classes contain nothing but typedefs, * and @c binary_function. These two classes contain nothing but typedefs,
* to aid in generic (template) programming. If you write your own * to aid in generic (template) programming. If you write your own
* functors, you might consider doing the same. * functors, you might consider doing the same.
* *
* @{ * @{
*/ */
/** /**
* This is one of the @link s20_3_1_base functor base classes@endlink. * This is one of the @link s20_3_1_base functor base classes@endlink.
*/ */
template <class _Arg, class _Result> template <class _Arg, class _Result>
struct unary_function { struct unary_function
typedef _Arg argument_type; ///< @c argument_type is the type of the argument (no surprises here) {
typedef _Result result_type; ///< @c result_type is the return type typedef _Arg argument_type; ///< @c argument_type is the type of the
}; /// argument (no surprises here)
/** typedef _Result result_type; ///< @c result_type is the return type
* This is one of the @link s20_3_1_base functor base classes@endlink. };
*/
template <class _Arg1, class _Arg2, class _Result> /**
struct binary_function { * This is one of the @link s20_3_1_base functor base classes@endlink.
typedef _Arg1 first_argument_type; ///< the type of the first argument (no surprises here) */
typedef _Arg2 second_argument_type; ///< the type of the second argument template <class _Arg1, class _Arg2, class _Result>
typedef _Result result_type; ///< type of the return type struct binary_function
}; {
/** @} */ typedef _Arg1 first_argument_type; ///< the type of the first argument
/// (no surprises here)
// 20.3.2 arithmetic
/** @defgroup s20_3_2_arithmetic Arithmetic Classes typedef _Arg2 second_argument_type; ///< the type of the second argument
* Because basic math often needs to be done during an algorithm, the library typedef _Result result_type; ///< type of the return type
* provides functors for those operations. See the documentation for };
* @link s20_3_1_base the base classes@endlink for examples of their use. /** @} */
*
* @{ // 20.3.2 arithmetic
*/ /** @defgroup s20_3_2_arithmetic Arithmetic Classes
/// One of the @link s20_3_2_arithmetic math functors@endlink. * Because basic math often needs to be done during an algorithm, the library
template <class _Tp> * provides functors for those operations. See the documentation for
struct plus : public binary_function<_Tp,_Tp,_Tp> { * @link s20_3_1_base the base classes@endlink for examples of their use.
_Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x + __y; } *
}; * @{
*/
/// One of the @link s20_3_2_arithmetic math functors@endlink. /// One of the @link s20_3_2_arithmetic math functors@endlink.
template <class _Tp> template <class _Tp>
struct minus : public binary_function<_Tp,_Tp,_Tp> { struct plus : public binary_function<_Tp,_Tp,_Tp>
_Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x - __y; } {
}; _Tp
operator()(const _Tp& __x, const _Tp& __y) const
/// One of the @link s20_3_2_arithmetic math functors@endlink. { return __x + __y; }
template <class _Tp> };
struct multiplies : public binary_function<_Tp,_Tp,_Tp> {
_Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x * __y; } /// One of the @link s20_3_2_arithmetic math functors@endlink.
}; template <class _Tp>
struct minus : public binary_function<_Tp,_Tp,_Tp>
/// One of the @link s20_3_2_arithmetic math functors@endlink. {
template <class _Tp> _Tp
struct divides : public binary_function<_Tp,_Tp,_Tp> { operator()(const _Tp& __x, const _Tp& __y) const
_Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x / __y; } { return __x - __y; }
}; };
/// One of the @link s20_3_2_arithmetic math functors@endlink. /// One of the @link s20_3_2_arithmetic math functors@endlink.
template <class _Tp> template <class _Tp>
struct modulus : public binary_function<_Tp,_Tp,_Tp> struct multiplies : public binary_function<_Tp,_Tp,_Tp>
{ {
_Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x % __y; } _Tp
}; operator()(const _Tp& __x, const _Tp& __y) const
{ return __x * __y; }
/// One of the @link s20_3_2_arithmetic math functors@endlink. };
template <class _Tp>
struct negate : public unary_function<_Tp,_Tp> /// One of the @link s20_3_2_arithmetic math functors@endlink.
{ template <class _Tp>
_Tp operator()(const _Tp& __x) const { return -__x; } struct divides : public binary_function<_Tp,_Tp,_Tp>
}; {
/** @} */ _Tp
operator()(const _Tp& __x, const _Tp& __y) const
// 20.3.3 comparisons { return __x / __y; }
/** @defgroup s20_3_3_comparisons Comparison Classes };
* The library provides six wrapper functors for all the basic comparisons
* in C++, like @c <. /// One of the @link s20_3_2_arithmetic math functors@endlink.
* template <class _Tp>
* @{ struct modulus : public binary_function<_Tp,_Tp,_Tp>
*/ {
/// One of the @link s20_3_3_comparisons comparison functors@endlink. _Tp
template <class _Tp> operator()(const _Tp& __x, const _Tp& __y) const
struct equal_to : public binary_function<_Tp,_Tp,bool> { return __x % __y; }
{ };
bool operator()(const _Tp& __x, const _Tp& __y) const { return __x == __y; }
}; /// One of the @link s20_3_2_arithmetic math functors@endlink.
template <class _Tp>
/// One of the @link s20_3_3_comparisons comparison functors@endlink. struct negate : public unary_function<_Tp,_Tp>
template <class _Tp> {
struct not_equal_to : public binary_function<_Tp,_Tp,bool> _Tp
{ operator()(const _Tp& __x) const
bool operator()(const _Tp& __x, const _Tp& __y) const { return __x != __y; } { return -__x; }
}; };
/** @} */
/// One of the @link s20_3_3_comparisons comparison functors@endlink.
template <class _Tp> // 20.3.3 comparisons
struct greater : public binary_function<_Tp,_Tp,bool> /** @defgroup s20_3_3_comparisons Comparison Classes
{ * The library provides six wrapper functors for all the basic comparisons
bool operator()(const _Tp& __x, const _Tp& __y) const { return __x > __y; } * in C++, like @c <.
}; *
* @{
/// One of the @link s20_3_3_comparisons comparison functors@endlink. */
template <class _Tp> /// One of the @link s20_3_3_comparisons comparison functors@endlink.
struct less : public binary_function<_Tp,_Tp,bool> template <class _Tp>
{ struct equal_to : public binary_function<_Tp,_Tp,bool>
bool operator()(const _Tp& __x, const _Tp& __y) const { return __x < __y; } {
}; bool
operator()(const _Tp& __x, const _Tp& __y) const
/// One of the @link s20_3_3_comparisons comparison functors@endlink. { return __x == __y; }
template <class _Tp> };
struct greater_equal : public binary_function<_Tp,_Tp,bool>
{ /// One of the @link s20_3_3_comparisons comparison functors@endlink.
bool operator()(const _Tp& __x, const _Tp& __y) const { return __x >= __y; } template <class _Tp>
}; struct not_equal_to : public binary_function<_Tp,_Tp,bool>
{
/// One of the @link s20_3_3_comparisons comparison functors@endlink. bool
template <class _Tp> operator()(const _Tp& __x, const _Tp& __y) const
struct less_equal : public binary_function<_Tp,_Tp,bool> { return __x != __y; }
{ };
bool operator()(const _Tp& __x, const _Tp& __y) const { return __x <= __y; }
}; /// One of the @link s20_3_3_comparisons comparison functors@endlink.
/** @} */ template <class _Tp>
struct greater : public binary_function<_Tp,_Tp,bool>
// 20.3.4 logical operations {
/** @defgroup s20_3_4_logical Boolean Operations Classes bool
* Here are wrapper functors for Boolean operations: @c &&, @c ||, and @c !. operator()(const _Tp& __x, const _Tp& __y) const
* { return __x > __y; }
* @{ };
*/
/// One of the @link s20_3_4_logical Boolean operations functors@endlink. /// One of the @link s20_3_3_comparisons comparison functors@endlink.
template <class _Tp> template <class _Tp>
struct logical_and : public binary_function<_Tp,_Tp,bool> struct less : public binary_function<_Tp,_Tp,bool>
{ {
bool operator()(const _Tp& __x, const _Tp& __y) const { return __x && __y; } bool
}; operator()(const _Tp& __x, const _Tp& __y) const
{ return __x < __y; }
};
/// One of the @link s20_3_3_comparisons comparison functors@endlink.
template <class _Tp>
struct greater_equal : public binary_function<_Tp,_Tp,bool>
{
bool
operator()(const _Tp& __x, const _Tp& __y) const
{ return __x >= __y; }
};
/// One of the @link s20_3_3_comparisons comparison functors@endlink.
template <class _Tp>
struct less_equal : public binary_function<_Tp,_Tp,bool>
{
bool
operator()(const _Tp& __x, const _Tp& __y) const
{ return __x <= __y; }
};
/** @} */
// 20.3.4 logical operations
/** @defgroup s20_3_4_logical Boolean Operations Classes
* Here are wrapper functors for Boolean operations: @c &&, @c ||, and @c !.
*
* @{
*/
/// One of the @link s20_3_4_logical Boolean operations functors@endlink.
template <class _Tp>
struct logical_and : public binary_function<_Tp,_Tp,bool>
{
bool
operator()(const _Tp& __x, const _Tp& __y) const
{ return __x && __y; }
};
/// One of the @link s20_3_4_logical Boolean operations functors@endlink.
template <class _Tp>
struct logical_or : public binary_function<_Tp,_Tp,bool>
{
bool
operator()(const _Tp& __x, const _Tp& __y) const
{ return __x || __y; }
};
/// One of the @link s20_3_4_logical Boolean operations functors@endlink.
template <class _Tp>
struct logical_not : public unary_function<_Tp,bool>
{
bool
operator()(const _Tp& __x) const
{ return !__x; }
};
/** @} */
// 20.3.5 negators
/** @defgroup s20_3_5_negators Negators
* The functions @c not1 and @c not2 each take a predicate functor
* and return an instance of @c unary_negate or
* @c binary_negate, respectively. These classes are functors whose
* @c operator() performs the stored predicate function and then returns
* the negation of the result.
*
* For example, given a vector of integers and a trivial predicate,
* \code
* struct IntGreaterThanThree
* : public std::unary_function<int, bool>
* {
* bool operator() (int x) { return x > 3; }
* };
*
* std::find_if (v.begin(), v.end(), not1(IntGreaterThanThree()));
* \endcode
* The call to @c find_if will locate the first index (i) of @c v for which
* "!(v[i] > 3)" is true.
*
* The not1/unary_negate combination works on predicates taking a single
* argument. The not2/binary_negate combination works on predicates which
* take two arguments.
*
* @{
*/
/// One of the @link s20_3_5_negators negation functors@endlink.
template <class _Predicate>
class unary_negate
: public unary_function<typename _Predicate::argument_type, bool>
{
protected:
_Predicate _M_pred;
public:
explicit unary_negate(const _Predicate& __x) : _M_pred(__x) {}
bool
operator()(const typename _Predicate::argument_type& __x) const
{ return !_M_pred(__x); }
};
/// One of the @link s20_3_5_negators negation functors@endlink.
template <class _Predicate>
inline unary_negate<_Predicate>
not1(const _Predicate& __pred)
{ return unary_negate<_Predicate>(__pred); }
/// One of the @link s20_3_5_negators negation functors@endlink.
template <class _Predicate>
class binary_negate
: public binary_function<typename _Predicate::first_argument_type,
typename _Predicate::second_argument_type,
bool>
{
protected:
_Predicate _M_pred;
public:
explicit binary_negate(const _Predicate& __x)
: _M_pred(__x) { }
bool
operator()(const typename _Predicate::first_argument_type& __x,
const typename _Predicate::second_argument_type& __y) const
{ return !_M_pred(__x, __y); }
};
/// One of the @link s20_3_5_negators negation functors@endlink.
template <class _Predicate>
inline binary_negate<_Predicate>
not2(const _Predicate& __pred)
{ return binary_negate<_Predicate>(__pred); }
/** @} */
// 20.3.6 binders
/** @defgroup s20_3_6_binder Binder Classes
* Binders turn functions/functors with two arguments into functors with
* a single argument, storing an argument to be applied later. For
* example, an variable @c B of type @c binder1st is constructed from a
* functor @c f and an argument @c x. Later, B's @c operator() is called
* with a single argument @c y. The return value is the value of @c f(x,y).
* @c B can be "called" with various arguments (y1, y2, ...) and will in
* turn call @c f(x,y1), @c f(x,y2), ...
*
* The function @c bind1st is provided to save some typing. It takes the
* function and an argument as parameters, and returns an instance of
* @c binder1st.
*
* The type @c binder2nd and its creator function @c bind2nd do the same
* thing, but the stored argument is passed as the second parameter instead
* of the first, e.g., @c bind2nd(std::minus<float>,1.3) will create a
* functor whose @c operator() accepts a floating-point number, subtracts
* 1.3 from it, and returns the result. (If @c bind1st had been used,
* the functor would perform "1.3 - x" instead.
*
* Creator-wrapper functions like @c bind1st are intended to be used in
* calling algorithms. Their return values will be temporary objects.
* (The goal is to not require you to type names like
* @c std::binder1st<std::plus<int>> for declaring a variable to hold the
* return value from @c bind1st(std::plus<int>,5).
*
* These become more useful when combined with the composition functions.
*
* @{
*/
/// One of the @link s20_3_6_binder binder functors@endlink.
template <class _Operation>
class binder1st
: public unary_function<typename _Operation::second_argument_type,
typename _Operation::result_type>
{
protected:
_Operation op;
typename _Operation::first_argument_type value;
public:
binder1st(const _Operation& __x,
const typename _Operation::first_argument_type& __y)
: op(__x), value(__y) {}
typename _Operation::result_type
operator()(const typename _Operation::second_argument_type& __x) const
{ return op(value, __x); }
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 109. Missing binders for non-const sequence elements
typename _Operation::result_type
operator()(typename _Operation::second_argument_type& __x) const
{ return op(value, __x); }
};
/// One of the @link s20_3_6_binder binder functors@endlink.
template <class _Operation, class _Tp>
inline binder1st<_Operation>
bind1st(const _Operation& __fn, const _Tp& __x)
{
typedef typename _Operation::first_argument_type _Arg1_type;
return binder1st<_Operation>(__fn, _Arg1_type(__x));
}
/// One of the @link s20_3_4_logical Boolean operations functors@endlink. /// One of the @link s20_3_6_binder binder functors@endlink.
template <class _Tp> template <class _Operation>
struct logical_or : public binary_function<_Tp,_Tp,bool> class binder2nd
{ : public unary_function<typename _Operation::first_argument_type,
bool operator()(const _Tp& __x, const _Tp& __y) const { return __x || __y; } typename _Operation::result_type>
}; {
protected:
_Operation op;
typename _Operation::second_argument_type value;
public:
binder2nd(const _Operation& __x,
const typename _Operation::second_argument_type& __y)
: op(__x), value(__y) {}
typename _Operation::result_type
operator()(const typename _Operation::first_argument_type& __x) const
{ return op(__x, value); }
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 109. Missing binders for non-const sequence elements
typename _Operation::result_type
operator()(typename _Operation::first_argument_type& __x) const
{ return op(__x, value); }
};
/// One of the @link s20_3_6_binder binder functors@endlink.
template <class _Operation, class _Tp>
inline binder2nd<_Operation>
bind2nd(const _Operation& __fn, const _Tp& __x)
{
typedef typename _Operation::second_argument_type _Arg2_type;
return binder2nd<_Operation>(__fn, _Arg2_type(__x));
}
/** @} */
// 20.3.7 adaptors pointers functions
/** @defgroup s20_3_7_adaptors Adaptors for pointers to functions
* The advantage of function objects over pointers to functions is that
* the objects in the standard library declare nested typedefs describing
* their argument and result types with uniform names (e.g., @c result_type
* from the base classes @c unary_function and @c binary_function).
* Sometimes those typedefs are required, not just optional.
*
* Adaptors are provided to turn pointers to unary (single-argument) and
* binary (double-argument) functions into function objects. The
* long-winded functor @c pointer_to_unary_function is constructed with a
* function pointer @c f, and its @c operator() called with argument @c x
* returns @c f(x). The functor @c pointer_to_binary_function does the same
* thing, but with a double-argument @c f and @c operator().
*
* The function @c ptr_fun takes a pointer-to-function @c f and constructs
* an instance of the appropriate functor.
*
* @{
*/
/// One of the @link s20_3_7_adaptors adaptors for function pointers@endlink.
template <class _Arg, class _Result>
class pointer_to_unary_function : public unary_function<_Arg, _Result>
{
protected:
_Result (*_M_ptr)(_Arg);
public:
pointer_to_unary_function() {}
explicit pointer_to_unary_function(_Result (*__x)(_Arg))
: _M_ptr(__x) {}
/// One of the @link s20_3_4_logical Boolean operations functors@endlink. _Result
template <class _Tp> operator()(_Arg __x) const
struct logical_not : public unary_function<_Tp,bool> { return _M_ptr(__x); }
{ };
bool operator()(const _Tp& __x) const { return !__x; }
}; /// One of the @link s20_3_7_adaptors adaptors for function pointers@endlink.
/** @} */ template <class _Arg, class _Result>
inline pointer_to_unary_function<_Arg, _Result>
// 20.3.5 negators ptr_fun(_Result (*__x)(_Arg))
/** @defgroup s20_3_5_negators Negators { return pointer_to_unary_function<_Arg, _Result>(__x); }
* The functions @c not1 and @c not2 each take a predicate functor
* and return an instance of @c unary_negate or /// One of the @link s20_3_7_adaptors adaptors for function pointers@endlink.
* @c binary_negate, respectively. These classes are functors whose template <class _Arg1, class _Arg2, class _Result>
* @c operator() performs the stored predicate function and then returns class pointer_to_binary_function
* the negation of the result. : public binary_function<_Arg1, _Arg2, _Result>
* {
* For example, given a vector of integers and a trivial predicate, protected:
* \code _Result (*_M_ptr)(_Arg1, _Arg2);
* struct IntGreaterThanThree public:
* : public std::unary_function<int, bool> pointer_to_binary_function() {}
* {
* bool operator() (int x) { return x > 3; } explicit pointer_to_binary_function(_Result (*__x)(_Arg1, _Arg2))
* };
*
* std::find_if (v.begin(), v.end(), not1(IntGreaterThanThree()));
* \endcode
* The call to @c find_if will locate the first index (i) of @c v for which
* "!(v[i] > 3)" is true.
*
* The not1/unary_negate combination works on predicates taking a single
* argument. The not2/binary_negate combination works on predicates which
* take two arguments.
*
* @{
*/
/// One of the @link s20_3_5_negators negation functors@endlink.
template <class _Predicate>
class unary_negate
: public unary_function<typename _Predicate::argument_type, bool> {
protected:
_Predicate _M_pred;
public:
explicit unary_negate(const _Predicate& __x) : _M_pred(__x) {}
bool operator()(const typename _Predicate::argument_type& __x) const {
return !_M_pred(__x);
}
};
/// One of the @link s20_3_5_negators negation functors@endlink.
template <class _Predicate>
inline unary_negate<_Predicate>
not1(const _Predicate& __pred)
{
return unary_negate<_Predicate>(__pred);
}
/// One of the @link s20_3_5_negators negation functors@endlink.
template <class _Predicate>
class binary_negate
: public binary_function<typename _Predicate::first_argument_type,
typename _Predicate::second_argument_type,
bool> {
protected:
_Predicate _M_pred;
public:
explicit binary_negate(const _Predicate& __x) : _M_pred(__x) {}
bool operator()(const typename _Predicate::first_argument_type& __x,
const typename _Predicate::second_argument_type& __y) const
{
return !_M_pred(__x, __y);
}
};
/// One of the @link s20_3_5_negators negation functors@endlink.
template <class _Predicate>
inline binary_negate<_Predicate>
not2(const _Predicate& __pred)
{
return binary_negate<_Predicate>(__pred);
}
/** @} */
// 20.3.6 binders
/** @defgroup s20_3_6_binder Binder Classes
* Binders turn functions/functors with two arguments into functors with
* a single argument, storing an argument to be applied later. For
* example, an variable @c B of type @c binder1st is constructed from a functor
* @c f and an argument @c x. Later, B's @c operator() is called with a
* single argument @c y. The return value is the value of @c f(x,y).
* @c B can be "called" with various arguments (y1, y2, ...) and will in
* turn call @c f(x,y1), @c f(x,y2), ...
*
* The function @c bind1st is provided to save some typing. It takes the
* function and an argument as parameters, and returns an instance of
* @c binder1st.
*
* The type @c binder2nd and its creator function @c bind2nd do the same
* thing, but the stored argument is passed as the second parameter instead
* of the first, e.g., @c bind2nd(std::minus<float>,1.3) will create a
* functor whose @c operator() accepts a floating-point number, subtracts
* 1.3 from it, and returns the result. (If @c bind1st had been used,
* the functor would perform "1.3 - x" instead.
*
* Creator-wrapper functions like @c bind1st are intended to be used in
* calling algorithms. Their return values will be temporary objects.
* (The goal is to not require you to type names like
* @c std::binder1st<std::plus<int>> for declaring a variable to hold the
* return value from @c bind1st(std::plus<int>,5).
*
* These become more useful when combined with the composition functions.
*
* @{
*/
/// One of the @link s20_3_6_binder binder functors@endlink.
template <class _Operation>
class binder1st
: public unary_function<typename _Operation::second_argument_type,
typename _Operation::result_type> {
protected:
_Operation op;
typename _Operation::first_argument_type value;
public:
binder1st(const _Operation& __x,
const typename _Operation::first_argument_type& __y)
: op(__x), value(__y) {}
typename _Operation::result_type
operator()(const typename _Operation::second_argument_type& __x) const {
return op(value, __x);
}
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 109. Missing binders for non-const sequence elements
typename _Operation::result_type
operator()(typename _Operation::second_argument_type& __x) const {
return op(value, __x);
}
};
/// One of the @link s20_3_6_binder binder functors@endlink.
template <class _Operation, class _Tp>
inline binder1st<_Operation>
bind1st(const _Operation& __fn, const _Tp& __x)
{
typedef typename _Operation::first_argument_type _Arg1_type;
return binder1st<_Operation>(__fn, _Arg1_type(__x));
}
/// One of the @link s20_3_6_binder binder functors@endlink.
template <class _Operation>
class binder2nd
: public unary_function<typename _Operation::first_argument_type,
typename _Operation::result_type> {
protected:
_Operation op;
typename _Operation::second_argument_type value;
public:
binder2nd(const _Operation& __x,
const typename _Operation::second_argument_type& __y)
: op(__x), value(__y) {}
typename _Operation::result_type
operator()(const typename _Operation::first_argument_type& __x) const {
return op(__x, value);
}
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 109. Missing binders for non-const sequence elements
typename _Operation::result_type
operator()(typename _Operation::first_argument_type& __x) const {
return op(__x, value);
}
};
/// One of the @link s20_3_6_binder binder functors@endlink.
template <class _Operation, class _Tp>
inline binder2nd<_Operation>
bind2nd(const _Operation& __fn, const _Tp& __x)
{
typedef typename _Operation::second_argument_type _Arg2_type;
return binder2nd<_Operation>(__fn, _Arg2_type(__x));
}
/** @} */
// 20.3.7 adaptors pointers functions
/** @defgroup s20_3_7_adaptors Adaptors for pointers to functions
* The advantage of function objects over pointers to functions is that
* the objects in the standard library declare nested typedefs describing
* their argument and result types with uniform names (e.g., @c result_type
* from the base classes @c unary_function and @c binary_function).
* Sometimes those typedefs are required, not just optional.
*
* Adaptors are provided to turn pointers to unary (single-argument) and
* binary (double-argument) functions into function objects. The long-winded
* functor @c pointer_to_unary_function is constructed with a function
* pointer @c f, and its @c operator() called with argument @c x returns
* @c f(x). The functor @c pointer_to_binary_function does the same thing,
* but with a double-argument @c f and @c operator().
*
* The function @c ptr_fun takes a pointer-to-function @c f and constructs
* an instance of the appropriate functor.
*
* @{
*/
/// One of the @link s20_3_7_adaptors adaptors for function pointers@endlink.
template <class _Arg, class _Result>
class pointer_to_unary_function : public unary_function<_Arg, _Result> {
protected:
_Result (*_M_ptr)(_Arg);
public:
pointer_to_unary_function() {}
explicit pointer_to_unary_function(_Result (*__x)(_Arg)) : _M_ptr(__x) {}
_Result operator()(_Arg __x) const { return _M_ptr(__x); }
};
/// One of the @link s20_3_7_adaptors adaptors for function pointers@endlink.
template <class _Arg, class _Result>
inline pointer_to_unary_function<_Arg, _Result> ptr_fun(_Result (*__x)(_Arg))
{
return pointer_to_unary_function<_Arg, _Result>(__x);
}
/// One of the @link s20_3_7_adaptors adaptors for function pointers@endlink.
template <class _Arg1, class _Arg2, class _Result>
class pointer_to_binary_function :
public binary_function<_Arg1,_Arg2,_Result> {
protected:
_Result (*_M_ptr)(_Arg1, _Arg2);
public:
pointer_to_binary_function() {}
explicit pointer_to_binary_function(_Result (*__x)(_Arg1, _Arg2))
: _M_ptr(__x) {} : _M_ptr(__x) {}
_Result operator()(_Arg1 __x, _Arg2 __y) const {
return _M_ptr(__x, __y);
}
};
/// One of the @link s20_3_7_adaptors adaptors for function pointers@endlink.
template <class _Arg1, class _Arg2, class _Result>
inline pointer_to_binary_function<_Arg1,_Arg2,_Result>
ptr_fun(_Result (*__x)(_Arg1, _Arg2)) {
return pointer_to_binary_function<_Arg1,_Arg2,_Result>(__x);
}
/** @} */
template <class _Tp>
struct _Identity : public unary_function<_Tp,_Tp> {
_Tp& operator()(_Tp& __x) const { return __x; }
const _Tp& operator()(const _Tp& __x) const { return __x; }
};
template <class _Pair>
struct _Select1st : public unary_function<_Pair, typename _Pair::first_type> {
typename _Pair::first_type& operator()(_Pair& __x) const {
return __x.first;
}
const typename _Pair::first_type& operator()(const _Pair& __x) const {
return __x.first;
}
};
template <class _Pair>
struct _Select2nd : public unary_function<_Pair, typename _Pair::second_type>
{
typename _Pair::second_type& operator()(_Pair& __x) const {
return __x.second;
}
const typename _Pair::second_type& operator()(const _Pair& __x) const {
return __x.second;
}
};
// 20.3.8 adaptors pointers members
/** @defgroup s20_3_8_memadaptors Adaptors for pointers to members
* There are a total of 16 = 2^4 function objects in this family.
* (1) Member functions taking no arguments vs member functions taking
* one argument.
* (2) Call through pointer vs call through reference.
* (3) Member function with void return type vs member function with
* non-void return type.
* (4) Const vs non-const member function.
*
* Note that choice (3) is nothing more than a workaround: according
* to the draft, compilers should handle void and non-void the same way.
* This feature is not yet widely implemented, though. You can only use
* member functions returning void if your compiler supports partial
* specialization.
*
* All of this complexity is in the function objects themselves. You can
* ignore it by using the helper function mem_fun and mem_fun_ref,
* which create whichever type of adaptor is appropriate.
*
* @{
*/
/// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
template <class _Ret, class _Tp>
class mem_fun_t : public unary_function<_Tp*,_Ret> {
public:
explicit mem_fun_t(_Ret (_Tp::*__pf)()) : _M_f(__pf) {}
_Ret operator()(_Tp* __p) const { return (__p->*_M_f)(); }
private:
_Ret (_Tp::*_M_f)();
};
/// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
template <class _Ret, class _Tp>
class const_mem_fun_t : public unary_function<const _Tp*,_Ret> {
public:
explicit const_mem_fun_t(_Ret (_Tp::*__pf)() const) : _M_f(__pf) {}
_Ret operator()(const _Tp* __p) const { return (__p->*_M_f)(); }
private:
_Ret (_Tp::*_M_f)() const;
};
/// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
template <class _Ret, class _Tp>
class mem_fun_ref_t : public unary_function<_Tp,_Ret> {
public:
explicit mem_fun_ref_t(_Ret (_Tp::*__pf)()) : _M_f(__pf) {}
_Ret operator()(_Tp& __r) const { return (__r.*_M_f)(); }
private:
_Ret (_Tp::*_M_f)();
};
/// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
template <class _Ret, class _Tp>
class const_mem_fun_ref_t : public unary_function<_Tp,_Ret> {
public:
explicit const_mem_fun_ref_t(_Ret (_Tp::*__pf)() const) : _M_f(__pf) {}
_Ret operator()(const _Tp& __r) const { return (__r.*_M_f)(); }
private:
_Ret (_Tp::*_M_f)() const;
};
/// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
template <class _Ret, class _Tp, class _Arg>
class mem_fun1_t : public binary_function<_Tp*,_Arg,_Ret> {
public:
explicit mem_fun1_t(_Ret (_Tp::*__pf)(_Arg)) : _M_f(__pf) {}
_Ret operator()(_Tp* __p, _Arg __x) const { return (__p->*_M_f)(__x); }
private:
_Ret (_Tp::*_M_f)(_Arg);
};
/// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
template <class _Ret, class _Tp, class _Arg>
class const_mem_fun1_t : public binary_function<const _Tp*,_Arg,_Ret> {
public:
explicit const_mem_fun1_t(_Ret (_Tp::*__pf)(_Arg) const) : _M_f(__pf) {}
_Ret operator()(const _Tp* __p, _Arg __x) const
{ return (__p->*_M_f)(__x); }
private:
_Ret (_Tp::*_M_f)(_Arg) const;
};
/// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
template <class _Ret, class _Tp, class _Arg>
class mem_fun1_ref_t : public binary_function<_Tp,_Arg,_Ret> {
public:
explicit mem_fun1_ref_t(_Ret (_Tp::*__pf)(_Arg)) : _M_f(__pf) {}
_Ret operator()(_Tp& __r, _Arg __x) const { return (__r.*_M_f)(__x); }
private:
_Ret (_Tp::*_M_f)(_Arg);
};
/// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
template <class _Ret, class _Tp, class _Arg>
class const_mem_fun1_ref_t : public binary_function<_Tp,_Arg,_Ret> {
public:
explicit const_mem_fun1_ref_t(_Ret (_Tp::*__pf)(_Arg) const) : _M_f(__pf) {}
_Ret operator()(const _Tp& __r, _Arg __x) const { return (__r.*_M_f)(__x); }
private:
_Ret (_Tp::*_M_f)(_Arg) const;
};
/// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
template <class _Tp>
class mem_fun_t<void, _Tp> : public unary_function<_Tp*,void> {
public:
explicit mem_fun_t(void (_Tp::*__pf)()) : _M_f(__pf) {}
void operator()(_Tp* __p) const { (__p->*_M_f)(); }
private:
void (_Tp::*_M_f)();
};
/// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
template <class _Tp>
class const_mem_fun_t<void, _Tp> : public unary_function<const _Tp*,void> {
public:
explicit const_mem_fun_t(void (_Tp::*__pf)() const) : _M_f(__pf) {}
void operator()(const _Tp* __p) const { (__p->*_M_f)(); }
private:
void (_Tp::*_M_f)() const;
};
/// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
template <class _Tp>
class mem_fun_ref_t<void, _Tp> : public unary_function<_Tp,void> {
public:
explicit mem_fun_ref_t(void (_Tp::*__pf)()) : _M_f(__pf) {}
void operator()(_Tp& __r) const { (__r.*_M_f)(); }
private:
void (_Tp::*_M_f)();
};
/// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
template <class _Tp>
class const_mem_fun_ref_t<void, _Tp> : public unary_function<_Tp,void> {
public:
explicit const_mem_fun_ref_t(void (_Tp::*__pf)() const) : _M_f(__pf) {}
void operator()(const _Tp& __r) const { (__r.*_M_f)(); }
private:
void (_Tp::*_M_f)() const;
};
/// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
template <class _Tp, class _Arg>
class mem_fun1_t<void, _Tp, _Arg> : public binary_function<_Tp*,_Arg,void> {
public:
explicit mem_fun1_t(void (_Tp::*__pf)(_Arg)) : _M_f(__pf) {}
void operator()(_Tp* __p, _Arg __x) const { (__p->*_M_f)(__x); }
private:
void (_Tp::*_M_f)(_Arg);
};
/// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
template <class _Tp, class _Arg>
class const_mem_fun1_t<void, _Tp, _Arg>
: public binary_function<const _Tp*,_Arg,void> {
public:
explicit const_mem_fun1_t(void (_Tp::*__pf)(_Arg) const) : _M_f(__pf) {}
void operator()(const _Tp* __p, _Arg __x) const { (__p->*_M_f)(__x); }
private:
void (_Tp::*_M_f)(_Arg) const;
};
/// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
template <class _Tp, class _Arg>
class mem_fun1_ref_t<void, _Tp, _Arg>
: public binary_function<_Tp,_Arg,void> {
public:
explicit mem_fun1_ref_t(void (_Tp::*__pf)(_Arg)) : _M_f(__pf) {}
void operator()(_Tp& __r, _Arg __x) const { (__r.*_M_f)(__x); }
private:
void (_Tp::*_M_f)(_Arg);
};
/// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
template <class _Tp, class _Arg>
class const_mem_fun1_ref_t<void, _Tp, _Arg>
: public binary_function<_Tp,_Arg,void> {
public:
explicit const_mem_fun1_ref_t(void (_Tp::*__pf)(_Arg) const) : _M_f(__pf) {}
void operator()(const _Tp& __r, _Arg __x) const { (__r.*_M_f)(__x); }
private:
void (_Tp::*_M_f)(_Arg) const;
};
// Mem_fun adaptor helper functions. There are only two:
// mem_fun and mem_fun_ref.
template <class _Ret, class _Tp>
inline mem_fun_t<_Ret,_Tp> mem_fun(_Ret (_Tp::*__f)())
{ return mem_fun_t<_Ret,_Tp>(__f); }
template <class _Ret, class _Tp>
inline const_mem_fun_t<_Ret,_Tp> mem_fun(_Ret (_Tp::*__f)() const)
{ return const_mem_fun_t<_Ret,_Tp>(__f); }
template <class _Ret, class _Tp>
inline mem_fun_ref_t<_Ret,_Tp> mem_fun_ref(_Ret (_Tp::*__f)())
{ return mem_fun_ref_t<_Ret,_Tp>(__f); }
template <class _Ret, class _Tp>
inline const_mem_fun_ref_t<_Ret,_Tp> mem_fun_ref(_Ret (_Tp::*__f)() const)
{ return const_mem_fun_ref_t<_Ret,_Tp>(__f); }
template <class _Ret, class _Tp, class _Arg>
inline mem_fun1_t<_Ret,_Tp,_Arg> mem_fun(_Ret (_Tp::*__f)(_Arg))
{ return mem_fun1_t<_Ret,_Tp,_Arg>(__f); }
template <class _Ret, class _Tp, class _Arg>
inline const_mem_fun1_t<_Ret,_Tp,_Arg> mem_fun(_Ret (_Tp::*__f)(_Arg) const)
{ return const_mem_fun1_t<_Ret,_Tp,_Arg>(__f); }
template <class _Ret, class _Tp, class _Arg>
inline mem_fun1_ref_t<_Ret,_Tp,_Arg> mem_fun_ref(_Ret (_Tp::*__f)(_Arg))
{ return mem_fun1_ref_t<_Ret,_Tp,_Arg>(__f); }
template <class _Ret, class _Tp, class _Arg>
inline const_mem_fun1_ref_t<_Ret,_Tp,_Arg>
mem_fun_ref(_Ret (_Tp::*__f)(_Arg) const)
{ return const_mem_fun1_ref_t<_Ret,_Tp,_Arg>(__f); }
/** @} */
_Result
operator()(_Arg1 __x, _Arg2 __y) const
{ return _M_ptr(__x, __y); }
};
/// One of the @link s20_3_7_adaptors adaptors for function pointers@endlink.
template <class _Arg1, class _Arg2, class _Result>
inline pointer_to_binary_function<_Arg1, _Arg2, _Result>
ptr_fun(_Result (*__x)(_Arg1, _Arg2))
{ return pointer_to_binary_function<_Arg1, _Arg2, _Result>(__x); }
/** @} */
template <class _Tp>
struct _Identity : public unary_function<_Tp,_Tp>
{
_Tp&
operator()(_Tp& __x) const
{ return __x; }
const _Tp&
operator()(const _Tp& __x) const
{ return __x; }
};
template <class _Pair>
struct _Select1st : public unary_function<_Pair,
typename _Pair::first_type>
{
typename _Pair::first_type&
operator()(_Pair& __x) const
{ return __x.first; }
const typename _Pair::first_type&
operator()(const _Pair& __x) const
{ return __x.first; }
};
template <class _Pair>
struct _Select2nd : public unary_function<_Pair,
typename _Pair::second_type>
{
typename _Pair::second_type&
operator()(_Pair& __x) const
{ return __x.second; }
const typename _Pair::second_type&
operator()(const _Pair& __x) const
{ return __x.second; }
};
// 20.3.8 adaptors pointers members
/** @defgroup s20_3_8_memadaptors Adaptors for pointers to members
* There are a total of 16 = 2^4 function objects in this family.
* (1) Member functions taking no arguments vs member functions taking
* one argument.
* (2) Call through pointer vs call through reference.
* (3) Member function with void return type vs member function with
* non-void return type.
* (4) Const vs non-const member function.
*
* Note that choice (3) is nothing more than a workaround: according
* to the draft, compilers should handle void and non-void the same way.
* This feature is not yet widely implemented, though. You can only use
* member functions returning void if your compiler supports partial
* specialization.
*
* All of this complexity is in the function objects themselves. You can
* ignore it by using the helper function mem_fun and mem_fun_ref,
* which create whichever type of adaptor is appropriate.
*
* @{
*/
/// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
template <class _Ret, class _Tp>
class mem_fun_t : public unary_function<_Tp*, _Ret>
{
public:
explicit mem_fun_t(_Ret (_Tp::*__pf)())
: _M_f(__pf) {}
_Ret
operator()(_Tp* __p) const
{ return (__p->*_M_f)(); }
private:
_Ret (_Tp::*_M_f)();
};
/// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
template <class _Ret, class _Tp>
class const_mem_fun_t : public unary_function<const _Tp*, _Ret>
{
public:
explicit const_mem_fun_t(_Ret (_Tp::*__pf)() const)
: _M_f(__pf) {}
_Ret
operator()(const _Tp* __p) const
{ return (__p->*_M_f)(); }
private:
_Ret (_Tp::*_M_f)() const;
};
/// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
template <class _Ret, class _Tp>
class mem_fun_ref_t : public unary_function<_Tp, _Ret>
{
public:
explicit mem_fun_ref_t(_Ret (_Tp::*__pf)())
: _M_f(__pf) {}
_Ret
operator()(_Tp& __r) const
{ return (__r.*_M_f)(); }
private:
_Ret (_Tp::*_M_f)();
};
/// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
template <class _Ret, class _Tp>
class const_mem_fun_ref_t : public unary_function<_Tp, _Ret>
{
public:
explicit const_mem_fun_ref_t(_Ret (_Tp::*__pf)() const)
: _M_f(__pf) {}
_Ret
operator()(const _Tp& __r) const
{ return (__r.*_M_f)(); }
private:
_Ret (_Tp::*_M_f)() const;
};
/// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
template <class _Ret, class _Tp, class _Arg>
class mem_fun1_t : public binary_function<_Tp*, _Arg, _Ret>
{
public:
explicit mem_fun1_t(_Ret (_Tp::*__pf)(_Arg))
: _M_f(__pf) {}
_Ret
operator()(_Tp* __p, _Arg __x) const
{ return (__p->*_M_f)(__x); }
private:
_Ret (_Tp::*_M_f)(_Arg);
};
/// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
template <class _Ret, class _Tp, class _Arg>
class const_mem_fun1_t : public binary_function<const _Tp*, _Arg, _Ret>
{
public:
explicit const_mem_fun1_t(_Ret (_Tp::*__pf)(_Arg) const)
: _M_f(__pf) {}
_Ret
operator()(const _Tp* __p, _Arg __x) const
{ return (__p->*_M_f)(__x); }
private:
_Ret (_Tp::*_M_f)(_Arg) const;
};
/// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
template <class _Ret, class _Tp, class _Arg>
class mem_fun1_ref_t : public binary_function<_Tp, _Arg, _Ret>
{
public:
explicit mem_fun1_ref_t(_Ret (_Tp::*__pf)(_Arg))
: _M_f(__pf) {}
_Ret
operator()(_Tp& __r, _Arg __x) const
{ return (__r.*_M_f)(__x); }
private:
_Ret (_Tp::*_M_f)(_Arg);
};
/// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
template <class _Ret, class _Tp, class _Arg>
class const_mem_fun1_ref_t : public binary_function<_Tp, _Arg, _Ret>
{
public:
explicit const_mem_fun1_ref_t(_Ret (_Tp::*__pf)(_Arg) const)
: _M_f(__pf) {}
_Ret
operator()(const _Tp& __r, _Arg __x) const
{ return (__r.*_M_f)(__x); }
private:
_Ret (_Tp::*_M_f)(_Arg) const;
};
/// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
template <class _Tp>
class mem_fun_t<void, _Tp> : public unary_function<_Tp*, void>
{
public:
explicit mem_fun_t(void (_Tp::*__pf)())
: _M_f(__pf) {}
void
operator()(_Tp* __p) const
{ (__p->*_M_f)(); }
private:
void (_Tp::*_M_f)();
};
/// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
template <class _Tp>
class const_mem_fun_t<void, _Tp> : public unary_function<const _Tp*, void>
{
public:
explicit const_mem_fun_t(void (_Tp::*__pf)() const)
: _M_f(__pf) {}
void
operator()(const _Tp* __p) const
{ (__p->*_M_f)(); }
private:
void (_Tp::*_M_f)() const;
};
/// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
template <class _Tp>
class mem_fun_ref_t<void, _Tp> : public unary_function<_Tp, void>
{
public:
explicit mem_fun_ref_t(void (_Tp::*__pf)())
: _M_f(__pf) {}
void
operator()(_Tp& __r) const
{ (__r.*_M_f)(); }
private:
void (_Tp::*_M_f)();
};
/// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
template <class _Tp>
class const_mem_fun_ref_t<void, _Tp> : public unary_function<_Tp, void>
{
public:
explicit const_mem_fun_ref_t(void (_Tp::*__pf)() const)
: _M_f(__pf) {}
void
operator()(const _Tp& __r)
const { (__r.*_M_f)(); }
private:
void (_Tp::*_M_f)() const;
};
/// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
template <class _Tp, class _Arg>
class mem_fun1_t<void, _Tp, _Arg> : public binary_function<_Tp*, _Arg, void>
{
public:
explicit mem_fun1_t(void (_Tp::*__pf)(_Arg))
: _M_f(__pf) {}
void
operator()(_Tp* __p, _Arg __x) const
{ (__p->*_M_f)(__x); }
private:
void (_Tp::*_M_f)(_Arg);
};
/// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
template <class _Tp, class _Arg>
class const_mem_fun1_t<void, _Tp, _Arg>
: public binary_function<const _Tp*, _Arg, void>
{
public:
explicit const_mem_fun1_t(void (_Tp::*__pf)(_Arg) const)
: _M_f(__pf) {}
void
operator()(const _Tp* __p, _Arg __x) const
{ (__p->*_M_f)(__x); }
private:
void (_Tp::*_M_f)(_Arg) const;
};
/// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
template <class _Tp, class _Arg>
class mem_fun1_ref_t<void, _Tp, _Arg>
: public binary_function<_Tp, _Arg, void>
{
public:
explicit mem_fun1_ref_t(void (_Tp::*__pf)(_Arg))
: _M_f(__pf) {}
void
operator()(_Tp& __r, _Arg __x) const
{ (__r.*_M_f)(__x); }
private:
void (_Tp::*_M_f)(_Arg);
};
/// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
template <class _Tp, class _Arg>
class const_mem_fun1_ref_t<void, _Tp, _Arg>
: public binary_function<_Tp, _Arg, void>
{
public:
explicit const_mem_fun1_ref_t(void (_Tp::*__pf)(_Arg) const)
: _M_f(__pf) {}
void
operator()(const _Tp& __r, _Arg __x) const
{ (__r.*_M_f)(__x); }
private:
void (_Tp::*_M_f)(_Arg) const;
};
// Mem_fun adaptor helper functions. There are only two:
// mem_fun and mem_fun_ref.
template <class _Ret, class _Tp>
inline mem_fun_t<_Ret,_Tp>
mem_fun(_Ret (_Tp::*__f)())
{ return mem_fun_t<_Ret,_Tp>(__f); }
template <class _Ret, class _Tp>
inline const_mem_fun_t<_Ret,_Tp>
mem_fun(_Ret (_Tp::*__f)() const)
{ return const_mem_fun_t<_Ret,_Tp>(__f); }
template <class _Ret, class _Tp>
inline mem_fun_ref_t<_Ret,_Tp>
mem_fun_ref(_Ret (_Tp::*__f)())
{ return mem_fun_ref_t<_Ret,_Tp>(__f); }
template <class _Ret, class _Tp>
inline const_mem_fun_ref_t<_Ret,_Tp>
mem_fun_ref(_Ret (_Tp::*__f)() const)
{ return const_mem_fun_ref_t<_Ret,_Tp>(__f); }
template <class _Ret, class _Tp, class _Arg>
inline mem_fun1_t<_Ret,_Tp,_Arg>
mem_fun(_Ret (_Tp::*__f)(_Arg))
{ return mem_fun1_t<_Ret,_Tp,_Arg>(__f); }
template <class _Ret, class _Tp, class _Arg>
inline const_mem_fun1_t<_Ret,_Tp,_Arg>
mem_fun(_Ret (_Tp::*__f)(_Arg) const)
{ return const_mem_fun1_t<_Ret,_Tp,_Arg>(__f); }
template <class _Ret, class _Tp, class _Arg>
inline mem_fun1_ref_t<_Ret,_Tp,_Arg>
mem_fun_ref(_Ret (_Tp::*__f)(_Arg))
{ return mem_fun1_ref_t<_Ret,_Tp,_Arg>(__f); }
template <class _Ret, class _Tp, class _Arg>
inline const_mem_fun1_ref_t<_Ret,_Tp,_Arg>
mem_fun_ref(_Ret (_Tp::*__f)(_Arg) const)
{ return const_mem_fun1_ref_t<_Ret,_Tp,_Arg>(__f); }
/** @} */
} // namespace std } // namespace std
#endif /* _FUNCTION_H */ #endif /* _FUNCTION_H */
......
// Iterators -*- C++ -*- // Iterators -*- C++ -*-
// Copyright (C) 2001, 2002 Free Software Foundation, Inc. // Copyright (C) 2001, 2002, 2004 Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the // software; you can redistribute it and/or modify it under the
...@@ -137,7 +137,8 @@ namespace std ...@@ -137,7 +137,8 @@ namespace std
* @return @c current, the %iterator used for underlying work. * @return @c current, the %iterator used for underlying work.
*/ */
iterator_type iterator_type
base() const { return current; } base() const
{ return current; }
/** /**
* @return TODO * @return TODO
...@@ -157,7 +158,8 @@ namespace std ...@@ -157,7 +158,8 @@ namespace std
* @doctodo * @doctodo
*/ */
pointer pointer
operator->() const { return &(operator*()); } operator->() const
{ return &(operator*()); }
/** /**
* @return TODO * @return TODO
...@@ -256,7 +258,8 @@ namespace std ...@@ -256,7 +258,8 @@ namespace std
* @doctodo * @doctodo
*/ */
reference reference
operator[](difference_type __n) const { return *(*this + __n); } operator[](difference_type __n) const
{ return *(*this + __n); }
}; };
//@{ //@{
...@@ -364,15 +367,18 @@ namespace std ...@@ -364,15 +367,18 @@ namespace std
/// Simply returns *this. /// Simply returns *this.
back_insert_iterator& back_insert_iterator&
operator*() { return *this; } operator*()
{ return *this; }
/// Simply returns *this. (This %iterator does not "move".) /// Simply returns *this. (This %iterator does not "move".)
back_insert_iterator& back_insert_iterator&
operator++() { return *this; } operator++()
{ return *this; }
/// Simply returns *this. (This %iterator does not "move".) /// Simply returns *this. (This %iterator does not "move".)
back_insert_iterator back_insert_iterator
operator++(int) { return *this; } operator++(int)
{ return *this; }
}; };
/** /**
...@@ -435,15 +441,18 @@ namespace std ...@@ -435,15 +441,18 @@ namespace std
/// Simply returns *this. /// Simply returns *this.
front_insert_iterator& front_insert_iterator&
operator*() { return *this; } operator*()
{ return *this; }
/// Simply returns *this. (This %iterator does not "move".) /// Simply returns *this. (This %iterator does not "move".)
front_insert_iterator& front_insert_iterator&
operator++() { return *this; } operator++()
{ return *this; }
/// Simply returns *this. (This %iterator does not "move".) /// Simply returns *this. (This %iterator does not "move".)
front_insert_iterator front_insert_iterator
operator++(int) { return *this; } operator++(int)
{ return *this; }
}; };
/** /**
...@@ -528,15 +537,18 @@ namespace std ...@@ -528,15 +537,18 @@ namespace std
/// Simply returns *this. /// Simply returns *this.
insert_iterator& insert_iterator&
operator*() { return *this; } operator*()
{ return *this; }
/// Simply returns *this. (This %iterator does not "move".) /// Simply returns *this. (This %iterator does not "move".)
insert_iterator& insert_iterator&
operator++() { return *this; } operator++()
{ return *this; }
/// Simply returns *this. (This %iterator does not "move".) /// Simply returns *this. (This %iterator does not "move".)
insert_iterator& insert_iterator&
operator++(int) { return *this; } operator++(int)
{ return *this; }
}; };
/** /**
...@@ -578,12 +590,12 @@ namespace __gnu_cxx ...@@ -578,12 +590,12 @@ namespace __gnu_cxx
public: public:
typedef typename iterator_traits<_Iterator>::iterator_category typedef typename iterator_traits<_Iterator>::iterator_category
iterator_category; iterator_category;
typedef typename iterator_traits<_Iterator>::value_type value_type; typedef typename iterator_traits<_Iterator>::value_type value_type;
typedef typename iterator_traits<_Iterator>::difference_type typedef typename iterator_traits<_Iterator>::difference_type
difference_type; difference_type;
typedef typename iterator_traits<_Iterator>::reference reference; typedef typename iterator_traits<_Iterator>::reference reference;
typedef typename iterator_traits<_Iterator>::pointer pointer; typedef typename iterator_traits<_Iterator>::pointer pointer;
__normal_iterator() : _M_current(_Iterator()) { } __normal_iterator() : _M_current(_Iterator()) { }
...@@ -592,28 +604,41 @@ namespace __gnu_cxx ...@@ -592,28 +604,41 @@ namespace __gnu_cxx
// Allow iterator to const_iterator conversion // Allow iterator to const_iterator conversion
template<typename _Iter> template<typename _Iter>
inline __normal_iterator(const __normal_iterator<_Iter, _Container>& __i) inline __normal_iterator(const __normal_iterator<_Iter,
_Container>& __i)
: _M_current(__i.base()) { } : _M_current(__i.base()) { }
// Forward iterator requirements // Forward iterator requirements
reference reference
operator*() const { return *_M_current; } operator*() const
{ return *_M_current; }
pointer pointer
operator->() const { return _M_current; } operator->() const
{ return _M_current; }
__normal_iterator& __normal_iterator&
operator++() { ++_M_current; return *this; } operator++()
{
++_M_current;
return *this;
}
__normal_iterator __normal_iterator
operator++(int) { return __normal_iterator(_M_current++); } operator++(int)
{ return __normal_iterator(_M_current++); }
// Bidirectional iterator requirements // Bidirectional iterator requirements
__normal_iterator& __normal_iterator&
operator--() { --_M_current; return *this; } operator--()
{
--_M_current;
return *this;
}
__normal_iterator __normal_iterator
operator--(int) { return __normal_iterator(_M_current--); } operator--(int)
{ return __normal_iterator(_M_current--); }
// Random access iterator requirements // Random access iterator requirements
reference reference
...@@ -637,7 +662,8 @@ namespace __gnu_cxx ...@@ -637,7 +662,8 @@ namespace __gnu_cxx
{ return __normal_iterator(_M_current - __n); } { return __normal_iterator(_M_current - __n); }
const _Iterator& const _Iterator&
base() const { return _M_current; } base() const
{ return _M_current; }
}; };
// Note: In what follows, the left- and right-hand-side iterators are // Note: In what follows, the left- and right-hand-side iterators are
...@@ -650,93 +676,93 @@ namespace __gnu_cxx ...@@ -650,93 +676,93 @@ namespace __gnu_cxx
// Forward iterator requirements // Forward iterator requirements
template<typename _IteratorL, typename _IteratorR, typename _Container> template<typename _IteratorL, typename _IteratorR, typename _Container>
inline bool inline bool
operator==(const __normal_iterator<_IteratorL, _Container>& __lhs, operator==(const __normal_iterator<_IteratorL, _Container>& __lhs,
const __normal_iterator<_IteratorR, _Container>& __rhs) const __normal_iterator<_IteratorR, _Container>& __rhs)
{ return __lhs.base() == __rhs.base(); } { return __lhs.base() == __rhs.base(); }
template<typename _Iterator, typename _Container> template<typename _Iterator, typename _Container>
inline bool inline bool
operator==(const __normal_iterator<_Iterator, _Container>& __lhs, operator==(const __normal_iterator<_Iterator, _Container>& __lhs,
const __normal_iterator<_Iterator, _Container>& __rhs) const __normal_iterator<_Iterator, _Container>& __rhs)
{ return __lhs.base() == __rhs.base(); } { return __lhs.base() == __rhs.base(); }
template<typename _IteratorL, typename _IteratorR, typename _Container> template<typename _IteratorL, typename _IteratorR, typename _Container>
inline bool inline bool
operator!=(const __normal_iterator<_IteratorL, _Container>& __lhs, operator!=(const __normal_iterator<_IteratorL, _Container>& __lhs,
const __normal_iterator<_IteratorR, _Container>& __rhs) const __normal_iterator<_IteratorR, _Container>& __rhs)
{ return __lhs.base() != __rhs.base(); } { return __lhs.base() != __rhs.base(); }
template<typename _Iterator, typename _Container> template<typename _Iterator, typename _Container>
inline bool inline bool
operator!=(const __normal_iterator<_Iterator, _Container>& __lhs, operator!=(const __normal_iterator<_Iterator, _Container>& __lhs,
const __normal_iterator<_Iterator, _Container>& __rhs) const __normal_iterator<_Iterator, _Container>& __rhs)
{ return __lhs.base() != __rhs.base(); } { return __lhs.base() != __rhs.base(); }
// Random access iterator requirements // Random access iterator requirements
template<typename _IteratorL, typename _IteratorR, typename _Container> template<typename _IteratorL, typename _IteratorR, typename _Container>
inline bool inline bool
operator<(const __normal_iterator<_IteratorL, _Container>& __lhs, operator<(const __normal_iterator<_IteratorL, _Container>& __lhs,
const __normal_iterator<_IteratorR, _Container>& __rhs) const __normal_iterator<_IteratorR, _Container>& __rhs)
{ return __lhs.base() < __rhs.base(); } { return __lhs.base() < __rhs.base(); }
template<typename _Iterator, typename _Container> template<typename _Iterator, typename _Container>
inline bool inline bool
operator<(const __normal_iterator<_Iterator, _Container>& __lhs, operator<(const __normal_iterator<_Iterator, _Container>& __lhs,
const __normal_iterator<_Iterator, _Container>& __rhs) const __normal_iterator<_Iterator, _Container>& __rhs)
{ return __lhs.base() < __rhs.base(); } { return __lhs.base() < __rhs.base(); }
template<typename _IteratorL, typename _IteratorR, typename _Container> template<typename _IteratorL, typename _IteratorR, typename _Container>
inline bool inline bool
operator>(const __normal_iterator<_IteratorL, _Container>& __lhs, operator>(const __normal_iterator<_IteratorL, _Container>& __lhs,
const __normal_iterator<_IteratorR, _Container>& __rhs) const __normal_iterator<_IteratorR, _Container>& __rhs)
{ return __lhs.base() > __rhs.base(); } { return __lhs.base() > __rhs.base(); }
template<typename _Iterator, typename _Container> template<typename _Iterator, typename _Container>
inline bool inline bool
operator>(const __normal_iterator<_Iterator, _Container>& __lhs, operator>(const __normal_iterator<_Iterator, _Container>& __lhs,
const __normal_iterator<_Iterator, _Container>& __rhs) const __normal_iterator<_Iterator, _Container>& __rhs)
{ return __lhs.base() > __rhs.base(); } { return __lhs.base() > __rhs.base(); }
template<typename _IteratorL, typename _IteratorR, typename _Container> template<typename _IteratorL, typename _IteratorR, typename _Container>
inline bool inline bool
operator<=(const __normal_iterator<_IteratorL, _Container>& __lhs, operator<=(const __normal_iterator<_IteratorL, _Container>& __lhs,
const __normal_iterator<_IteratorR, _Container>& __rhs) const __normal_iterator<_IteratorR, _Container>& __rhs)
{ return __lhs.base() <= __rhs.base(); } { return __lhs.base() <= __rhs.base(); }
template<typename _Iterator, typename _Container> template<typename _Iterator, typename _Container>
inline bool inline bool
operator<=(const __normal_iterator<_Iterator, _Container>& __lhs, operator<=(const __normal_iterator<_Iterator, _Container>& __lhs,
const __normal_iterator<_Iterator, _Container>& __rhs) const __normal_iterator<_Iterator, _Container>& __rhs)
{ return __lhs.base() <= __rhs.base(); } { return __lhs.base() <= __rhs.base(); }
template<typename _IteratorL, typename _IteratorR, typename _Container> template<typename _IteratorL, typename _IteratorR, typename _Container>
inline bool inline bool
operator>=(const __normal_iterator<_IteratorL, _Container>& __lhs, operator>=(const __normal_iterator<_IteratorL, _Container>& __lhs,
const __normal_iterator<_IteratorR, _Container>& __rhs) const __normal_iterator<_IteratorR, _Container>& __rhs)
{ return __lhs.base() >= __rhs.base(); } { return __lhs.base() >= __rhs.base(); }
template<typename _Iterator, typename _Container> template<typename _Iterator, typename _Container>
inline bool inline bool
operator>=(const __normal_iterator<_Iterator, _Container>& __lhs, operator>=(const __normal_iterator<_Iterator, _Container>& __lhs,
const __normal_iterator<_Iterator, _Container>& __rhs) const __normal_iterator<_Iterator, _Container>& __rhs)
{ return __lhs.base() >= __rhs.base(); } { return __lhs.base() >= __rhs.base(); }
// _GLIBCXX_RESOLVE_LIB_DEFECTS // _GLIBCXX_RESOLVE_LIB_DEFECTS
// According to the resolution of DR179 not only the various comparison // According to the resolution of DR179 not only the various comparison
// operators but also operator- must accept mixed iterator/const_iterator // operators but also operator- must accept mixed iterator/const_iterator
// parameters. // parameters.
template<typename _IteratorL, typename _IteratorR, typename _Container> template<typename _IteratorL, typename _IteratorR, typename _Container>
inline typename __normal_iterator<_IteratorL, _Container>::difference_type inline typename __normal_iterator<_IteratorL, _Container>::difference_type
operator-(const __normal_iterator<_IteratorL, _Container>& __lhs, operator-(const __normal_iterator<_IteratorL, _Container>& __lhs,
const __normal_iterator<_IteratorR, _Container>& __rhs) const __normal_iterator<_IteratorR, _Container>& __rhs)
{ return __lhs.base() - __rhs.base(); } { return __lhs.base() - __rhs.base(); }
template<typename _Iterator, typename _Container> template<typename _Iterator, typename _Container>
inline __normal_iterator<_Iterator, _Container> inline __normal_iterator<_Iterator, _Container>
operator+(typename __normal_iterator<_Iterator, _Container>::difference_type __n, operator+(typename __normal_iterator<_Iterator, _Container>::difference_type
const __normal_iterator<_Iterator, _Container>& __i) __n, const __normal_iterator<_Iterator, _Container>& __i)
{ return __normal_iterator<_Iterator, _Container>(__i.base() + __n); } { return __normal_iterator<_Iterator, _Container>(__i.base() + __n); }
} // namespace __gnu_cxx } // namespace __gnu_cxx
#endif #endif
......
// Functions used by iterators -*- C++ -*- // Functions used by iterators -*- C++ -*-
// Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. // Copyright (C) 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the // software; you can redistribute it and/or modify it under the
...@@ -78,9 +78,11 @@ namespace std ...@@ -78,9 +78,11 @@ namespace std
__glibcxx_function_requires(_InputIteratorConcept<_InputIterator>) __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
typename iterator_traits<_InputIterator>::difference_type __n = 0; typename iterator_traits<_InputIterator>::difference_type __n = 0;
while (__first != __last) { while (__first != __last)
++__first; ++__n; {
} ++__first;
++__n;
}
return __n; return __n;
} }
...@@ -90,7 +92,8 @@ namespace std ...@@ -90,7 +92,8 @@ namespace std
random_access_iterator_tag) random_access_iterator_tag)
{ {
// concept requirements // concept requirements
__glibcxx_function_requires(_RandomAccessIteratorConcept<_RandomAccessIterator>) __glibcxx_function_requires(_RandomAccessIteratorConcept<
_RandomAccessIterator>)
return __last - __first; return __last - __first;
} }
...@@ -111,7 +114,8 @@ namespace std ...@@ -111,7 +114,8 @@ namespace std
distance(_InputIterator __first, _InputIterator __last) distance(_InputIterator __first, _InputIterator __last)
{ {
// concept requirements -- taken care of in __distance // concept requirements -- taken care of in __distance
return std::__distance(__first, __last, std::__iterator_category(__first)); return std::__distance(__first, __last,
std::__iterator_category(__first));
} }
template<typename _InputIterator, typename _Distance> template<typename _InputIterator, typename _Distance>
...@@ -120,7 +124,8 @@ namespace std ...@@ -120,7 +124,8 @@ namespace std
{ {
// concept requirements // concept requirements
__glibcxx_function_requires(_InputIteratorConcept<_InputIterator>) __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
while (__n--) ++__i; while (__n--)
++__i;
} }
template<typename _BidirectionalIterator, typename _Distance> template<typename _BidirectionalIterator, typename _Distance>
...@@ -129,8 +134,8 @@ namespace std ...@@ -129,8 +134,8 @@ namespace std
bidirectional_iterator_tag) bidirectional_iterator_tag)
{ {
// concept requirements // concept requirements
__glibcxx_function_requires(_BidirectionalIteratorConcept<_BidirectionalIterator>) __glibcxx_function_requires(_BidirectionalIteratorConcept<
_BidirectionalIterator>)
if (__n > 0) if (__n > 0)
while (__n--) ++__i; while (__n--) ++__i;
else else
...@@ -143,7 +148,8 @@ namespace std ...@@ -143,7 +148,8 @@ namespace std
random_access_iterator_tag) random_access_iterator_tag)
{ {
// concept requirements // concept requirements
__glibcxx_function_requires(_RandomAccessIteratorConcept<_RandomAccessIterator>) __glibcxx_function_requires(_RandomAccessIteratorConcept<
_RandomAccessIterator>)
__i += __n; __i += __n;
} }
......
// Types used in iterator implementation -*- C++ -*- // Types used in iterator implementation -*- C++ -*-
// Copyright (C) 2001, 2002 Free Software Foundation, Inc. // Copyright (C) 2001, 2002, 2004 Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the // software; you can redistribute it and/or modify it under the
...@@ -82,9 +82,11 @@ namespace std ...@@ -82,9 +82,11 @@ namespace std
struct output_iterator_tag {}; struct output_iterator_tag {};
/// Forward iterators support a superset of input iterator operations. /// Forward iterators support a superset of input iterator operations.
struct forward_iterator_tag : public input_iterator_tag {}; struct forward_iterator_tag : public input_iterator_tag {};
/// Bidirectional iterators support a superset of forward iterator operations. /// Bidirectional iterators support a superset of forward iterator
/// operations.
struct bidirectional_iterator_tag : public forward_iterator_tag {}; struct bidirectional_iterator_tag : public forward_iterator_tag {};
/// Random-access iterators support a superset of bidirectional iterator operations. /// Random-access iterators support a superset of bidirectional iterator
/// operations.
struct random_access_iterator_tag : public bidirectional_iterator_tag {}; struct random_access_iterator_tag : public bidirectional_iterator_tag {};
//@} //@}
......
...@@ -94,7 +94,6 @@ namespace __gnu_norm ...@@ -94,7 +94,6 @@ namespace __gnu_norm
_Tp _M_data; ///< User's data. _Tp _M_data; ///< User's data.
}; };
/** /**
* @brief A list::iterator. * @brief A list::iterator.
* *
...@@ -325,7 +324,6 @@ namespace __gnu_norm ...@@ -325,7 +324,6 @@ namespace __gnu_norm
} }
}; };
/** /**
* @brief A standard container with linear time access to elements, * @brief A standard container with linear time access to elements,
* and fixed time insertion/deletion at any point in the sequence. * and fixed time insertion/deletion at any point in the sequence.
...@@ -573,7 +571,8 @@ namespace __gnu_norm ...@@ -573,7 +571,8 @@ namespace __gnu_norm
/// Get a copy of the memory allocation object. /// Get a copy of the memory allocation object.
allocator_type allocator_type
get_allocator() const { return _Base::get_allocator(); } get_allocator() const
{ return _Base::get_allocator(); }
// iterators // iterators
/** /**
...@@ -581,7 +580,8 @@ namespace __gnu_norm ...@@ -581,7 +580,8 @@ namespace __gnu_norm
* %list. Iteration is done in ordinary element order. * %list. Iteration is done in ordinary element order.
*/ */
iterator iterator
begin() { return this->_M_node._M_next; } begin()
{ return this->_M_node._M_next; }
/** /**
* Returns a read-only (constant) iterator that points to the * Returns a read-only (constant) iterator that points to the
...@@ -589,7 +589,8 @@ namespace __gnu_norm ...@@ -589,7 +589,8 @@ namespace __gnu_norm
* element order. * element order.
*/ */
const_iterator const_iterator
begin() const { return this->_M_node._M_next; } begin() const
{ return this->_M_node._M_next; }
/** /**
* Returns a read/write iterator that points one past the last * Returns a read/write iterator that points one past the last
...@@ -605,7 +606,8 @@ namespace __gnu_norm ...@@ -605,7 +606,8 @@ namespace __gnu_norm
* element order. * element order.
*/ */
const_iterator const_iterator
end() const { return &this->_M_node; } end() const
{ return &this->_M_node; }
/** /**
* Returns a read/write reverse iterator that points to the last * Returns a read/write reverse iterator that points to the last
...@@ -613,7 +615,8 @@ namespace __gnu_norm ...@@ -613,7 +615,8 @@ namespace __gnu_norm
* order. * order.
*/ */
reverse_iterator reverse_iterator
rbegin() { return reverse_iterator(end()); } rbegin()
{ return reverse_iterator(end()); }
/** /**
* Returns a read-only (constant) reverse iterator that points to * Returns a read-only (constant) reverse iterator that points to
...@@ -621,7 +624,8 @@ namespace __gnu_norm ...@@ -621,7 +624,8 @@ namespace __gnu_norm
* element order. * element order.
*/ */
const_reverse_iterator const_reverse_iterator
rbegin() const { return const_reverse_iterator(end()); } rbegin() const
{ return const_reverse_iterator(end()); }
/** /**
* Returns a read/write reverse iterator that points to one * Returns a read/write reverse iterator that points to one
...@@ -629,7 +633,8 @@ namespace __gnu_norm ...@@ -629,7 +633,8 @@ namespace __gnu_norm
* reverse element order. * reverse element order.
*/ */
reverse_iterator reverse_iterator
rend() { return reverse_iterator(begin()); } rend()
{ return reverse_iterator(begin()); }
/** /**
* Returns a read-only (constant) reverse iterator that points to one * Returns a read-only (constant) reverse iterator that points to one
...@@ -646,15 +651,18 @@ namespace __gnu_norm ...@@ -646,15 +651,18 @@ namespace __gnu_norm
* end().) * end().)
*/ */
bool bool
empty() const { return this->_M_node._M_next == &this->_M_node; } empty() const
{ return this->_M_node._M_next == &this->_M_node; }
/** Returns the number of elements in the %list. */ /** Returns the number of elements in the %list. */
size_type size_type
size() const { return std::distance(begin(), end()); } size() const
{ return std::distance(begin(), end()); }
/** Returns the size() of the largest possible %list. */ /** Returns the size() of the largest possible %list. */
size_type size_type
max_size() const { return size_type(-1); } max_size() const
{ return size_type(-1); }
/** /**
* @brief Resizes the %list to the specified number of elements. * @brief Resizes the %list to the specified number of elements.
...@@ -679,7 +687,8 @@ namespace __gnu_norm ...@@ -679,7 +687,8 @@ namespace __gnu_norm
* and new elements are default-constructed. * and new elements are default-constructed.
*/ */
void void
resize(size_type __new_size) { this->resize(__new_size, value_type()); } resize(size_type __new_size)
{ this->resize(__new_size, value_type()); }
// element access // element access
/** /**
...@@ -687,28 +696,32 @@ namespace __gnu_norm ...@@ -687,28 +696,32 @@ namespace __gnu_norm
* element of the %list. * element of the %list.
*/ */
reference reference
front() { return *begin(); } front()
{ return *begin(); }
/** /**
* Returns a read-only (constant) reference to the data at the first * Returns a read-only (constant) reference to the data at the first
* element of the %list. * element of the %list.
*/ */
const_reference const_reference
front() const { return *begin(); } front() const
{ return *begin(); }
/** /**
* Returns a read/write reference to the data at the last element * Returns a read/write reference to the data at the last element
* of the %list. * of the %list.
*/ */
reference reference
back() { return *(--end()); } back()
{ return *(--end()); }
/** /**
* Returns a read-only (constant) reference to the data at the last * Returns a read-only (constant) reference to the data at the last
* element of the %list. * element of the %list.
*/ */
const_reference const_reference
back() const { return *(--end()); } back() const
{ return *(--end()); }
// [23.2.2.3] modifiers // [23.2.2.3] modifiers
/** /**
...@@ -722,7 +735,8 @@ namespace __gnu_norm ...@@ -722,7 +735,8 @@ namespace __gnu_norm
* references. * references.
*/ */
void void
push_front(const value_type& __x) { this->_M_insert(begin(), __x); } push_front(const value_type& __x)
{ this->_M_insert(begin(), __x); }
/** /**
* @brief Removes first element. * @brief Removes first element.
...@@ -737,7 +751,8 @@ namespace __gnu_norm ...@@ -737,7 +751,8 @@ namespace __gnu_norm
* called. * called.
*/ */
void void
pop_front() { this->_M_erase(begin()); } pop_front()
{ this->_M_erase(begin()); }
/** /**
* @brief Add data to the end of the %list. * @brief Add data to the end of the %list.
...@@ -750,7 +765,8 @@ namespace __gnu_norm ...@@ -750,7 +765,8 @@ namespace __gnu_norm
* references. * references.
*/ */
void void
push_back(const value_type& __x) { this->_M_insert(end(), __x); } push_back(const value_type& __x)
{ this->_M_insert(end(), __x); }
/** /**
* @brief Removes last element. * @brief Removes last element.
...@@ -764,7 +780,8 @@ namespace __gnu_norm ...@@ -764,7 +780,8 @@ namespace __gnu_norm
* is needed, it should be retrieved before pop_back() is called. * is needed, it should be retrieved before pop_back() is called.
*/ */
void void
pop_back() { this->_M_erase(this->_M_node._M_prev); } pop_back()
{ this->_M_erase(this->_M_node._M_prev); }
/** /**
* @brief Inserts given value into %list before specified iterator. * @brief Inserts given value into %list before specified iterator.
...@@ -876,7 +893,8 @@ namespace __gnu_norm ...@@ -876,7 +893,8 @@ namespace __gnu_norm
* function. * function.
*/ */
void void
swap(list& __x) { _List_node_base::swap(this->_M_node,__x._M_node); } swap(list& __x)
{ _List_node_base::swap(this->_M_node,__x._M_node); }
/** /**
* Erases all the elements. Note that this function only erases * Erases all the elements. Note that this function only erases
...@@ -922,7 +940,8 @@ namespace __gnu_norm ...@@ -922,7 +940,8 @@ namespace __gnu_norm
{ {
iterator __j = __i; iterator __j = __i;
++__j; ++__j;
if (__position == __i || __position == __j) return; if (__position == __i || __position == __j)
return;
this->_M_transfer(__position, __i, __j); this->_M_transfer(__position, __i, __j);
} }
...@@ -1037,7 +1056,8 @@ namespace __gnu_norm ...@@ -1037,7 +1056,8 @@ namespace __gnu_norm
* Reverse the order of elements in the list in linear time. * Reverse the order of elements in the list in linear time.
*/ */
void void
reverse() { this->_M_node.reverse(); } reverse()
{ this->_M_node.reverse(); }
/** /**
* @brief Sort the elements. * @brief Sort the elements.
...@@ -1118,16 +1138,13 @@ namespace __gnu_norm ...@@ -1118,16 +1138,13 @@ namespace __gnu_norm
// Moves the elements from [first,last) before position. // Moves the elements from [first,last) before position.
void void
_M_transfer(iterator __position, iterator __first, iterator __last) _M_transfer(iterator __position, iterator __first, iterator __last)
{ { __position._M_node->transfer(__first._M_node,__last._M_node); }
__position._M_node->transfer(__first._M_node,__last._M_node);
}
// Inserts new element at position given and with value given. // Inserts new element at position given and with value given.
void void
_M_insert(iterator __position, const value_type& __x) _M_insert(iterator __position, const value_type& __x)
{ {
_Node* __tmp = _M_create_node(__x); _Node* __tmp = _M_create_node(__x);
__tmp->hook(__position._M_node); __tmp->hook(__position._M_node);
} }
...@@ -1142,7 +1159,6 @@ namespace __gnu_norm ...@@ -1142,7 +1159,6 @@ namespace __gnu_norm
} }
}; };
/** /**
* @brief List equality comparison. * @brief List equality comparison.
* @param x A %list. * @param x A %list.
...@@ -1167,7 +1183,7 @@ namespace __gnu_norm ...@@ -1167,7 +1183,7 @@ namespace __gnu_norm
{ {
++__i1; ++__i1;
++__i2; ++__i2;
} }
return __i1 == __end1 && __i2 == __end2; return __i1 == __end1 && __i2 == __end2;
} }
...@@ -1185,10 +1201,8 @@ namespace __gnu_norm ...@@ -1185,10 +1201,8 @@ namespace __gnu_norm
template<typename _Tp, typename _Alloc> template<typename _Tp, typename _Alloc>
inline bool inline bool
operator<(const list<_Tp,_Alloc>& __x, const list<_Tp,_Alloc>& __y) operator<(const list<_Tp,_Alloc>& __x, const list<_Tp,_Alloc>& __y)
{ { return std::lexicographical_compare(__x.begin(), __x.end(),
return std::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end()); }
__y.begin(), __y.end());
}
/// Based on operator== /// Based on operator==
template<typename _Tp, typename _Alloc> template<typename _Tp, typename _Alloc>
......
// Map implementation -*- C++ -*- // Map implementation -*- C++ -*-
// Copyright (C) 2001, 2002 Free Software Foundation, Inc. // Copyright (C) 2001, 2002, 2004 Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the // software; you can redistribute it and/or modify it under the
...@@ -89,503 +89,536 @@ namespace __gnu_norm ...@@ -89,503 +89,536 @@ namespace __gnu_norm
template <typename _Key, typename _Tp, typename _Compare = less<_Key>, template <typename _Key, typename _Tp, typename _Compare = less<_Key>,
typename _Alloc = allocator<pair<const _Key, _Tp> > > typename _Alloc = allocator<pair<const _Key, _Tp> > >
class map class map
{ {
// concept requirements // concept requirements
__glibcxx_class_requires(_Tp, _SGIAssignableConcept) __glibcxx_class_requires(_Tp, _SGIAssignableConcept)
__glibcxx_class_requires4(_Compare, bool, _Key, _Key, _BinaryFunctionConcept) __glibcxx_class_requires4(_Compare, bool, _Key, _Key,
_BinaryFunctionConcept)
public: public:
typedef _Key key_type; typedef _Key key_type;
typedef _Tp mapped_type; typedef _Tp mapped_type;
typedef pair<const _Key, _Tp> value_type; typedef pair<const _Key, _Tp> value_type;
typedef _Compare key_compare; typedef _Compare key_compare;
class value_compare class value_compare
: public binary_function<value_type, value_type, bool> : public binary_function<value_type, value_type, bool>
{ {
friend class map<_Key,_Tp,_Compare,_Alloc>; friend class map<_Key,_Tp,_Compare,_Alloc>;
protected: protected:
_Compare comp; _Compare comp;
value_compare(_Compare __c) : comp(__c) {}
value_compare(_Compare __c)
: comp(__c) { }
public: public:
bool operator()(const value_type& __x, const value_type& __y) const bool operator()(const value_type& __x, const value_type& __y) const
{ return comp(__x.first, __y.first); } { return comp(__x.first, __y.first); }
}; };
private: private:
/// @if maint This turns a red-black tree into a [multi]map. @endif /// @if maint This turns a red-black tree into a [multi]map. @endif
typedef _Rb_tree<key_type, value_type, typedef _Rb_tree<key_type, value_type,
_Select1st<value_type>, key_compare, _Alloc> _Rep_type; _Select1st<value_type>, key_compare, _Alloc> _Rep_type;
/// @if maint The actual tree structure. @endif /// @if maint The actual tree structure. @endif
_Rep_type _M_t; _Rep_type _M_t;
public: public:
// many of these are specified differently in ISO, but the following are // many of these are specified differently in ISO, but the following are
// "functionally equivalent" // "functionally equivalent"
typedef typename _Rep_type::allocator_type allocator_type; typedef typename _Rep_type::allocator_type allocator_type;
typedef typename _Rep_type::reference reference; typedef typename _Rep_type::reference reference;
typedef typename _Rep_type::const_reference const_reference; typedef typename _Rep_type::const_reference const_reference;
typedef typename _Rep_type::iterator iterator; typedef typename _Rep_type::iterator iterator;
typedef typename _Rep_type::const_iterator const_iterator; typedef typename _Rep_type::const_iterator const_iterator;
typedef typename _Rep_type::size_type size_type; typedef typename _Rep_type::size_type size_type;
typedef typename _Rep_type::difference_type difference_type; typedef typename _Rep_type::difference_type difference_type;
typedef typename _Rep_type::pointer pointer; typedef typename _Rep_type::pointer pointer;
typedef typename _Rep_type::const_pointer const_pointer; typedef typename _Rep_type::const_pointer const_pointer;
typedef typename _Rep_type::reverse_iterator reverse_iterator; typedef typename _Rep_type::reverse_iterator reverse_iterator;
typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator; typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator;
// [23.3.1.1] construct/copy/destroy
// [23.3.1.1] construct/copy/destroy // (get_allocator() is normally listed in this section, but seems to have
// (get_allocator() is normally listed in this section, but seems to have // been accidentally omitted in the printed standard)
// been accidentally omitted in the printed standard) /**
/** * @brief Default constructor creates no elements.
* @brief Default constructor creates no elements. */
*/ map()
map() : _M_t(_Compare(), allocator_type()) { } : _M_t(_Compare(), allocator_type()) { }
// for some reason this was made a separate function // for some reason this was made a separate function
/** /**
* @brief Default constructor creates no elements. * @brief Default constructor creates no elements.
*/ */
explicit explicit
map(const _Compare& __comp, const allocator_type& __a = allocator_type()) map(const _Compare& __comp, const allocator_type& __a = allocator_type())
: _M_t(__comp, __a) { } : _M_t(__comp, __a) { }
/** /**
* @brief Map copy constructor. * @brief Map copy constructor.
* @param x A %map of identical element and allocator types. * @param x A %map of identical element and allocator types.
* *
* The newly-created %map uses a copy of the allocation object used * The newly-created %map uses a copy of the allocation object used
* by @a x. * by @a x.
*/ */
map(const map& __x) map(const map& __x)
: _M_t(__x._M_t) { } : _M_t(__x._M_t) { }
/** /**
* @brief Builds a %map from a range. * @brief Builds a %map from a range.
* @param first An input iterator. * @param first An input iterator.
* @param last An input iterator. * @param last An input iterator.
* *
* Create a %map consisting of copies of the elements from [first,last). * Create a %map consisting of copies of the elements from [first,last).
* This is linear in N if the range is already sorted, and NlogN * This is linear in N if the range is already sorted, and NlogN
* otherwise (where N is distance(first,last)). * otherwise (where N is distance(first,last)).
*/ */
template <typename _InputIterator> template <typename _InputIterator>
map(_InputIterator __first, _InputIterator __last) map(_InputIterator __first, _InputIterator __last)
: _M_t(_Compare(), allocator_type()) : _M_t(_Compare(), allocator_type())
{ _M_t.insert_unique(__first, __last); } { _M_t.insert_unique(__first, __last); }
/** /**
* @brief Builds a %map from a range. * @brief Builds a %map from a range.
* @param first An input iterator. * @param first An input iterator.
* @param last An input iterator. * @param last An input iterator.
* @param comp A comparison functor. * @param comp A comparison functor.
* @param a An allocator object. * @param a An allocator object.
* *
* Create a %map consisting of copies of the elements from [first,last). * Create a %map consisting of copies of the elements from [first,last).
* This is linear in N if the range is already sorted, and NlogN * This is linear in N if the range is already sorted, and NlogN
* otherwise (where N is distance(first,last)). * otherwise (where N is distance(first,last)).
*/ */
template <typename _InputIterator> template <typename _InputIterator>
map(_InputIterator __first, _InputIterator __last, map(_InputIterator __first, _InputIterator __last,
const _Compare& __comp, const allocator_type& __a = allocator_type()) const _Compare& __comp, const allocator_type& __a = allocator_type())
: _M_t(__comp, __a) : _M_t(__comp, __a)
{ _M_t.insert_unique(__first, __last); } { _M_t.insert_unique(__first, __last); }
// FIXME There is no dtor declared, but we should have something generated // FIXME There is no dtor declared, but we should have something generated
// by Doxygen. I don't know what tags to add to this paragraph to make // by Doxygen. I don't know what tags to add to this paragraph to make
// that happen: // that happen:
/** /**
* The dtor only erases the elements, and note that if the elements * The dtor only erases the elements, and note that if the elements
* themselves are pointers, the pointed-to memory is not touched in any * themselves are pointers, the pointed-to memory is not touched in any
* way. Managing the pointer is the user's responsibilty. * way. Managing the pointer is the user's responsibilty.
*/ */
/** /**
* @brief Map assignment operator. * @brief Map assignment operator.
* @param x A %map of identical element and allocator types. * @param x A %map of identical element and allocator types.
* *
* All the elements of @a x are copied, but unlike the copy constructor, * All the elements of @a x are copied, but unlike the copy constructor,
* the allocator object is not copied. * the allocator object is not copied.
*/ */
map& map&
operator=(const map& __x) operator=(const map& __x)
{ {
_M_t = __x._M_t; _M_t = __x._M_t;
return *this; return *this;
} }
/// Get a copy of the memory allocation object. /// Get a copy of the memory allocation object.
allocator_type allocator_type
get_allocator() const { return _M_t.get_allocator(); } get_allocator() const
{ return _M_t.get_allocator(); }
// iterators
/** // iterators
* Returns a read/write iterator that points to the first pair in the %map. /**
* Iteration is done in ascending order according to the keys. * Returns a read/write iterator that points to the first pair in the
*/ * %map.
iterator * Iteration is done in ascending order according to the keys.
begin() { return _M_t.begin(); } */
iterator
/** begin()
* Returns a read-only (constant) iterator that points to the first pair { return _M_t.begin(); }
* in the %map. Iteration is done in ascending order according to the
* keys. /**
*/ * Returns a read-only (constant) iterator that points to the first pair
const_iterator * in the %map. Iteration is done in ascending order according to the
begin() const { return _M_t.begin(); } * keys.
*/
/** const_iterator
* Returns a read/write iterator that points one past the last pair in the begin() const
* %map. Iteration is done in ascending order according to the keys. { return _M_t.begin(); }
*/
iterator /**
end() { return _M_t.end(); } * Returns a read/write iterator that points one past the last pair in
* the %map. Iteration is done in ascending order according to the keys.
/** */
* Returns a read-only (constant) iterator that points one past the last iterator
* pair in the %map. Iteration is done in ascending order according to the end()
* keys. { return _M_t.end(); }
*/
const_iterator /**
end() const { return _M_t.end(); } * Returns a read-only (constant) iterator that points one past the last
* pair in the %map. Iteration is done in ascending order according to
/** * the keys.
* Returns a read/write reverse iterator that points to the last pair in */
* the %map. Iteration is done in descending order according to the keys. const_iterator
*/ end() const
reverse_iterator { return _M_t.end(); }
rbegin() { return _M_t.rbegin(); }
/**
/** * Returns a read/write reverse iterator that points to the last pair in
* Returns a read-only (constant) reverse iterator that points to the last * the %map. Iteration is done in descending order according to the
* pair in the %map. Iteration is done in descending order according to * keys.
* the keys. */
*/ reverse_iterator
const_reverse_iterator rbegin()
rbegin() const { return _M_t.rbegin(); } { return _M_t.rbegin(); }
/** /**
* Returns a read/write reverse iterator that points to one before the * Returns a read-only (constant) reverse iterator that points to the
* first pair in the %map. Iteration is done in descending order according * last pair in the %map. Iteration is done in descending order
* to the keys. * according to the keys.
*/ */
reverse_iterator const_reverse_iterator
rend() { return _M_t.rend(); } rbegin() const
{ return _M_t.rbegin(); }
/**
* Returns a read-only (constant) reverse iterator that points to one /**
* before the first pair in the %map. Iteration is done in descending * Returns a read/write reverse iterator that points to one before the
* order according to the keys. * first pair in the %map. Iteration is done in descending order
*/ * according to the keys.
const_reverse_iterator */
rend() const { return _M_t.rend(); } reverse_iterator
rend()
// capacity { return _M_t.rend(); }
/** Returns true if the %map is empty. (Thus begin() would equal end().) */
bool /**
empty() const { return _M_t.empty(); } * Returns a read-only (constant) reverse iterator that points to one
* before the first pair in the %map. Iteration is done in descending
/** Returns the size of the %map. */ * order according to the keys.
size_type */
size() const { return _M_t.size(); } const_reverse_iterator
rend() const
/** Returns the maximum size of the %map. */ { return _M_t.rend(); }
size_type
max_size() const { return _M_t.max_size(); } // capacity
/** Returns true if the %map is empty. (Thus begin() would equal
// [23.3.1.2] element access * end().)
/** */
* @brief Subscript ( @c [] ) access to %map data. bool
* @param k The key for which data should be retrieved. empty() const
* @return A reference to the data of the (key,data) %pair. { return _M_t.empty(); }
*
* Allows for easy lookup with the subscript ( @c [] ) operator. Returns /** Returns the size of the %map. */
* data associated with the key specified in subscript. If the key does size_type
* not exist, a pair with that key is created using default values, which size() const
* is then returned. { return _M_t.size(); }
*
* Lookup requires logarithmic time. /** Returns the maximum size of the %map. */
*/ size_type
mapped_type& max_size() const
operator[](const key_type& __k) { return _M_t.max_size(); }
{
// concept requirements // [23.3.1.2] element access
__glibcxx_function_requires(_DefaultConstructibleConcept<mapped_type>) /**
* @brief Subscript ( @c [] ) access to %map data.
iterator __i = lower_bound(__k); * @param k The key for which data should be retrieved.
// __i->first is greater than or equivalent to __k. * @return A reference to the data of the (key,data) %pair.
if (__i == end() || key_comp()(__k, (*__i).first)) *
* Allows for easy lookup with the subscript ( @c [] ) operator. Returns
* data associated with the key specified in subscript. If the key does
* not exist, a pair with that key is created using default values, which
* is then returned.
*
* Lookup requires logarithmic time.
*/
mapped_type&
operator[](const key_type& __k)
{
// concept requirements
__glibcxx_function_requires(_DefaultConstructibleConcept<mapped_type>)
iterator __i = lower_bound(__k);
// __i->first is greater than or equivalent to __k.
if (__i == end() || key_comp()(__k, (*__i).first))
__i = insert(__i, value_type(__k, mapped_type())); __i = insert(__i, value_type(__k, mapped_type()));
return (*__i).second; return (*__i).second;
} }
// modifiers // modifiers
/** /**
* @brief Attempts to insert a std::pair into the %map. * @brief Attempts to insert a std::pair into the %map.
* @param x Pair to be inserted (see std::make_pair for easy creation of * @param x Pair to be inserted (see std::make_pair for easy creation of
* pairs). * pairs).
* @return A pair, of which the first element is an iterator that points * @return A pair, of which the first element is an iterator that points
* to the possibly inserted pair, and the second is a bool that * to the possibly inserted pair, and the second is a bool that
* is true if the pair was actually inserted. * is true if the pair was actually inserted.
* *
* This function attempts to insert a (key, value) %pair into the %map. * This function attempts to insert a (key, value) %pair into the %map.
* A %map relies on unique keys and thus a %pair is only inserted if its * A %map relies on unique keys and thus a %pair is only inserted if its
* first element (the key) is not already present in the %map. * first element (the key) is not already present in the %map.
* *
* Insertion requires logarithmic time. * Insertion requires logarithmic time.
*/ */
pair<iterator,bool> pair<iterator,bool>
insert(const value_type& __x) insert(const value_type& __x)
{ return _M_t.insert_unique(__x); } { return _M_t.insert_unique(__x); }
/** /**
* @brief Attempts to insert a std::pair into the %map. * @brief Attempts to insert a std::pair into the %map.
* @param position An iterator that serves as a hint as to where the * @param position An iterator that serves as a hint as to where the
* pair should be inserted. * pair should be inserted.
* @param x Pair to be inserted (see std::make_pair for easy creation of * @param x Pair to be inserted (see std::make_pair for easy creation of
* pairs). * pairs).
* @return An iterator that points to the element with key of @a x (may * @return An iterator that points to the element with key of @a x (may
* or may not be the %pair passed in). * or may not be the %pair passed in).
* *
* This function is not concerned about whether the insertion took place, * This function is not concerned about whether the insertion took place,
* and thus does not return a boolean like the single-argument * and thus does not return a boolean like the single-argument
* insert() does. Note that the first parameter is only a hint and can * insert() does. Note that the first parameter is only a hint and can
* potentially improve the performance of the insertion process. A bad * potentially improve the performance of the insertion process. A bad
* hint would cause no gains in efficiency. * hint would cause no gains in efficiency.
* *
* See http://gcc.gnu.org/onlinedocs/libstdc++/23_containers/howto.html#4 * See http://gcc.gnu.org/onlinedocs/libstdc++/23_containers/howto.html#4
* for more on "hinting". * for more on "hinting".
* *
* Insertion requires logarithmic time (if the hint is not taken). * Insertion requires logarithmic time (if the hint is not taken).
*/ */
iterator iterator
insert(iterator position, const value_type& __x) insert(iterator position, const value_type& __x)
{ return _M_t.insert_unique(position, __x); } { return _M_t.insert_unique(position, __x); }
/** /**
* @brief A template function that attemps to insert a range of elements. * @brief A template function that attemps to insert a range of elements.
* @param first Iterator pointing to the start of the range to be * @param first Iterator pointing to the start of the range to be
* inserted. * inserted.
* @param last Iterator pointing to the end of the range. * @param last Iterator pointing to the end of the range.
* *
* Complexity similar to that of the range constructor. * Complexity similar to that of the range constructor.
*/ */
template <typename _InputIterator> template <typename _InputIterator>
void
insert(_InputIterator __first, _InputIterator __last)
{ _M_t.insert_unique(__first, __last); }
/**
* @brief Erases an element from a %map.
* @param position An iterator pointing to the element to be erased.
*
* This function erases an element, pointed to by the given iterator,
* from a %map. Note that this function only erases the element, and
* that if the element is itself a pointer, the pointed-to memory is not
* touched in any way. Managing the pointer is the user's responsibilty.
*/
void void
insert(_InputIterator __first, _InputIterator __last) erase(iterator __position)
{ _M_t.insert_unique(__first, __last); } { _M_t.erase(__position); }
/** /**
* @brief Erases an element from a %map. * @brief Erases elements according to the provided key.
* @param position An iterator pointing to the element to be erased. * @param x Key of element to be erased.
* * @return The number of elements erased.
* This function erases an element, pointed to by the given iterator, from *
* a %map. Note that this function only erases the element, and that if * This function erases all the elements located by the given key from
* the element is itself a pointer, the pointed-to memory is not touched * a %map.
* in any way. Managing the pointer is the user's responsibilty. * Note that this function only erases the element, and that if
*/ * the element is itself a pointer, the pointed-to memory is not touched
void * in any way. Managing the pointer is the user's responsibilty.
erase(iterator __position) { _M_t.erase(__position); } */
size_type
/** erase(const key_type& __x)
* @brief Erases elements according to the provided key. { return _M_t.erase(__x); }
* @param x Key of element to be erased.
* @return The number of elements erased. /**
* * @brief Erases a [first,last) range of elements from a %map.
* This function erases all the elements located by the given key from * @param first Iterator pointing to the start of the range to be
* a %map. * erased.
* Note that this function only erases the element, and that if * @param last Iterator pointing to the end of the range to be erased.
* the element is itself a pointer, the pointed-to memory is not touched *
* in any way. Managing the pointer is the user's responsibilty. * This function erases a sequence of elements from a %map.
*/ * Note that this function only erases the element, and that if
size_type * the element is itself a pointer, the pointed-to memory is not touched
erase(const key_type& __x) { return _M_t.erase(__x); } * in any way. Managing the pointer is the user's responsibilty.
*/
/** void
* @brief Erases a [first,last) range of elements from a %map. erase(iterator __first, iterator __last)
* @param first Iterator pointing to the start of the range to be erased. { _M_t.erase(__first, __last); }
* @param last Iterator pointing to the end of the range to be erased.
* /**
* This function erases a sequence of elements from a %map. * @brief Swaps data with another %map.
* Note that this function only erases the element, and that if * @param x A %map of the same element and allocator types.
* the element is itself a pointer, the pointed-to memory is not touched *
* in any way. Managing the pointer is the user's responsibilty. * This exchanges the elements between two maps in constant time.
*/ * (It is only swapping a pointer, an integer, and an instance of
void * the @c Compare type (which itself is often stateless and empty), so it
erase(iterator __first, iterator __last) { _M_t.erase(__first, __last); } * should be quite fast.)
* Note that the global std::swap() function is specialized such that
/** * std::swap(m1,m2) will feed to this function.
* @brief Swaps data with another %map. */
* @param x A %map of the same element and allocator types. void
* swap(map& __x)
* This exchanges the elements between two maps in constant time. { _M_t.swap(__x._M_t); }
* (It is only swapping a pointer, an integer, and an instance of
* the @c Compare type (which itself is often stateless and empty), so it /**
* should be quite fast.) * Erases all elements in a %map. Note that this function only erases
* Note that the global std::swap() function is specialized such that * the elements, and that if the elements themselves are pointers, the
* std::swap(m1,m2) will feed to this function. * pointed-to memory is not touched in any way. Managing the pointer is
*/ * the user's responsibilty.
void */
swap(map& __x) { _M_t.swap(__x._M_t); } void
clear()
/** { _M_t.clear(); }
* Erases all elements in a %map. Note that this function only erases
* the elements, and that if the elements themselves are pointers, the // observers
* pointed-to memory is not touched in any way. Managing the pointer is /**
* the user's responsibilty. * Returns the key comparison object out of which the %map was
*/ * constructed.
void */
clear() { _M_t.clear(); } key_compare
key_comp() const
// observers { return _M_t.key_comp(); }
/**
* Returns the key comparison object out of which the %map was constructed. /**
*/ * Returns a value comparison object, built from the key comparison
key_compare * object out of which the %map was constructed.
key_comp() const { return _M_t.key_comp(); } */
value_compare
/** value_comp() const
* Returns a value comparison object, built from the key comparison { return value_compare(_M_t.key_comp()); }
* object out of which the %map was constructed.
*/ // [23.3.1.3] map operations
value_compare /**
value_comp() const { return value_compare(_M_t.key_comp()); } * @brief Tries to locate an element in a %map.
* @param x Key of (key, value) %pair to be located.
// [23.3.1.3] map operations * @return Iterator pointing to sought-after element, or end() if not
/** * found.
* @brief Tries to locate an element in a %map. *
* @param x Key of (key, value) %pair to be located. * This function takes a key and tries to locate the element with which
* @return Iterator pointing to sought-after element, or end() if not * the key matches. If successful the function returns an iterator
* found. * pointing to the sought after %pair. If unsuccessful it returns the
* * past-the-end ( @c end() ) iterator.
* This function takes a key and tries to locate the element with which */
* the key matches. If successful the function returns an iterator iterator
* pointing to the sought after %pair. If unsuccessful it returns the find(const key_type& __x)
* past-the-end ( @c end() ) iterator. { return _M_t.find(__x); }
*/
iterator /**
find(const key_type& __x) { return _M_t.find(__x); } * @brief Tries to locate an element in a %map.
* @param x Key of (key, value) %pair to be located.
/** * @return Read-only (constant) iterator pointing to sought-after
* @brief Tries to locate an element in a %map. * element, or end() if not found.
* @param x Key of (key, value) %pair to be located. *
* @return Read-only (constant) iterator pointing to sought-after * This function takes a key and tries to locate the element with which
* element, or end() if not found. * the key matches. If successful the function returns a constant
* * iterator pointing to the sought after %pair. If unsuccessful it
* This function takes a key and tries to locate the element with which * returns the past-the-end ( @c end() ) iterator.
* the key matches. If successful the function returns a constant iterator */
* pointing to the sought after %pair. If unsuccessful it returns the const_iterator
* past-the-end ( @c end() ) iterator. find(const key_type& __x) const
*/ { return _M_t.find(__x); }
const_iterator
find(const key_type& __x) const { return _M_t.find(__x); } /**
* @brief Finds the number of elements with given key.
/** * @param x Key of (key, value) pairs to be located.
* @brief Finds the number of elements with given key. * @return Number of elements with specified key.
* @param x Key of (key, value) pairs to be located. *
* @return Number of elements with specified key. * This function only makes sense for multimaps; for map the result will
* * either be 0 (not present) or 1 (present).
* This function only makes sense for multimaps; for map the result will */
* either be 0 (not present) or 1 (present). size_type
*/ count(const key_type& __x) const
size_type { return _M_t.find(__x) == _M_t.end() ? 0 : 1; }
count(const key_type& __x) const
{ return _M_t.find(__x) == _M_t.end() ? 0 : 1; } /**
* @brief Finds the beginning of a subsequence matching given key.
/** * @param x Key of (key, value) pair to be located.
* @brief Finds the beginning of a subsequence matching given key. * @return Iterator pointing to first element equal to or greater
* @param x Key of (key, value) pair to be located. * than key, or end().
* @return Iterator pointing to first element equal to or greater *
* than key, or end(). * This function returns the first element of a subsequence of elements
* * that matches the given key. If unsuccessful it returns an iterator
* This function returns the first element of a subsequence of elements * pointing to the first element that has a greater value than given key
* that matches the given key. If unsuccessful it returns an iterator * or end() if no such element exists.
* pointing to the first element that has a greater value than given key */
* or end() if no such element exists. iterator
*/ lower_bound(const key_type& __x)
iterator { return _M_t.lower_bound(__x); }
lower_bound(const key_type& __x) { return _M_t.lower_bound(__x); }
/**
/** * @brief Finds the beginning of a subsequence matching given key.
* @brief Finds the beginning of a subsequence matching given key. * @param x Key of (key, value) pair to be located.
* @param x Key of (key, value) pair to be located. * @return Read-only (constant) iterator pointing to first element
* @return Read-only (constant) iterator pointing to first element * equal to or greater than key, or end().
* equal to or greater than key, or end(). *
* * This function returns the first element of a subsequence of elements
* This function returns the first element of a subsequence of elements * that matches the given key. If unsuccessful it returns an iterator
* that matches the given key. If unsuccessful it returns an iterator * pointing to the first element that has a greater value than given key
* pointing to the first element that has a greater value than given key * or end() if no such element exists.
* or end() if no such element exists. */
*/ const_iterator
const_iterator lower_bound(const key_type& __x) const
lower_bound(const key_type& __x) const { return _M_t.lower_bound(__x); } { return _M_t.lower_bound(__x); }
/** /**
* @brief Finds the end of a subsequence matching given key. * @brief Finds the end of a subsequence matching given key.
* @param x Key of (key, value) pair to be located. * @param x Key of (key, value) pair to be located.
* @return Iterator pointing to the first element * @return Iterator pointing to the first element
* greater than key, or end(). * greater than key, or end().
*/ */
iterator iterator
upper_bound(const key_type& __x) { return _M_t.upper_bound(__x); } upper_bound(const key_type& __x)
{ return _M_t.upper_bound(__x); }
/**
* @brief Finds the end of a subsequence matching given key. /**
* @param x Key of (key, value) pair to be located. * @brief Finds the end of a subsequence matching given key.
* @return Read-only (constant) iterator pointing to first iterator * @param x Key of (key, value) pair to be located.
* greater than key, or end(). * @return Read-only (constant) iterator pointing to first iterator
*/ * greater than key, or end().
const_iterator */
upper_bound(const key_type& __x) const const_iterator
{ return _M_t.upper_bound(__x); } upper_bound(const key_type& __x) const
{ return _M_t.upper_bound(__x); }
/**
* @brief Finds a subsequence matching given key. /**
* @param x Key of (key, value) pairs to be located. * @brief Finds a subsequence matching given key.
* @return Pair of iterators that possibly points to the subsequence * @param x Key of (key, value) pairs to be located.
* matching given key. * @return Pair of iterators that possibly points to the subsequence
* * matching given key.
* This function is equivalent to *
* @code * This function is equivalent to
* std::make_pair(c.lower_bound(val), * @code
* c.upper_bound(val)) * std::make_pair(c.lower_bound(val),
* @endcode * c.upper_bound(val))
* (but is faster than making the calls separately). * @endcode
* * (but is faster than making the calls separately).
* This function probably only makes sense for multimaps. *
*/ * This function probably only makes sense for multimaps.
pair<iterator,iterator> */
equal_range(const key_type& __x) pair<iterator,iterator>
{ return _M_t.equal_range(__x); } equal_range(const key_type& __x)
{ return _M_t.equal_range(__x); }
/**
* @brief Finds a subsequence matching given key. /**
* @param x Key of (key, value) pairs to be located. * @brief Finds a subsequence matching given key.
* @return Pair of read-only (constant) iterators that possibly points to * @param x Key of (key, value) pairs to be located.
* the subsequence matching given key. * @return Pair of read-only (constant) iterators that possibly points
* * to the subsequence matching given key.
* This function is equivalent to *
* @code * This function is equivalent to
* std::make_pair(c.lower_bound(val), * @code
* c.upper_bound(val)) * std::make_pair(c.lower_bound(val),
* @endcode * c.upper_bound(val))
* (but is faster than making the calls separately). * @endcode
* * (but is faster than making the calls separately).
* This function probably only makes sense for multimaps. *
*/ * This function probably only makes sense for multimaps.
pair<const_iterator,const_iterator> */
equal_range(const key_type& __x) const pair<const_iterator,const_iterator>
{ return _M_t.equal_range(__x); } equal_range(const key_type& __x) const
{ return _M_t.equal_range(__x); }
template <typename _K1, typename _T1, typename _C1, typename _A1>
friend bool operator== (const map<_K1,_T1,_C1,_A1>&, template <typename _K1, typename _T1, typename _C1, typename _A1>
const map<_K1,_T1,_C1,_A1>&); friend bool operator== (const map<_K1,_T1,_C1,_A1>&,
template <typename _K1, typename _T1, typename _C1, typename _A1> const map<_K1,_T1,_C1,_A1>&);
friend bool operator< (const map<_K1,_T1,_C1,_A1>&, template <typename _K1, typename _T1, typename _C1, typename _A1>
const map<_K1,_T1,_C1,_A1>&); friend bool operator< (const map<_K1,_T1,_C1,_A1>&,
}; const map<_K1,_T1,_C1,_A1>&);
};
/** /**
* @brief Map equality comparison. * @brief Map equality comparison.
......
// Multimap implementation -*- C++ -*- // Multimap implementation -*- C++ -*-
// Copyright (C) 2001, 2002 Free Software Foundation, Inc. // Copyright (C) 2001, 2002, 2004 Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the // software; you can redistribute it and/or modify it under the
...@@ -103,466 +103,507 @@ namespace __gnu_norm ...@@ -103,466 +103,507 @@ namespace __gnu_norm
*/ */
template <typename _Key, typename _Tp, typename _Compare, typename _Alloc> template <typename _Key, typename _Tp, typename _Compare, typename _Alloc>
class multimap class multimap
{ {
// concept requirements // concept requirements
__glibcxx_class_requires(_Tp, _SGIAssignableConcept) __glibcxx_class_requires(_Tp, _SGIAssignableConcept)
__glibcxx_class_requires4(_Compare, bool, _Key, _Key, _BinaryFunctionConcept) __glibcxx_class_requires4(_Compare, bool, _Key, _Key,
_BinaryFunctionConcept)
public:
typedef _Key key_type; public:
typedef _Tp mapped_type; typedef _Key key_type;
typedef pair<const _Key, _Tp> value_type; typedef _Tp mapped_type;
typedef _Compare key_compare; typedef pair<const _Key, _Tp> value_type;
typedef _Compare key_compare;
class value_compare
class value_compare
: public binary_function<value_type, value_type, bool> : public binary_function<value_type, value_type, bool>
{ {
friend class multimap<_Key,_Tp,_Compare,_Alloc>; friend class multimap<_Key,_Tp,_Compare,_Alloc>;
protected: protected:
_Compare comp; _Compare comp;
value_compare(_Compare __c) : comp(__c) {}
value_compare(_Compare __c)
: comp(__c) { }
public: public:
bool operator()(const value_type& __x, const value_type& __y) const bool operator()(const value_type& __x, const value_type& __y) const
{ return comp(__x.first, __y.first); } { return comp(__x.first, __y.first); }
}; };
private: private:
/// @if maint This turns a red-black tree into a [multi]map. @endif /// @if maint This turns a red-black tree into a [multi]map. @endif
typedef _Rb_tree<key_type, value_type, typedef _Rb_tree<key_type, value_type,
_Select1st<value_type>, key_compare, _Alloc> _Rep_type; _Select1st<value_type>, key_compare, _Alloc> _Rep_type;
/// @if maint The actual tree structure. @endif /// @if maint The actual tree structure. @endif
_Rep_type _M_t; _Rep_type _M_t;
public: public:
// many of these are specified differently in ISO, but the following are // many of these are specified differently in ISO, but the following are
// "functionally equivalent" // "functionally equivalent"
typedef typename _Rep_type::allocator_type allocator_type; typedef typename _Rep_type::allocator_type allocator_type;
typedef typename _Rep_type::reference reference; typedef typename _Rep_type::reference reference;
typedef typename _Rep_type::const_reference const_reference; typedef typename _Rep_type::const_reference const_reference;
typedef typename _Rep_type::iterator iterator; typedef typename _Rep_type::iterator iterator;
typedef typename _Rep_type::const_iterator const_iterator; typedef typename _Rep_type::const_iterator const_iterator;
typedef typename _Rep_type::size_type size_type; typedef typename _Rep_type::size_type size_type;
typedef typename _Rep_type::difference_type difference_type; typedef typename _Rep_type::difference_type difference_type;
typedef typename _Rep_type::pointer pointer; typedef typename _Rep_type::pointer pointer;
typedef typename _Rep_type::const_pointer const_pointer; typedef typename _Rep_type::const_pointer const_pointer;
typedef typename _Rep_type::reverse_iterator reverse_iterator; typedef typename _Rep_type::reverse_iterator reverse_iterator;
typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator; typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator;
// [23.3.2] construct/copy/destroy // [23.3.2] construct/copy/destroy
// (get_allocator() is also listed in this section) // (get_allocator() is also listed in this section)
/** /**
* @brief Default constructor creates no elements. * @brief Default constructor creates no elements.
*/ */
multimap() : _M_t(_Compare(), allocator_type()) { } multimap()
: _M_t(_Compare(), allocator_type()) { }
// for some reason this was made a separate function
/** // for some reason this was made a separate function
* @brief Default constructor creates no elements. /**
*/ * @brief Default constructor creates no elements.
explicit */
multimap(const _Compare& __comp, const allocator_type& __a = allocator_type()) explicit
multimap(const _Compare& __comp,
const allocator_type& __a = allocator_type())
: _M_t(__comp, __a) { } : _M_t(__comp, __a) { }
/** /**
* @brief %Multimap copy constructor. * @brief %Multimap copy constructor.
* @param x A %multimap of identical element and allocator types. * @param x A %multimap of identical element and allocator types.
* *
* The newly-created %multimap uses a copy of the allocation object used * The newly-created %multimap uses a copy of the allocation object used
* by @a x. * by @a x.
*/ */
multimap(const multimap& __x) multimap(const multimap& __x)
: _M_t(__x._M_t) { } : _M_t(__x._M_t) { }
/** /**
* @brief Builds a %multimap from a range. * @brief Builds a %multimap from a range.
* @param first An input iterator. * @param first An input iterator.
* @param last An input iterator. * @param last An input iterator.
* *
* Create a %multimap consisting of copies of the elements from * Create a %multimap consisting of copies of the elements from
* [first,last). This is linear in N if the range is already sorted, * [first,last). This is linear in N if the range is already sorted,
* and NlogN otherwise (where N is distance(first,last)). * and NlogN otherwise (where N is distance(first,last)).
*/ */
template <typename _InputIterator> template <typename _InputIterator>
multimap(_InputIterator __first, _InputIterator __last) multimap(_InputIterator __first, _InputIterator __last)
: _M_t(_Compare(), allocator_type()) : _M_t(_Compare(), allocator_type())
{ _M_t.insert_equal(__first, __last); } { _M_t.insert_equal(__first, __last); }
/** /**
* @brief Builds a %multimap from a range. * @brief Builds a %multimap from a range.
* @param first An input iterator. * @param first An input iterator.
* @param last An input iterator. * @param last An input iterator.
* @param comp A comparison functor. * @param comp A comparison functor.
* @param a An allocator object. * @param a An allocator object.
* *
* Create a %multimap consisting of copies of the elements from * Create a %multimap consisting of copies of the elements from
* [first,last). This is linear in N if the range is already sorted, * [first,last). This is linear in N if the range is already sorted,
* and NlogN otherwise (where N is distance(first,last)). * and NlogN otherwise (where N is distance(first,last)).
*/ */
template <typename _InputIterator> template <typename _InputIterator>
multimap(_InputIterator __first, _InputIterator __last, multimap(_InputIterator __first, _InputIterator __last,
const _Compare& __comp, const _Compare& __comp,
const allocator_type& __a = allocator_type()) const allocator_type& __a = allocator_type())
: _M_t(__comp, __a) : _M_t(__comp, __a)
{ _M_t.insert_equal(__first, __last); } { _M_t.insert_equal(__first, __last); }
// FIXME There is no dtor declared, but we should have something generated // FIXME There is no dtor declared, but we should have something generated
// by Doxygen. I don't know what tags to add to this paragraph to make // by Doxygen. I don't know what tags to add to this paragraph to make
// that happen: // that happen:
/** /**
* The dtor only erases the elements, and note that if the elements * The dtor only erases the elements, and note that if the elements
* themselves are pointers, the pointed-to memory is not touched in any * themselves are pointers, the pointed-to memory is not touched in any
* way. Managing the pointer is the user's responsibilty. * way. Managing the pointer is the user's responsibilty.
*/ */
/** /**
* @brief %Multimap assignment operator. * @brief %Multimap assignment operator.
* @param x A %multimap of identical element and allocator types. * @param x A %multimap of identical element and allocator types.
* *
* All the elements of @a x are copied, but unlike the copy constructor, * All the elements of @a x are copied, but unlike the copy constructor,
* the allocator object is not copied. * the allocator object is not copied.
*/ */
multimap& multimap&
operator=(const multimap& __x) operator=(const multimap& __x)
{ {
_M_t = __x._M_t; _M_t = __x._M_t;
return *this; return *this;
} }
/// Get a copy of the memory allocation object. /// Get a copy of the memory allocation object.
allocator_type allocator_type
get_allocator() const { return _M_t.get_allocator(); } get_allocator() const
{ return _M_t.get_allocator(); }
// iterators
/** // iterators
* Returns a read/write iterator that points to the first pair in the /**
* %multimap. Iteration is done in ascending order according to the keys. * Returns a read/write iterator that points to the first pair in the
*/ * %multimap. Iteration is done in ascending order according to the
iterator * keys.
begin() { return _M_t.begin(); } */
iterator
/** begin()
* Returns a read-only (constant) iterator that points to the first pair { return _M_t.begin(); }
* in the %multimap. Iteration is done in ascending order according to the
* keys. /**
*/ * Returns a read-only (constant) iterator that points to the first pair
const_iterator * in the %multimap. Iteration is done in ascending order according to
begin() const { return _M_t.begin(); } * the keys.
*/
/** const_iterator
* Returns a read/write iterator that points one past the last pair in the begin() const
* %multimap. Iteration is done in ascending order according to the keys. { return _M_t.begin(); }
*/
iterator /**
end() { return _M_t.end(); } * Returns a read/write iterator that points one past the last pair in
* the %multimap. Iteration is done in ascending order according to the
/** * keys.
* Returns a read-only (constant) iterator that points one past the last */
* pair in the %multimap. Iteration is done in ascending order according iterator
* to the keys. end()
*/ { return _M_t.end(); }
const_iterator
end() const { return _M_t.end(); } /**
* Returns a read-only (constant) iterator that points one past the last
/** * pair in the %multimap. Iteration is done in ascending order according
* Returns a read/write reverse iterator that points to the last pair in * to the keys.
* the %multimap. Iteration is done in descending order according to the */
* keys. const_iterator
*/ end() const
reverse_iterator { return _M_t.end(); }
rbegin() { return _M_t.rbegin(); }
/**
/** * Returns a read/write reverse iterator that points to the last pair in
* Returns a read-only (constant) reverse iterator that points to the last * the %multimap. Iteration is done in descending order according to the
* pair in the %multimap. Iteration is done in descending order according * keys.
* to the keys. */
*/ reverse_iterator
const_reverse_iterator rbegin()
rbegin() const { return _M_t.rbegin(); } { return _M_t.rbegin(); }
/** /**
* Returns a read/write reverse iterator that points to one before the * Returns a read-only (constant) reverse iterator that points to the
* first pair in the %multimap. Iteration is done in descending order * last pair in the %multimap. Iteration is done in descending order
* according to the keys. * according to the keys.
*/ */
reverse_iterator const_reverse_iterator
rend() { return _M_t.rend(); } rbegin() const
{ return _M_t.rbegin(); }
/**
* Returns a read-only (constant) reverse iterator that points to one /**
* before the first pair in the %multimap. Iteration is done in descending * Returns a read/write reverse iterator that points to one before the
* order according to the keys. * first pair in the %multimap. Iteration is done in descending order
*/ * according to the keys.
const_reverse_iterator */
rend() const { return _M_t.rend(); } reverse_iterator
rend()
// capacity { return _M_t.rend(); }
/** Returns true if the %multimap is empty. */
bool /**
empty() const { return _M_t.empty(); } * Returns a read-only (constant) reverse iterator that points to one
* before the first pair in the %multimap. Iteration is done in
/** Returns the size of the %multimap. */ * descending order according to the keys.
size_type */
size() const { return _M_t.size(); } const_reverse_iterator
rend() const
/** Returns the maximum size of the %multimap. */ { return _M_t.rend(); }
size_type
max_size() const { return _M_t.max_size(); } // capacity
/** Returns true if the %multimap is empty. */
// modifiers bool
/** empty() const
* @brief Inserts a std::pair into the %multimap. { return _M_t.empty(); }
* @param x Pair to be inserted (see std::make_pair for easy creation of
* pairs). /** Returns the size of the %multimap. */
* @return An iterator that points to the inserted (key,value) pair. size_type
* size() const
* This function inserts a (key, value) pair into the %multimap. Contrary { return _M_t.size(); }
* to a std::map the %multimap does not rely on unique keys and thus
* multiple pairs with the same key can be inserted. /** Returns the maximum size of the %multimap. */
* size_type
* Insertion requires logarithmic time. max_size() const
*/ { return _M_t.max_size(); }
iterator
insert(const value_type& __x) { return _M_t.insert_equal(__x); } // modifiers
/**
/** * @brief Inserts a std::pair into the %multimap.
* @brief Inserts a std::pair into the %multimap. * @param x Pair to be inserted (see std::make_pair for easy creation
* @param position An iterator that serves as a hint as to where the * of pairs).
* pair should be inserted. * @return An iterator that points to the inserted (key,value) pair.
* @param x Pair to be inserted (see std::make_pair for easy creation of *
* pairs). * This function inserts a (key, value) pair into the %multimap.
* @return An iterator that points to the inserted (key,value) pair. * Contrary to a std::map the %multimap does not rely on unique keys and
* * thus multiple pairs with the same key can be inserted.
* This function inserts a (key, value) pair into the %multimap. Contrary *
* to a std::map the %multimap does not rely on unique keys and thus * Insertion requires logarithmic time.
* multiple pairs with the same key can be inserted. */
* Note that the first parameter is only a hint and can potentially iterator
* improve the performance of the insertion process. A bad hint would insert(const value_type& __x)
* cause no gains in efficiency. { return _M_t.insert_equal(__x); }
*
* See http://gcc.gnu.org/onlinedocs/libstdc++/23_containers/howto.html#4 /**
* for more on "hinting". * @brief Inserts a std::pair into the %multimap.
* * @param position An iterator that serves as a hint as to where the
* Insertion requires logarithmic time (if the hint is not taken). * pair should be inserted.
*/ * @param x Pair to be inserted (see std::make_pair for easy creation
iterator * of pairs).
insert(iterator __position, const value_type& __x) * @return An iterator that points to the inserted (key,value) pair.
{ return _M_t.insert_equal(__position, __x); } *
* This function inserts a (key, value) pair into the %multimap.
* Contrary to a std::map the %multimap does not rely on unique keys and
* thus multiple pairs with the same key can be inserted.
* Note that the first parameter is only a hint and can potentially
* improve the performance of the insertion process. A bad hint would
* cause no gains in efficiency.
*
* See http://gcc.gnu.org/onlinedocs/libstdc++/23_containers/howto.html#4
* for more on "hinting".
*
* Insertion requires logarithmic time (if the hint is not taken).
*/
iterator
insert(iterator __position, const value_type& __x)
{ return _M_t.insert_equal(__position, __x); }
/**
* @brief A template function that attemps to insert a range of elements.
* @param first Iterator pointing to the start of the range to be
* inserted.
* @param last Iterator pointing to the end of the range.
*
* Complexity similar to that of the range constructor.
*/
template <typename _InputIterator>
void
insert(_InputIterator __first, _InputIterator __last)
{ _M_t.insert_equal(__first, __last); }
/** /**
* @brief A template function that attemps to insert a range of elements. * @brief Erases an element from a %multimap.
* @param first Iterator pointing to the start of the range to be * @param position An iterator pointing to the element to be erased.
* inserted. *
* @param last Iterator pointing to the end of the range. * This function erases an element, pointed to by the given iterator,
* * from a %multimap. Note that this function only erases the element,
* Complexity similar to that of the range constructor. * and that if the element is itself a pointer, the pointed-to memory is
*/ * not touched in any way. Managing the pointer is the user's
template <typename _InputIterator> * responsibilty.
*/
void void
insert(_InputIterator __first, _InputIterator __last) erase(iterator __position)
{ _M_t.insert_equal(__first, __last); } { _M_t.erase(__position); }
/** /**
* @brief Erases an element from a %multimap. * @brief Erases elements according to the provided key.
* @param position An iterator pointing to the element to be erased. * @param x Key of element to be erased.
* * @return The number of elements erased.
* This function erases an element, pointed to by the given iterator, from *
* a %multimap. Note that this function only erases the element, and that * This function erases all elements located by the given key from a
* if the element is itself a pointer, the pointed-to memory is not * %multimap.
* touched in any way. Managing the pointer is the user's responsibilty. * Note that this function only erases the element, and that if
*/ * the element is itself a pointer, the pointed-to memory is not touched
void * in any way. Managing the pointer is the user's responsibilty.
erase(iterator __position) { _M_t.erase(__position); } */
size_type
/** erase(const key_type& __x)
* @brief Erases elements according to the provided key. { return _M_t.erase(__x); }
* @param x Key of element to be erased.
* @return The number of elements erased. /**
* * @brief Erases a [first,last) range of elements from a %multimap.
* This function erases all elements located by the given key from a * @param first Iterator pointing to the start of the range to be
* %multimap. * erased.
* Note that this function only erases the element, and that if * @param last Iterator pointing to the end of the range to be erased.
* the element is itself a pointer, the pointed-to memory is not touched *
* in any way. Managing the pointer is the user's responsibilty. * This function erases a sequence of elements from a %multimap.
*/ * Note that this function only erases the elements, and that if
size_type * the elements themselves are pointers, the pointed-to memory is not
erase(const key_type& __x) { return _M_t.erase(__x); } * touched in any way. Managing the pointer is the user's responsibilty.
*/
/** void
* @brief Erases a [first,last) range of elements from a %multimap. erase(iterator __first, iterator __last)
* @param first Iterator pointing to the start of the range to be erased. { _M_t.erase(__first, __last); }
* @param last Iterator pointing to the end of the range to be erased.
* /**
* This function erases a sequence of elements from a %multimap. * @brief Swaps data with another %multimap.
* Note that this function only erases the elements, and that if * @param x A %multimap of the same element and allocator types.
* the elements themselves are pointers, the pointed-to memory is not *
* touched in any way. Managing the pointer is the user's responsibilty. * This exchanges the elements between two multimaps in constant time.
*/ * (It is only swapping a pointer, an integer, and an instance of
void * the @c Compare type (which itself is often stateless and empty), so it
erase(iterator __first, iterator __last) { _M_t.erase(__first, __last); } * should be quite fast.)
* Note that the global std::swap() function is specialized such that
/** * std::swap(m1,m2) will feed to this function.
* @brief Swaps data with another %multimap. */
* @param x A %multimap of the same element and allocator types. void
* swap(multimap& __x)
* This exchanges the elements between two multimaps in constant time. { _M_t.swap(__x._M_t); }
* (It is only swapping a pointer, an integer, and an instance of
* the @c Compare type (which itself is often stateless and empty), so it /**
* should be quite fast.) * Erases all elements in a %multimap. Note that this function only
* Note that the global std::swap() function is specialized such that * erases the elements, and that if the elements themselves are pointers,
* std::swap(m1,m2) will feed to this function. * the pointed-to memory is not touched in any way. Managing the pointer
*/ * is the user's responsibilty.
void */
swap(multimap& __x) { _M_t.swap(__x._M_t); } void
clear()
/** { _M_t.clear(); }
* Erases all elements in a %multimap. Note that this function only erases
* the elements, and that if the elements themselves are pointers, the // observers
* pointed-to memory is not touched in any way. Managing the pointer is /**
* the user's responsibilty. * Returns the key comparison object out of which the %multimap
*/ * was constructed.
void */
clear() { _M_t.clear(); } key_compare
key_comp() const
// observers { return _M_t.key_comp(); }
/**
* Returns the key comparison object out of which the %multimap /**
* was constructed. * Returns a value comparison object, built from the key comparison
*/ * object out of which the %multimap was constructed.
key_compare */
key_comp() const { return _M_t.key_comp(); } value_compare
value_comp() const
/** { return value_compare(_M_t.key_comp()); }
* Returns a value comparison object, built from the key comparison
* object out of which the %multimap was constructed. // multimap operations
*/ /**
value_compare * @brief Tries to locate an element in a %multimap.
value_comp() const { return value_compare(_M_t.key_comp()); } * @param x Key of (key, value) pair to be located.
* @return Iterator pointing to sought-after element,
// multimap operations * or end() if not found.
/** *
* @brief Tries to locate an element in a %multimap. * This function takes a key and tries to locate the element with which
* @param x Key of (key, value) pair to be located. * the key matches. If successful the function returns an iterator
* @return Iterator pointing to sought-after element, * pointing to the sought after %pair. If unsuccessful it returns the
* or end() if not found. * past-the-end ( @c end() ) iterator.
* */
* This function takes a key and tries to locate the element with which iterator
* the key matches. If successful the function returns an iterator find(const key_type& __x)
* pointing to the sought after %pair. If unsuccessful it returns the { return _M_t.find(__x); }
* past-the-end ( @c end() ) iterator.
*/ /**
iterator * @brief Tries to locate an element in a %multimap.
find(const key_type& __x) { return _M_t.find(__x); } * @param x Key of (key, value) pair to be located.
* @return Read-only (constant) iterator pointing to sought-after
/** * element, or end() if not found.
* @brief Tries to locate an element in a %multimap. *
* @param x Key of (key, value) pair to be located. * This function takes a key and tries to locate the element with which
* @return Read-only (constant) iterator pointing to sought-after * the key matches. If successful the function returns a constant
* element, or end() if not found. * iterator pointing to the sought after %pair. If unsuccessful it
* * returns the past-the-end ( @c end() ) iterator.
* This function takes a key and tries to locate the element with which */
* the key matches. If successful the function returns a constant iterator const_iterator
* pointing to the sought after %pair. If unsuccessful it returns the find(const key_type& __x) const
* past-the-end ( @c end() ) iterator. { return _M_t.find(__x); }
*/
const_iterator /**
find(const key_type& __x) const { return _M_t.find(__x); } * @brief Finds the number of elements with given key.
* @param x Key of (key, value) pairs to be located.
/** * @return Number of elements with specified key.
* @brief Finds the number of elements with given key. */
* @param x Key of (key, value) pairs to be located. size_type
* @return Number of elements with specified key. count(const key_type& __x) const
*/ { return _M_t.count(__x); }
size_type
count(const key_type& __x) const { return _M_t.count(__x); } /**
* @brief Finds the beginning of a subsequence matching given key.
/** * @param x Key of (key, value) pair to be located.
* @brief Finds the beginning of a subsequence matching given key. * @return Iterator pointing to first element equal to or greater
* @param x Key of (key, value) pair to be located. * than key, or end().
* @return Iterator pointing to first element equal to or greater *
* than key, or end(). * This function returns the first element of a subsequence of elements
* * that matches the given key. If unsuccessful it returns an iterator
* This function returns the first element of a subsequence of elements * pointing to the first element that has a greater value than given key
* that matches the given key. If unsuccessful it returns an iterator * or end() if no such element exists.
* pointing to the first element that has a greater value than given key */
* or end() if no such element exists. iterator
*/ lower_bound(const key_type& __x)
iterator { return _M_t.lower_bound(__x); }
lower_bound(const key_type& __x) { return _M_t.lower_bound(__x); }
/**
/** * @brief Finds the beginning of a subsequence matching given key.
* @brief Finds the beginning of a subsequence matching given key. * @param x Key of (key, value) pair to be located.
* @param x Key of (key, value) pair to be located. * @return Read-only (constant) iterator pointing to first element
* @return Read-only (constant) iterator pointing to first element * equal to or greater than key, or end().
* equal to or greater than key, or end(). *
* * This function returns the first element of a subsequence of elements
* This function returns the first element of a subsequence of elements * that matches the given key. If unsuccessful the iterator will point
* that matches the given key. If unsuccessful the iterator will point * to the next greatest element or, if no such greater element exists, to
* to the next greatest element or, if no such greater element exists, to * end().
* end(). */
*/ const_iterator
const_iterator lower_bound(const key_type& __x) const
lower_bound(const key_type& __x) const { return _M_t.lower_bound(__x); } { return _M_t.lower_bound(__x); }
/** /**
* @brief Finds the end of a subsequence matching given key. * @brief Finds the end of a subsequence matching given key.
* @param x Key of (key, value) pair to be located. * @param x Key of (key, value) pair to be located.
* @return Iterator pointing to the first element * @return Iterator pointing to the first element
* greater than key, or end(). * greater than key, or end().
*/ */
iterator iterator
upper_bound(const key_type& __x) { return _M_t.upper_bound(__x); } upper_bound(const key_type& __x)
{ return _M_t.upper_bound(__x); }
/**
* @brief Finds the end of a subsequence matching given key. /**
* @param x Key of (key, value) pair to be located. * @brief Finds the end of a subsequence matching given key.
* @return Read-only (constant) iterator pointing to first iterator * @param x Key of (key, value) pair to be located.
* greater than key, or end(). * @return Read-only (constant) iterator pointing to first iterator
*/ * greater than key, or end().
const_iterator */
upper_bound(const key_type& __x) const { return _M_t.upper_bound(__x); } const_iterator
upper_bound(const key_type& __x) const
/** { return _M_t.upper_bound(__x); }
* @brief Finds a subsequence matching given key.
* @param x Key of (key, value) pairs to be located. /**
* @return Pair of iterators that possibly points to the subsequence * @brief Finds a subsequence matching given key.
* matching given key. * @param x Key of (key, value) pairs to be located.
* * @return Pair of iterators that possibly points to the subsequence
* This function is equivalent to * matching given key.
* @code *
* std::make_pair(c.lower_bound(val), * This function is equivalent to
* c.upper_bound(val)) * @code
* @endcode * std::make_pair(c.lower_bound(val),
* (but is faster than making the calls separately). * c.upper_bound(val))
*/ * @endcode
pair<iterator,iterator> * (but is faster than making the calls separately).
equal_range(const key_type& __x) { return _M_t.equal_range(__x); } */
pair<iterator,iterator>
/** equal_range(const key_type& __x)
* @brief Finds a subsequence matching given key. { return _M_t.equal_range(__x); }
* @param x Key of (key, value) pairs to be located.
* @return Pair of read-only (constant) iterators that possibly points to /**
* the subsequence matching given key. * @brief Finds a subsequence matching given key.
* * @param x Key of (key, value) pairs to be located.
* This function is equivalent to * @return Pair of read-only (constant) iterators that possibly points
* @code * to the subsequence matching given key.
* std::make_pair(c.lower_bound(val), *
* c.upper_bound(val)) * This function is equivalent to
* @endcode * @code
* (but is faster than making the calls separately). * std::make_pair(c.lower_bound(val),
*/ * c.upper_bound(val))
pair<const_iterator,const_iterator> * @endcode
equal_range(const key_type& __x) const { return _M_t.equal_range(__x); } * (but is faster than making the calls separately).
*/
template <typename _K1, typename _T1, typename _C1, typename _A1> pair<const_iterator,const_iterator>
friend bool operator== (const multimap<_K1,_T1,_C1,_A1>&, equal_range(const key_type& __x) const
const multimap<_K1,_T1,_C1,_A1>&); { return _M_t.equal_range(__x); }
template <typename _K1, typename _T1, typename _C1, typename _A1>
friend bool operator< (const multimap<_K1,_T1,_C1,_A1>&, template <typename _K1, typename _T1, typename _C1, typename _A1>
const multimap<_K1,_T1,_C1,_A1>&); friend bool
operator== (const multimap<_K1,_T1,_C1,_A1>&,
const multimap<_K1,_T1,_C1,_A1>&);
template <typename _K1, typename _T1, typename _C1, typename _A1>
friend bool
operator< (const multimap<_K1,_T1,_C1,_A1>&,
const multimap<_K1,_T1,_C1,_A1>&);
}; };
/** /**
* @brief Multimap equality comparison. * @brief Multimap equality comparison.
* @param x A %multimap. * @param x A %multimap.
...@@ -577,9 +618,7 @@ namespace __gnu_norm ...@@ -577,9 +618,7 @@ namespace __gnu_norm
inline bool inline bool
operator==(const multimap<_Key,_Tp,_Compare,_Alloc>& __x, operator==(const multimap<_Key,_Tp,_Compare,_Alloc>& __x,
const multimap<_Key,_Tp,_Compare,_Alloc>& __y) const multimap<_Key,_Tp,_Compare,_Alloc>& __y)
{ { return __x._M_t == __y._M_t; }
return __x._M_t == __y._M_t;
}
/** /**
* @brief Multimap ordering relation. * @brief Multimap ordering relation.
......
...@@ -66,19 +66,18 @@ ...@@ -66,19 +66,18 @@
namespace __gnu_norm namespace __gnu_norm
{ {
// Forward declaration of operators < and ==, needed for friend declaration. // Forward declaration of operators < and ==, needed for friend declaration.
template <class _Key, class _Compare = less<_Key>,
class _Alloc = allocator<_Key> >
class multiset;
template <class _Key, class _Compare = less<_Key>, template <class _Key, class _Compare, class _Alloc>
class _Alloc = allocator<_Key> > inline bool operator==(const multiset<_Key,_Compare,_Alloc>& __x,
class multiset; const multiset<_Key,_Compare,_Alloc>& __y);
template <class _Key, class _Compare, class _Alloc>
inline bool operator==(const multiset<_Key,_Compare,_Alloc>& __x,
const multiset<_Key,_Compare,_Alloc>& __y);
template <class _Key, class _Compare, class _Alloc> template <class _Key, class _Compare, class _Alloc>
inline bool operator<(const multiset<_Key,_Compare,_Alloc>& __x, inline bool operator<(const multiset<_Key,_Compare,_Alloc>& __x,
const multiset<_Key,_Compare,_Alloc>& __y); const multiset<_Key,_Compare,_Alloc>& __y);
/** /**
* @brief A standard container made up of elements, which can be retrieved * @brief A standard container made up of elements, which can be retrieved
...@@ -101,362 +100,410 @@ inline bool operator<(const multiset<_Key,_Compare,_Alloc>& __x, ...@@ -101,362 +100,410 @@ inline bool operator<(const multiset<_Key,_Compare,_Alloc>& __x,
* @endif * @endif
*/ */
template <class _Key, class _Compare, class _Alloc> template <class _Key, class _Compare, class _Alloc>
class multiset class multiset
{ {
// concept requirements // concept requirements
__glibcxx_class_requires(_Key, _SGIAssignableConcept) __glibcxx_class_requires(_Key, _SGIAssignableConcept)
__glibcxx_class_requires4(_Compare, bool, _Key, _Key, _BinaryFunctionConcept) __glibcxx_class_requires4(_Compare, bool, _Key, _Key,
_BinaryFunctionConcept)
public:
public:
// typedefs: // typedefs:
typedef _Key key_type;
typedef _Key key_type; typedef _Key value_type;
typedef _Key value_type; typedef _Compare key_compare;
typedef _Compare key_compare; typedef _Compare value_compare;
typedef _Compare value_compare;
private:
private: /// @if maint This turns a red-black tree into a [multi]set. @endif
/// @if maint This turns a red-black tree into a [multi]set. @endif typedef _Rb_tree<key_type, value_type,
typedef _Rb_tree<key_type, value_type, _Identity<value_type>, key_compare, _Alloc> _Rep_type;
_Identity<value_type>, key_compare, _Alloc> _Rep_type; /// @if maint The actual tree structure. @endif
/// @if maint The actual tree structure. @endif _Rep_type _M_t;
_Rep_type _M_t;
public:
public: typedef typename _Alloc::pointer pointer;
typedef typename _Alloc::pointer pointer; typedef typename _Alloc::const_pointer const_pointer;
typedef typename _Alloc::const_pointer const_pointer; typedef typename _Alloc::reference reference;
typedef typename _Alloc::reference reference; typedef typename _Alloc::const_reference const_reference;
typedef typename _Alloc::const_reference const_reference; typedef typename _Rep_type::const_iterator iterator;
typedef typename _Rep_type::const_iterator iterator; typedef typename _Rep_type::const_iterator const_iterator;
typedef typename _Rep_type::const_iterator const_iterator; typedef typename _Rep_type::const_reverse_iterator reverse_iterator;
typedef typename _Rep_type::const_reverse_iterator reverse_iterator; typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator;
typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator; typedef typename _Rep_type::size_type size_type;
typedef typename _Rep_type::size_type size_type; typedef typename _Rep_type::difference_type difference_type;
typedef typename _Rep_type::difference_type difference_type; typedef typename _Rep_type::allocator_type allocator_type;
typedef typename _Rep_type::allocator_type allocator_type;
// allocation/deallocation // allocation/deallocation
/** /**
* @brief Default constructor creates no elements. * @brief Default constructor creates no elements.
*/
multiset() : _M_t(_Compare(), allocator_type()) {}
explicit multiset(const _Compare& __comp,
const allocator_type& __a = allocator_type())
: _M_t(__comp, __a) {}
/**
* @brief Builds a %multiset from a range.
* @param first An input iterator.
* @param last An input iterator.
*
* Create a %multiset consisting of copies of the elements from
* [first,last). This is linear in N if the range is already sorted,
* and NlogN otherwise (where N is distance(first,last)).
*/
template <class _InputIterator>
multiset(_InputIterator __first, _InputIterator __last)
: _M_t(_Compare(), allocator_type())
{ _M_t.insert_equal(__first, __last); }
/**
* @brief Builds a %multiset from a range.
* @param first An input iterator.
* @param last An input iterator.
* @param comp A comparison functor.
* @param a An allocator object.
*
* Create a %multiset consisting of copies of the elements from
* [first,last). This is linear in N if the range is already sorted,
* and NlogN otherwise (where N is distance(first,last)).
*/
template <class _InputIterator>
multiset(_InputIterator __first, _InputIterator __last,
const _Compare& __comp,
const allocator_type& __a = allocator_type())
: _M_t(__comp, __a) { _M_t.insert_equal(__first, __last); }
/**
* @brief %Multiset copy constructor.
* @param x A %multiset of identical element and allocator types.
*
* The newly-created %multiset uses a copy of the allocation object used
* by @a x.
*/
multiset(const multiset<_Key,_Compare,_Alloc>& __x) : _M_t(__x._M_t) {}
/**
* @brief %Multiset assignment operator.
* @param x A %multiset of identical element and allocator types.
*
* All the elements of @a x are copied, but unlike the copy constructor,
* the allocator object is not copied.
*/
multiset<_Key,_Compare,_Alloc>&
operator=(const multiset<_Key,_Compare,_Alloc>& __x) {
_M_t = __x._M_t;
return *this;
}
// accessors:
/// Returns the comparison object.
key_compare key_comp() const { return _M_t.key_comp(); }
/// Returns the comparison object.
value_compare value_comp() const { return _M_t.key_comp(); }
/// Returns the memory allocation object.
allocator_type get_allocator() const { return _M_t.get_allocator(); }
/**
* Returns a read/write iterator that points to the first element in the
* %multiset. Iteration is done in ascending order according to the
* keys.
*/
iterator begin() const { return _M_t.begin(); }
/**
* Returns a read/write iterator that points one past the last element in
* the %multiset. Iteration is done in ascending order according to the
* keys.
*/
iterator end() const { return _M_t.end(); }
/**
* Returns a read/write reverse iterator that points to the last element
* in the %multiset. Iteration is done in descending order according to
* the keys.
*/
reverse_iterator rbegin() const { return _M_t.rbegin(); }
/**
* Returns a read/write reverse iterator that points to the last element
* in the %multiset. Iteration is done in descending order according to
* the keys.
*/
reverse_iterator rend() const { return _M_t.rend(); }
/// Returns true if the %set is empty.
bool empty() const { return _M_t.empty(); }
/// Returns the size of the %set.
size_type size() const { return _M_t.size(); }
/// Returns the maximum size of the %set.
size_type max_size() const { return _M_t.max_size(); }
/**
* @brief Swaps data with another %multiset.
* @param x A %multiset of the same element and allocator types.
*
* This exchanges the elements between two multisets in constant time.
* (It is only swapping a pointer, an integer, and an instance of the @c
* Compare type (which itself is often stateless and empty), so it should
* be quite fast.)
* Note that the global std::swap() function is specialized such that
* std::swap(s1,s2) will feed to this function.
*/ */
void swap(multiset<_Key,_Compare,_Alloc>& __x) { _M_t.swap(__x._M_t); } multiset()
: _M_t(_Compare(), allocator_type()) { }
// insert/erase
/** explicit multiset(const _Compare& __comp,
* @brief Inserts an element into the %multiset. const allocator_type& __a = allocator_type())
* @param x Element to be inserted. : _M_t(__comp, __a) { }
* @return An iterator that points to the inserted element.
* /**
* This function inserts an element into the %multiset. Contrary * @brief Builds a %multiset from a range.
* to a std::set the %multiset does not rely on unique keys and thus * @param first An input iterator.
* multiple copies of the same element can be inserted. * @param last An input iterator.
* *
* Insertion requires logarithmic time. * Create a %multiset consisting of copies of the elements from
*/ * [first,last). This is linear in N if the range is already sorted,
iterator insert(const value_type& __x) { * and NlogN otherwise (where N is distance(first,last)).
return _M_t.insert_equal(__x); */
} template <class _InputIterator>
multiset(_InputIterator __first, _InputIterator __last)
/** : _M_t(_Compare(), allocator_type())
* @brief Inserts an element into the %multiset. { _M_t.insert_equal(__first, __last); }
* @param position An iterator that serves as a hint as to where the
* element should be inserted. /**
* @param x Element to be inserted. * @brief Builds a %multiset from a range.
* @return An iterator that points to the inserted element. * @param first An input iterator.
* * @param last An input iterator.
* This function inserts an element into the %multiset. Contrary * @param comp A comparison functor.
* to a std::set the %multiset does not rely on unique keys and thus * @param a An allocator object.
* multiple copies of the same element can be inserted. *
* * Create a %multiset consisting of copies of the elements from
* Note that the first parameter is only a hint and can potentially * [first,last). This is linear in N if the range is already sorted,
* improve the performance of the insertion process. A bad hint would * and NlogN otherwise (where N is distance(first,last)).
* cause no gains in efficiency. */
* template <class _InputIterator>
* See http://gcc.gnu.org/onlinedocs/libstdc++/23_containers/howto.html#4 multiset(_InputIterator __first, _InputIterator __last,
* for more on "hinting". const _Compare& __comp,
* const allocator_type& __a = allocator_type())
* Insertion requires logarithmic time (if the hint is not taken). : _M_t(__comp, __a)
*/ { _M_t.insert_equal(__first, __last); }
iterator insert(iterator __position, const value_type& __x) {
typedef typename _Rep_type::iterator _Rep_iterator; /**
return _M_t.insert_equal((_Rep_iterator&)__position, __x); * @brief %Multiset copy constructor.
} * @param x A %multiset of identical element and allocator types.
*
/** * The newly-created %multiset uses a copy of the allocation object used
* @brief A template function that attemps to insert a range of elements. * by @a x.
* @param first Iterator pointing to the start of the range to be */
* inserted. multiset(const multiset<_Key,_Compare,_Alloc>& __x)
* @param last Iterator pointing to the end of the range. : _M_t(__x._M_t) { }
*
* Complexity similar to that of the range constructor. /**
*/ * @brief %Multiset assignment operator.
template <class _InputIterator> * @param x A %multiset of identical element and allocator types.
void insert(_InputIterator __first, _InputIterator __last) { *
_M_t.insert_equal(__first, __last); * All the elements of @a x are copied, but unlike the copy constructor,
} * the allocator object is not copied.
*/
/** multiset<_Key,_Compare,_Alloc>&
* @brief Erases an element from a %multiset. operator=(const multiset<_Key,_Compare,_Alloc>& __x)
* @param position An iterator pointing to the element to be erased. {
* _M_t = __x._M_t;
* This function erases an element, pointed to by the given iterator, return *this;
* from a %multiset. Note that this function only erases the element, }
* and that if the element is itself a pointer, the pointed-to memory is
* not touched in any way. Managing the pointer is the user's // accessors:
* responsibilty.
*/ /// Returns the comparison object.
void erase(iterator __position) { key_compare
typedef typename _Rep_type::iterator _Rep_iterator; key_comp() const
_M_t.erase((_Rep_iterator&)__position); { return _M_t.key_comp(); }
} /// Returns the comparison object.
value_compare
/** value_comp() const
* @brief Erases elements according to the provided key. { return _M_t.key_comp(); }
* @param x Key of element to be erased. /// Returns the memory allocation object.
* @return The number of elements erased. allocator_type
* get_allocator() const
* This function erases all elements located by the given key from a { return _M_t.get_allocator(); }
* %multiset.
* Note that this function only erases the element, and that if /**
* the element is itself a pointer, the pointed-to memory is not touched * Returns a read/write iterator that points to the first element in the
* in any way. Managing the pointer is the user's responsibilty. * %multiset. Iteration is done in ascending order according to the
*/ * keys.
size_type erase(const key_type& __x) { */
return _M_t.erase(__x); iterator
} begin() const
{ return _M_t.begin(); }
/**
* @brief Erases a [first,last) range of elements from a %multiset. /**
* @param first Iterator pointing to the start of the range to be erased. * Returns a read/write iterator that points one past the last element in
* @param last Iterator pointing to the end of the range to be erased. * the %multiset. Iteration is done in ascending order according to the
* * keys.
* This function erases a sequence of elements from a %multiset. */
* Note that this function only erases the elements, and that if iterator
* the elements themselves are pointers, the pointed-to memory is not end() const
* touched in any way. Managing the pointer is the user's responsibilty. { return _M_t.end(); }
*/
void erase(iterator __first, iterator __last) { /**
typedef typename _Rep_type::iterator _Rep_iterator; * Returns a read/write reverse iterator that points to the last element
_M_t.erase((_Rep_iterator&)__first, (_Rep_iterator&)__last); * in the %multiset. Iteration is done in descending order according to
} * the keys.
*/
/** reverse_iterator
* Erases all elements in a %multiset. Note that this function only rbegin() const
* erases the elements, and that if the elements themselves are pointers, { return _M_t.rbegin(); }
* the pointed-to memory is not touched in any way. Managing the pointer
* is the user's responsibilty. /**
*/ * Returns a read/write reverse iterator that points to the last element
void clear() { _M_t.clear(); } * in the %multiset. Iteration is done in descending order according to
* the keys.
// multiset operations: */
reverse_iterator
/** rend() const
* @brief Finds the number of elements with given key. { return _M_t.rend(); }
* @param x Key of elements to be located.
* @return Number of elements with specified key. /// Returns true if the %set is empty.
*/ bool
size_type count(const key_type& __x) const { return _M_t.count(__x); } empty() const
{ return _M_t.empty(); }
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 214. set::find() missing const overload /// Returns the size of the %set.
//@{ size_type
/** size() const
* @brief Tries to locate an element in a %set. { return _M_t.size(); }
* @param x Element to be located.
* @return Iterator pointing to sought-after element, or end() if not /// Returns the maximum size of the %set.
* found. size_type
* max_size() const
* This function takes a key and tries to locate the element with which { return _M_t.max_size(); }
* the key matches. If successful the function returns an iterator
* pointing to the sought after element. If unsuccessful it returns the /**
* past-the-end ( @c end() ) iterator. * @brief Swaps data with another %multiset.
*/ * @param x A %multiset of the same element and allocator types.
iterator find(const key_type& __x) { return _M_t.find(__x); } *
const_iterator find(const key_type& __x) const { return _M_t.find(__x); } * This exchanges the elements between two multisets in constant time.
//@} * (It is only swapping a pointer, an integer, and an instance of the @c
* Compare type (which itself is often stateless and empty), so it should
//@{ * be quite fast.)
/** * Note that the global std::swap() function is specialized such that
* @brief Finds the beginning of a subsequence matching given key. * std::swap(s1,s2) will feed to this function.
* @param x Key to be located. */
* @return Iterator pointing to first element equal to or greater void
* than key, or end(). swap(multiset<_Key,_Compare,_Alloc>& __x)
* { _M_t.swap(__x._M_t); }
* This function returns the first element of a subsequence of elements
* that matches the given key. If unsuccessful it returns an iterator // insert/erase
* pointing to the first element that has a greater value than given key /**
* or end() if no such element exists. * @brief Inserts an element into the %multiset.
*/ * @param x Element to be inserted.
iterator lower_bound(const key_type& __x) { * @return An iterator that points to the inserted element.
return _M_t.lower_bound(__x); *
} * This function inserts an element into the %multiset. Contrary
const_iterator lower_bound(const key_type& __x) const { * to a std::set the %multiset does not rely on unique keys and thus
return _M_t.lower_bound(__x); * multiple copies of the same element can be inserted.
} *
//@} * Insertion requires logarithmic time.
*/
//@{ iterator
/** insert(const value_type& __x)
* @brief Finds the end of a subsequence matching given key. { return _M_t.insert_equal(__x); }
* @param x Key to be located.
* @return Iterator pointing to the first element /**
* greater than key, or end(). * @brief Inserts an element into the %multiset.
*/ * @param position An iterator that serves as a hint as to where the
iterator upper_bound(const key_type& __x) { * element should be inserted.
return _M_t.upper_bound(__x); * @param x Element to be inserted.
} * @return An iterator that points to the inserted element.
const_iterator upper_bound(const key_type& __x) const { *
return _M_t.upper_bound(__x); * This function inserts an element into the %multiset. Contrary
} * to a std::set the %multiset does not rely on unique keys and thus
//@} * multiple copies of the same element can be inserted.
*
//@{ * Note that the first parameter is only a hint and can potentially
/** * improve the performance of the insertion process. A bad hint would
* @brief Finds a subsequence matching given key. * cause no gains in efficiency.
* @param x Key to be located. *
* @return Pair of iterators that possibly points to the subsequence * See http://gcc.gnu.org/onlinedocs/libstdc++/23_containers/howto.html#4
* matching given key. * for more on "hinting".
* *
* This function is equivalent to * Insertion requires logarithmic time (if the hint is not taken).
* @code */
* std::make_pair(c.lower_bound(val), iterator
* c.upper_bound(val)) insert(iterator __position, const value_type& __x)
* @endcode {
* (but is faster than making the calls separately). typedef typename _Rep_type::iterator _Rep_iterator;
* return _M_t.insert_equal((_Rep_iterator&)__position, __x);
* This function probably only makes sense for multisets. }
*/
pair<iterator,iterator> equal_range(const key_type& __x) { /**
return _M_t.equal_range(__x); * @brief A template function that attemps to insert a range of elements.
} * @param first Iterator pointing to the start of the range to be
pair<const_iterator,const_iterator> equal_range(const key_type& __x) const { * inserted.
return _M_t.equal_range(__x); * @param last Iterator pointing to the end of the range.
} *
* Complexity similar to that of the range constructor.
template <class _K1, class _C1, class _A1> */
friend bool operator== (const multiset<_K1,_C1,_A1>&, template <class _InputIterator>
const multiset<_K1,_C1,_A1>&); void
template <class _K1, class _C1, class _A1> insert(_InputIterator __first, _InputIterator __last)
friend bool operator< (const multiset<_K1,_C1,_A1>&, { _M_t.insert_equal(__first, __last); }
const multiset<_K1,_C1,_A1>&);
}; /**
* @brief Erases an element from a %multiset.
* @param position An iterator pointing to the element to be erased.
*
* This function erases an element, pointed to by the given iterator,
* from a %multiset. Note that this function only erases the element,
* and that if the element is itself a pointer, the pointed-to memory is
* not touched in any way. Managing the pointer is the user's
* responsibilty.
*/
void
erase(iterator __position)
{
typedef typename _Rep_type::iterator _Rep_iterator;
_M_t.erase((_Rep_iterator&)__position);
}
/**
* @brief Erases elements according to the provided key.
* @param x Key of element to be erased.
* @return The number of elements erased.
*
* This function erases all elements located by the given key from a
* %multiset.
* Note that this function only erases the element, and that if
* the element is itself a pointer, the pointed-to memory is not touched
* in any way. Managing the pointer is the user's responsibilty.
*/
size_type
erase(const key_type& __x)
{ return _M_t.erase(__x); }
/**
* @brief Erases a [first,last) range of elements from a %multiset.
* @param first Iterator pointing to the start of the range to be
* erased.
* @param last Iterator pointing to the end of the range to be erased.
*
* This function erases a sequence of elements from a %multiset.
* Note that this function only erases the elements, and that if
* the elements themselves are pointers, the pointed-to memory is not
* touched in any way. Managing the pointer is the user's responsibilty.
*/
void
erase(iterator __first, iterator __last)
{
typedef typename _Rep_type::iterator _Rep_iterator;
_M_t.erase((_Rep_iterator&)__first, (_Rep_iterator&)__last);
}
/**
* Erases all elements in a %multiset. Note that this function only
* erases the elements, and that if the elements themselves are pointers,
* the pointed-to memory is not touched in any way. Managing the pointer
* is the user's responsibilty.
*/
void
clear()
{ _M_t.clear(); }
// multiset operations:
/**
* @brief Finds the number of elements with given key.
* @param x Key of elements to be located.
* @return Number of elements with specified key.
*/
size_type
count(const key_type& __x) const
{ return _M_t.count(__x); }
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 214. set::find() missing const overload
//@{
/**
* @brief Tries to locate an element in a %set.
* @param x Element to be located.
* @return Iterator pointing to sought-after element, or end() if not
* found.
*
* This function takes a key and tries to locate the element with which
* the key matches. If successful the function returns an iterator
* pointing to the sought after element. If unsuccessful it returns the
* past-the-end ( @c end() ) iterator.
*/
iterator
find(const key_type& __x)
{ return _M_t.find(__x); }
const_iterator
find(const key_type& __x) const
{ return _M_t.find(__x); }
//@}
//@{
/**
* @brief Finds the beginning of a subsequence matching given key.
* @param x Key to be located.
* @return Iterator pointing to first element equal to or greater
* than key, or end().
*
* This function returns the first element of a subsequence of elements
* that matches the given key. If unsuccessful it returns an iterator
* pointing to the first element that has a greater value than given key
* or end() if no such element exists.
*/
iterator
lower_bound(const key_type& __x)
{ return _M_t.lower_bound(__x); }
const_iterator
lower_bound(const key_type& __x) const
{ return _M_t.lower_bound(__x); }
//@}
//@{
/**
* @brief Finds the end of a subsequence matching given key.
* @param x Key to be located.
* @return Iterator pointing to the first element
* greater than key, or end().
*/
iterator
upper_bound(const key_type& __x)
{ return _M_t.upper_bound(__x); }
const_iterator
upper_bound(const key_type& __x) const
{ return _M_t.upper_bound(__x); }
//@}
//@{
/**
* @brief Finds a subsequence matching given key.
* @param x Key to be located.
* @return Pair of iterators that possibly points to the subsequence
* matching given key.
*
* This function is equivalent to
* @code
* std::make_pair(c.lower_bound(val),
* c.upper_bound(val))
* @endcode
* (but is faster than making the calls separately).
*
* This function probably only makes sense for multisets.
*/
pair<iterator,iterator>
equal_range(const key_type& __x)
{ return _M_t.equal_range(__x); }
pair<const_iterator,const_iterator>
equal_range(const key_type& __x) const
{ return _M_t.equal_range(__x); }
template <class _K1, class _C1, class _A1>
friend bool
operator== (const multiset<_K1,_C1,_A1>&,
const multiset<_K1,_C1,_A1>&);
template <class _K1, class _C1, class _A1>
friend bool
operator< (const multiset<_K1,_C1,_A1>&,
const multiset<_K1,_C1,_A1>&);
};
/** /**
* @brief Multiset equality comparison. * @brief Multiset equality comparison.
...@@ -464,7 +511,8 @@ inline bool operator<(const multiset<_Key,_Compare,_Alloc>& __x, ...@@ -464,7 +511,8 @@ inline bool operator<(const multiset<_Key,_Compare,_Alloc>& __x,
* @param y A %multiset of the same type as @a x. * @param y A %multiset of the same type as @a x.
* @return True iff the size and elements of the multisets are equal. * @return True iff the size and elements of the multisets are equal.
* *
* This is an equivalence relation. It is linear in the size of the multisets. * This is an equivalence relation. It is linear in the size of the
* multisets.
* Multisets are considered equivalent if their sizes are equal, and if * Multisets are considered equivalent if their sizes are equal, and if
* corresponding elements compare equal. * corresponding elements compare equal.
*/ */
...@@ -472,8 +520,8 @@ inline bool operator<(const multiset<_Key,_Compare,_Alloc>& __x, ...@@ -472,8 +520,8 @@ inline bool operator<(const multiset<_Key,_Compare,_Alloc>& __x,
inline bool inline bool
operator==(const multiset<_Key,_Compare,_Alloc>& __x, operator==(const multiset<_Key,_Compare,_Alloc>& __x,
const multiset<_Key,_Compare,_Alloc>& __y) const multiset<_Key,_Compare,_Alloc>& __y)
{ return __x._M_t == __y._M_t; } { return __x._M_t == __y._M_t; }
/** /**
* @brief Multiset ordering relation. * @brief Multiset ordering relation.
* @param x A %multiset. * @param x A %multiset.
...@@ -489,42 +537,42 @@ inline bool operator<(const multiset<_Key,_Compare,_Alloc>& __x, ...@@ -489,42 +537,42 @@ inline bool operator<(const multiset<_Key,_Compare,_Alloc>& __x,
inline bool inline bool
operator<(const multiset<_Key,_Compare,_Alloc>& __x, operator<(const multiset<_Key,_Compare,_Alloc>& __x,
const multiset<_Key,_Compare,_Alloc>& __y) const multiset<_Key,_Compare,_Alloc>& __y)
{ return __x._M_t < __y._M_t; } { return __x._M_t < __y._M_t; }
/// Returns !(x == y). /// Returns !(x == y).
template <class _Key, class _Compare, class _Alloc> template <class _Key, class _Compare, class _Alloc>
inline bool inline bool
operator!=(const multiset<_Key,_Compare,_Alloc>& __x, operator!=(const multiset<_Key,_Compare,_Alloc>& __x,
const multiset<_Key,_Compare,_Alloc>& __y) const multiset<_Key,_Compare,_Alloc>& __y)
{ return !(__x == __y); } { return !(__x == __y); }
/// Returns y < x. /// Returns y < x.
template <class _Key, class _Compare, class _Alloc> template <class _Key, class _Compare, class _Alloc>
inline bool inline bool
operator>(const multiset<_Key,_Compare,_Alloc>& __x, operator>(const multiset<_Key,_Compare,_Alloc>& __x,
const multiset<_Key,_Compare,_Alloc>& __y) const multiset<_Key,_Compare,_Alloc>& __y)
{ return __y < __x; } { return __y < __x; }
/// Returns !(y < x) /// Returns !(y < x)
template <class _Key, class _Compare, class _Alloc> template <class _Key, class _Compare, class _Alloc>
inline bool inline bool
operator<=(const multiset<_Key,_Compare,_Alloc>& __x, operator<=(const multiset<_Key,_Compare,_Alloc>& __x,
const multiset<_Key,_Compare,_Alloc>& __y) const multiset<_Key,_Compare,_Alloc>& __y)
{ return !(__y < __x); } { return !(__y < __x); }
/// Returns !(x < y) /// Returns !(x < y)
template <class _Key, class _Compare, class _Alloc> template <class _Key, class _Compare, class _Alloc>
inline bool inline bool
operator>=(const multiset<_Key,_Compare,_Alloc>& __x, operator>=(const multiset<_Key,_Compare,_Alloc>& __x,
const multiset<_Key,_Compare,_Alloc>& __y) const multiset<_Key,_Compare,_Alloc>& __y)
{ return !(__x < __y); } { return !(__x < __y); }
/// See std::multiset::swap(). /// See std::multiset::swap().
template <class _Key, class _Compare, class _Alloc> template <class _Key, class _Compare, class _Alloc>
inline void inline void
swap(multiset<_Key,_Compare,_Alloc>& __x, swap(multiset<_Key,_Compare,_Alloc>& __x,
multiset<_Key,_Compare,_Alloc>& __y) multiset<_Key,_Compare,_Alloc>& __y)
{ __x.swap(__y); } { __x.swap(__y); }
} // namespace __gnu_norm } // namespace __gnu_norm
......
// std::rel_ops implementation -*- C++ -*- // std::rel_ops implementation -*- C++ -*-
// Copyright (C) 2001, 2002 Free Software Foundation, Inc. // Copyright (C) 2001, 2002, 2004 Free Software Foundation, Inc.
// //
// This file is part of the GNU ISO C++ Library. This library is free // This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the // software; you can redistribute it and/or modify it under the
...@@ -75,61 +75,61 @@ namespace std ...@@ -75,61 +75,61 @@ namespace std
{ {
namespace rel_ops namespace rel_ops
{ {
/** @namespace std::rel_ops /** @namespace std::rel_ops
* @brief The generated relational operators are sequestered here. * @brief The generated relational operators are sequestered here.
*/ */
/**
* @brief Defines @c != for arbitrary types, in terms of @c ==.
* @param x A thing.
* @param y Another thing.
* @return x != y
*
* This function uses @c == to determine its result.
*/
template <class _Tp>
inline bool
operator!=(const _Tp& __x, const _Tp& __y)
{ return !(__x == __y); }
/** /**
* @brief Defines @c != for arbitrary types, in terms of @c ==. * @brief Defines @c > for arbitrary types, in terms of @c <.
* @param x A thing. * @param x A thing.
* @param y Another thing. * @param y Another thing.
* @return x != y * @return x > y
* *
* This function uses @c == to determine its result. * This function uses @c < to determine its result.
*/ */
template <class _Tp> template <class _Tp>
inline bool operator!=(const _Tp& __x, const _Tp& __y) { inline bool
return !(__x == __y); operator>(const _Tp& __x, const _Tp& __y)
} { return __y < __x; }
/** /**
* @brief Defines @c > for arbitrary types, in terms of @c <. * @brief Defines @c <= for arbitrary types, in terms of @c <.
* @param x A thing. * @param x A thing.
* @param y Another thing. * @param y Another thing.
* @return x > y * @return x <= y
* *
* This function uses @c < to determine its result. * This function uses @c < to determine its result.
*/ */
template <class _Tp> template <class _Tp>
inline bool operator>(const _Tp& __x, const _Tp& __y) { inline bool
return __y < __x; operator<=(const _Tp& __x, const _Tp& __y)
} { return !(__y < __x); }
/** /**
* @brief Defines @c <= for arbitrary types, in terms of @c <. * @brief Defines @c >= for arbitrary types, in terms of @c <.
* @param x A thing. * @param x A thing.
* @param y Another thing. * @param y Another thing.
* @return x <= y * @return x >= y
* *
* This function uses @c < to determine its result. * This function uses @c < to determine its result.
*/ */
template <class _Tp> template <class _Tp>
inline bool operator<=(const _Tp& __x, const _Tp& __y) { inline bool
return !(__y < __x); operator>=(const _Tp& __x, const _Tp& __y)
} { return !(__x < __y); }
/**
* @brief Defines @c >= for arbitrary types, in terms of @c <.
* @param x A thing.
* @param y Another thing.
* @return x >= y
*
* This function uses @c < to determine its result.
*/
template <class _Tp>
inline bool operator>=(const _Tp& __x, const _Tp& __y) {
return !(__x < __y);
}
} // namespace rel_ops } // namespace rel_ops
} // namespace std } // namespace std
......
...@@ -108,7 +108,8 @@ namespace __gnu_norm ...@@ -108,7 +108,8 @@ namespace __gnu_norm
{ {
// concept requirements // concept requirements
__glibcxx_class_requires(_Key, _SGIAssignableConcept) __glibcxx_class_requires(_Key, _SGIAssignableConcept)
__glibcxx_class_requires4(_Compare, bool, _Key, _Key, _BinaryFunctionConcept) __glibcxx_class_requires4(_Compare, bool, _Key, _Key,
_BinaryFunctionConcept)
public: public:
// typedefs: // typedefs:
...@@ -142,7 +143,8 @@ namespace __gnu_norm ...@@ -142,7 +143,8 @@ namespace __gnu_norm
// allocation/deallocation // allocation/deallocation
/// Default constructor creates no elements. /// Default constructor creates no elements.
set() : _M_t(_Compare(), allocator_type()) {} set()
: _M_t(_Compare(), allocator_type()) {}
/** /**
* @brief Default constructor creates no elements. * @brief Default constructor creates no elements.
...@@ -152,7 +154,7 @@ namespace __gnu_norm ...@@ -152,7 +154,7 @@ namespace __gnu_norm
*/ */
explicit set(const _Compare& __comp, explicit set(const _Compare& __comp,
const allocator_type& __a = allocator_type()) const allocator_type& __a = allocator_type())
: _M_t(__comp, __a) {} : _M_t(__comp, __a) {}
/** /**
* @brief Builds a %set from a range. * @brief Builds a %set from a range.
...@@ -164,9 +166,9 @@ namespace __gnu_norm ...@@ -164,9 +166,9 @@ namespace __gnu_norm
* otherwise (where N is distance(first,last)). * otherwise (where N is distance(first,last)).
*/ */
template<class _InputIterator> template<class _InputIterator>
set(_InputIterator __first, _InputIterator __last) set(_InputIterator __first, _InputIterator __last)
: _M_t(_Compare(), allocator_type()) : _M_t(_Compare(), allocator_type())
{ _M_t.insert_unique(__first, __last); } { _M_t.insert_unique(__first, __last); }
/** /**
* @brief Builds a %set from a range. * @brief Builds a %set from a range.
...@@ -180,10 +182,11 @@ namespace __gnu_norm ...@@ -180,10 +182,11 @@ namespace __gnu_norm
* otherwise (where N is distance(first,last)). * otherwise (where N is distance(first,last)).
*/ */
template<class _InputIterator> template<class _InputIterator>
set(_InputIterator __first, _InputIterator __last, const _Compare& __comp, set(_InputIterator __first, _InputIterator __last,
const allocator_type& __a = allocator_type()) const _Compare& __comp,
const allocator_type& __a = allocator_type())
: _M_t(__comp, __a) : _M_t(__comp, __a)
{ _M_t.insert_unique(__first, __last); } { _M_t.insert_unique(__first, __last); }
/** /**
* @brief Set copy constructor. * @brief Set copy constructor.
...@@ -192,7 +195,8 @@ namespace __gnu_norm ...@@ -192,7 +195,8 @@ namespace __gnu_norm
* The newly-created %set uses a copy of the allocation object used * The newly-created %set uses a copy of the allocation object used
* by @a x. * by @a x.
*/ */
set(const set<_Key,_Compare,_Alloc>& __x) : _M_t(__x._M_t) {} set(const set<_Key,_Compare,_Alloc>& __x)
: _M_t(__x._M_t) { }
/** /**
* @brief Set assignment operator. * @brief Set assignment operator.
...@@ -201,7 +205,8 @@ namespace __gnu_norm ...@@ -201,7 +205,8 @@ namespace __gnu_norm
* All the elements of @a x are copied, but unlike the copy constructor, * All the elements of @a x are copied, but unlike the copy constructor,
* the allocator object is not copied. * the allocator object is not copied.
*/ */
set<_Key,_Compare,_Alloc>& operator=(const set<_Key, _Compare, _Alloc>& __x) set<_Key,_Compare,_Alloc>&
operator=(const set<_Key, _Compare, _Alloc>& __x)
{ {
_M_t = __x._M_t; _M_t = __x._M_t;
return *this; return *this;
...@@ -210,45 +215,66 @@ namespace __gnu_norm ...@@ -210,45 +215,66 @@ namespace __gnu_norm
// accessors: // accessors:
/// Returns the comparison object with which the %set was constructed. /// Returns the comparison object with which the %set was constructed.
key_compare key_comp() const { return _M_t.key_comp(); } key_compare
key_comp() const
{ return _M_t.key_comp(); }
/// Returns the comparison object with which the %set was constructed. /// Returns the comparison object with which the %set was constructed.
value_compare value_comp() const { return _M_t.key_comp(); } value_compare
value_comp() const
{ return _M_t.key_comp(); }
/// Returns the allocator object with which the %set was constructed. /// Returns the allocator object with which the %set was constructed.
allocator_type get_allocator() const { return _M_t.get_allocator(); } allocator_type
get_allocator() const
{ return _M_t.get_allocator(); }
/** /**
* Returns a read/write iterator that points to the first element in the * Returns a read/write iterator that points to the first element in the
* %set. Iteration is done in ascending order according to the keys. * %set. Iteration is done in ascending order according to the keys.
*/ */
iterator begin() const { return _M_t.begin(); } iterator
begin() const
{ return _M_t.begin(); }
/** /**
* Returns a read/write iterator that points one past the last element in * Returns a read/write iterator that points one past the last element in
* the %set. Iteration is done in ascending order according to the keys. * the %set. Iteration is done in ascending order according to the keys.
*/ */
iterator end() const { return _M_t.end(); } iterator
end() const
{ return _M_t.end(); }
/** /**
* Returns a read/write reverse iterator that points to the last element in * Returns a read/write reverse iterator that points to the last element
* the %set. Iteration is done in descending order according to the keys. * in the %set. Iteration is done in descending order according to the
* keys.
*/ */
reverse_iterator rbegin() const { return _M_t.rbegin(); } reverse_iterator
rbegin() const
{ return _M_t.rbegin(); }
/** /**
* Returns a read-only (constant) reverse iterator that points to the last * Returns a read-only (constant) reverse iterator that points to the
* pair in the %map. Iteration is done in descending order according to * last pair in the %map. Iteration is done in descending order
* the keys. * according to the keys.
*/ */
reverse_iterator rend() const { return _M_t.rend(); } reverse_iterator
rend() const
{ return _M_t.rend(); }
/// Returns true if the %set is empty. /// Returns true if the %set is empty.
bool empty() const { return _M_t.empty(); } bool
empty() const
{ return _M_t.empty(); }
/// Returns the size of the %set. /// Returns the size of the %set.
size_type size() const { return _M_t.size(); } size_type
size() const
{ return _M_t.size(); }
/// Returns the maximum size of the %set. /// Returns the maximum size of the %set.
size_type max_size() const { return _M_t.max_size(); } size_type
max_size() const
{ return _M_t.max_size(); }
/** /**
* @brief Swaps data with another %set. * @brief Swaps data with another %set.
...@@ -261,15 +287,17 @@ namespace __gnu_norm ...@@ -261,15 +287,17 @@ namespace __gnu_norm
* Note that the global std::swap() function is specialized such that * Note that the global std::swap() function is specialized such that
* std::swap(s1,s2) will feed to this function. * std::swap(s1,s2) will feed to this function.
*/ */
void swap(set<_Key,_Compare,_Alloc>& __x) { _M_t.swap(__x._M_t); } void
swap(set<_Key,_Compare,_Alloc>& __x)
{ _M_t.swap(__x._M_t); }
// insert/erase // insert/erase
/** /**
* @brief Attempts to insert an element into the %set. * @brief Attempts to insert an element into the %set.
* @param x Element to be inserted. * @param x Element to be inserted.
* @return A pair, of which the first element is an iterator that points * @return A pair, of which the first element is an iterator that points
* to the possibly inserted element, and the second is a bool that * to the possibly inserted element, and the second is a bool
* is true if the element was actually inserted. * that is true if the element was actually inserted.
* *
* This function attempts to insert an element into the %set. A %set * This function attempts to insert an element into the %set. A %set
* relies on unique keys and thus an element is only inserted if it is * relies on unique keys and thus an element is only inserted if it is
...@@ -277,9 +305,10 @@ namespace __gnu_norm ...@@ -277,9 +305,10 @@ namespace __gnu_norm
* *
* Insertion requires logarithmic time. * Insertion requires logarithmic time.
*/ */
pair<iterator,bool> insert(const value_type& __x) pair<iterator,bool>
insert(const value_type& __x)
{ {
pair<typename _Rep_type::iterator, bool> __p = _M_t.insert_unique(__x); pair<typename _Rep_type::iterator, bool> __p = _M_t.insert_unique(__x);
return pair<iterator, bool>(__p.first, __p.second); return pair<iterator, bool>(__p.first, __p.second);
} }
...@@ -302,7 +331,8 @@ namespace __gnu_norm ...@@ -302,7 +331,8 @@ namespace __gnu_norm
* *
* Insertion requires logarithmic time (if the hint is not taken). * Insertion requires logarithmic time (if the hint is not taken).
*/ */
iterator insert(iterator __position, const value_type& __x) iterator
insert(iterator __position, const value_type& __x)
{ {
typedef typename _Rep_type::iterator _Rep_iterator; typedef typename _Rep_type::iterator _Rep_iterator;
return _M_t.insert_unique((_Rep_iterator&)__position, __x); return _M_t.insert_unique((_Rep_iterator&)__position, __x);
...@@ -317,7 +347,8 @@ namespace __gnu_norm ...@@ -317,7 +347,8 @@ namespace __gnu_norm
* Complexity similar to that of the range constructor. * Complexity similar to that of the range constructor.
*/ */
template<class _InputIterator> template<class _InputIterator>
void insert(_InputIterator __first, _InputIterator __last) void
insert(_InputIterator __first, _InputIterator __last)
{ _M_t.insert_unique(__first, __last); } { _M_t.insert_unique(__first, __last); }
/** /**
...@@ -329,7 +360,8 @@ namespace __gnu_norm ...@@ -329,7 +360,8 @@ namespace __gnu_norm
* that if the element is itself a pointer, the pointed-to memory is not * that if the element is itself a pointer, the pointed-to memory is not
* touched in any way. Managing the pointer is the user's responsibilty. * touched in any way. Managing the pointer is the user's responsibilty.
*/ */
void erase(iterator __position) void
erase(iterator __position)
{ {
typedef typename _Rep_type::iterator _Rep_iterator; typedef typename _Rep_type::iterator _Rep_iterator;
_M_t.erase((_Rep_iterator&)__position); _M_t.erase((_Rep_iterator&)__position);
...@@ -346,11 +378,13 @@ namespace __gnu_norm ...@@ -346,11 +378,13 @@ namespace __gnu_norm
* the element is itself a pointer, the pointed-to memory is not touched * the element is itself a pointer, the pointed-to memory is not touched
* in any way. Managing the pointer is the user's responsibilty. * in any way. Managing the pointer is the user's responsibilty.
*/ */
size_type erase(const key_type& __x) { return _M_t.erase(__x); } size_type
erase(const key_type& __x) { return _M_t.erase(__x); }
/** /**
* @brief Erases a [first,last) range of elements from a %set. * @brief Erases a [first,last) range of elements from a %set.
* @param first Iterator pointing to the start of the range to be erased. * @param first Iterator pointing to the start of the range to be
* erased.
* @param last Iterator pointing to the end of the range to be erased. * @param last Iterator pointing to the end of the range to be erased.
* *
* This function erases a sequence of elements from a %set. * This function erases a sequence of elements from a %set.
...@@ -358,7 +392,8 @@ namespace __gnu_norm ...@@ -358,7 +392,8 @@ namespace __gnu_norm
* the element is itself a pointer, the pointed-to memory is not touched * the element is itself a pointer, the pointed-to memory is not touched
* in any way. Managing the pointer is the user's responsibilty. * in any way. Managing the pointer is the user's responsibilty.
*/ */
void erase(iterator __first, iterator __last) void
erase(iterator __first, iterator __last)
{ {
typedef typename _Rep_type::iterator _Rep_iterator; typedef typename _Rep_type::iterator _Rep_iterator;
_M_t.erase((_Rep_iterator&)__first, (_Rep_iterator&)__last); _M_t.erase((_Rep_iterator&)__first, (_Rep_iterator&)__last);
...@@ -370,7 +405,9 @@ namespace __gnu_norm ...@@ -370,7 +405,9 @@ namespace __gnu_norm
* pointed-to memory is not touched in any way. Managing the pointer is * pointed-to memory is not touched in any way. Managing the pointer is
* the user's responsibilty. * the user's responsibilty.
*/ */
void clear() { _M_t.clear(); } void
clear()
{ _M_t.clear(); }
// set operations: // set operations:
...@@ -382,7 +419,8 @@ namespace __gnu_norm ...@@ -382,7 +419,8 @@ namespace __gnu_norm
* This function only makes sense for multisets; for set the result will * This function only makes sense for multisets; for set the result will
* either be 0 (not present) or 1 (present). * either be 0 (not present) or 1 (present).
*/ */
size_type count(const key_type& __x) const size_type
count(const key_type& __x) const
{ return _M_t.find(__x) == _M_t.end() ? 0 : 1; } { return _M_t.find(__x) == _M_t.end() ? 0 : 1; }
// _GLIBCXX_RESOLVE_LIB_DEFECTS // _GLIBCXX_RESOLVE_LIB_DEFECTS
...@@ -399,8 +437,13 @@ namespace __gnu_norm ...@@ -399,8 +437,13 @@ namespace __gnu_norm
* pointing to the sought after element. If unsuccessful it returns the * pointing to the sought after element. If unsuccessful it returns the
* past-the-end ( @c end() ) iterator. * past-the-end ( @c end() ) iterator.
*/ */
iterator find(const key_type& __x) { return _M_t.find(__x); } iterator
const_iterator find(const key_type& __x) const { return _M_t.find(__x); } find(const key_type& __x)
{ return _M_t.find(__x); }
const_iterator
find(const key_type& __x) const
{ return _M_t.find(__x); }
//@} //@}
//@{ //@{
...@@ -415,9 +458,12 @@ namespace __gnu_norm ...@@ -415,9 +458,12 @@ namespace __gnu_norm
* pointing to the first element that has a greater value than given key * pointing to the first element that has a greater value than given key
* or end() if no such element exists. * or end() if no such element exists.
*/ */
iterator lower_bound(const key_type& __x) iterator
lower_bound(const key_type& __x)
{ return _M_t.lower_bound(__x); } { return _M_t.lower_bound(__x); }
const_iterator lower_bound(const key_type& __x) const
const_iterator
lower_bound(const key_type& __x) const
{ return _M_t.lower_bound(__x); } { return _M_t.lower_bound(__x); }
//@} //@}
...@@ -428,9 +474,12 @@ namespace __gnu_norm ...@@ -428,9 +474,12 @@ namespace __gnu_norm
* @return Iterator pointing to the first element * @return Iterator pointing to the first element
* greater than key, or end(). * greater than key, or end().
*/ */
iterator upper_bound(const key_type& __x) iterator
upper_bound(const key_type& __x)
{ return _M_t.upper_bound(__x); } { return _M_t.upper_bound(__x); }
const_iterator upper_bound(const key_type& __x) const
const_iterator
upper_bound(const key_type& __x) const
{ return _M_t.upper_bound(__x); } { return _M_t.upper_bound(__x); }
//@} //@}
...@@ -450,16 +499,22 @@ namespace __gnu_norm ...@@ -450,16 +499,22 @@ namespace __gnu_norm
* *
* This function probably only makes sense for multisets. * This function probably only makes sense for multisets.
*/ */
pair<iterator,iterator> equal_range(const key_type& __x) pair<iterator,iterator>
equal_range(const key_type& __x)
{ return _M_t.equal_range(__x); } { return _M_t.equal_range(__x); }
pair<const_iterator,const_iterator> equal_range(const key_type& __x) const
pair<const_iterator,const_iterator>
equal_range(const key_type& __x) const
{ return _M_t.equal_range(__x); } { return _M_t.equal_range(__x); }
//@} //@}
template<class _K1, class _C1, class _A1> template<class _K1, class _C1, class _A1>
friend bool operator== (const set<_K1,_C1,_A1>&, const set<_K1,_C1,_A1>&); friend bool
operator== (const set<_K1,_C1,_A1>&, const set<_K1,_C1,_A1>&);
template<class _K1, class _C1, class _A1> template<class _K1, class _C1, class _A1>
friend bool operator< (const set<_K1,_C1,_A1>&, const set<_K1,_C1,_A1>&); friend bool
operator< (const set<_K1,_C1,_A1>&, const set<_K1,_C1,_A1>&);
}; };
...@@ -508,8 +563,7 @@ namespace __gnu_norm ...@@ -508,8 +563,7 @@ namespace __gnu_norm
inline bool inline bool
operator>(const set<_Key,_Compare,_Alloc>& __x, operator>(const set<_Key,_Compare,_Alloc>& __x,
const set<_Key,_Compare,_Alloc>& __y) const set<_Key,_Compare,_Alloc>& __y)
{ return __y < __x; } { return __y < __x; }
/// Returns !(y < x) /// Returns !(y < x)
template<class _Key, class _Compare, class _Alloc> template<class _Key, class _Compare, class _Alloc>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment