se_iterator(end()); } /** * Returns a read/write reverse iterator that points to one * before the first element in the %list. Iteration is done in * reverse element order. */ reverse_iterator rend() { return reverse_iterator(begin()); } /** * Returns a read-only (constant) reverse iterator that points to one * before the first element in the %list. Iteration is done in reverse * element order. */ const_reverse_iterator rend() const { return const_reverse_iterator(begin()); } #ifdef __GXX_EXPERIMENTAL_CXX0X__ /** * Returns a read-only (constant) iterator that points to the * first element in the %list. Iteration is done in ordinary * element order. */ const_iterator cbegin() const { return const_iterator(this->_M_impl._M_node._M_next); } /** * Returns a read-only (constant) iterator that points one past * the last element in the %list. Iteration is done in ordinary * element order. */ const_iterator cend() const { return const_iterator(&this->_M_impl._M_node); } /** * Returns a read-only (constant) reverse iterator that points to * the last element in the %list. Iteration is done in reverse * element order. */ const_reverse_iterator crbegin() const { return const_reverse_iterator(end()); } /** * Returns a read-only (constant) reverse iterator that points to one * before the first element in the %list. Iteration is done in reverse * element order. */ const_reverse_iterator crend() const { return const_reverse_iterator(begin()); } #endif // [23.2.2.2] capacity /** * Returns true if the %list is empty. (Thus begin() would equal * end().) */ bool empty() const { return this->_M_impl._M_node._M_next == &this->_M_impl._M_node; } /** Returns the number of elements in the %list. */ size_type size() const { return std::distance(begin(), end()); } /** Returns the size() of the largest possible %list. */ size_type max_size() const { return _M_get_Tp_allocator().max_size(); } /** * @brief Resizes the %list to the specified number of elements. * @param new_size Number of elements the %list should contain. * @param x Data with which new elements should be populated. * * This function will %resize the %list to the specified number * of elements. If the number is smaller than the %list's * current size the %list is truncated, otherwise the %list is * extended and new elements are populated with given data. */ void resize(size_type __new_size, value_type __x = value_type()); // element access /** * Returns a read/write reference to the data at the first * element of the %list. */ reference front() { return *begin(); } /** * Returns a read-only (constant) reference to the data at the first * element of the %list. */ const_reference front() const { return *begin(); } /** * Returns a read/write reference to the data at the last element * of the %list. */ reference back() { iterator __tmp = end(); --__tmp; return *__tmp; } /** * Returns a read-only (constant) reference to the data at the last * element of the %list. */ const_reference back() const { const_iterator __tmp = end(); --__tmp; return *__tmp; } // [23.2.2.3] modifiers /** * @brief Add data to the front of the %list. * @param x Data to be added. * * This is a typical stack operation. The function creates an * element at the front of the %list and assigns the given data * to it. Due to the nature of a %list this operation can be * done in constant time, and does not invalidate iterators and * references. */ #ifndef __GXX_EXPERIMENTAL_CXX0X__ void push_front(const value_type& __x) { this->_M_insert(begin(), __x); } #else template void push_front(_Args&&... __args) { this->_M_insert(begin(), std::forward<_Args>(__args)...); } #endif /** * @brief Removes first element. * * This is a typical stack operation. It shrinks the %list by * one. Due to the nature of a %list this operation can be done * in constant time, and only invalidates iterators/references to * the element being removed. * * 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 pop_front() { this->_M_erase(begin()); } /** * @brief Add data to the end of the %list. * @param x Data to be added. * * This is a typical stack operation. The function creates an * element at the end of the %list and assigns the given data to * it. Due to the nature of a %list this operation can be done * in constant time, and does not invalidate iterators and * references. */ #ifndef __GXX_EXPERIMENTAL_CXX0X__ void push_back(const value_type& __x) { this->_M_insert(end(), __x); } #else template void push_back(_Args&&... __args) { this->_M_insert(end(), std::forward<_Args>(__args)...); } #endif /** * @brief Removes last element. * * This is a typical stack operation. It shrinks the %list by * one. Due to the nature of a %list this operation can be done * in constant time, and only invalidates iterators/references to * the element being removed. * * Note that no data is returned, and if the last element's data * is needed, it should be retrieved before pop_back() is called. */ void pop_back() { this->_M_erase(iterator(this->_M_impl._M_node._M_prev)); } #ifdef __GXX_EXPERIMENTAL_CXX0X__ /** * @brief Constructs object in %list before specified iterator. * @param position A const_iterator into the %list. * @param args Arguments. * @return An iterator that points to the inserted data. * * This function will insert an object of type T constructed * with T(std::forward(args)...) before the specified * location. Due to the nature of a %list this operation can * be done in constant time, and does not invalidate iterators * and references. */ template iterator emplace(iterator __position, _Args&&... __args); #endif /** * @brief Inserts given value into %list before specified iterator. * @param position An iterator into the %list. * @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. Due to the nature of a %list this * operation can be done in constant time, and does not * invalidate iterators and references. */ iterator insert(iterator __position, const value_type& __x); #ifdef __GXX_EXPERIMENTAL_CXX0X__ /** * @brief Inserts given rvalue into %list before specified iterator. * @param position An iterator into the %list. * @param x Data to be inserted. * @return An iterator that points to the inserted data. * * This function will insert a copy of the given rvalue before * the specified location. Due to the nature of a %list this * operation can be done in constant time, and does not * invalidate iterators and references. */ iterator insert(iterator __position, value_type&& __x) { return emplace(__position, std::move(__x)); } #endif /** * @brief Inserts a number of copies of given data into the %list. * @param position An iterator into the %list. * @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. * * This operation is linear in the number of elements inserted and * does not invalidate iterators and references. */ void insert(iterator __position, size_type __n, const value_type& __x) { list __tmp(__n, __x, _M_get_Node_allocator()); splice(__position, __tmp); } /** * @brief Inserts a range into the %list. * @param position An iterator into the %list. * @param first An input iterator. * @param last An input iterator. * * This function will insert copies of the data in the range [@a * first,@a last) into the %list before the location specified by * @a position. * * This operation is linear in the number of elements inserted and * does not invalidate iterators and references. */ template void insert(iterator __position, _InputIterator __first, _InputIterator __last) { list __tmp(__first, __last, _M_get_Node_allocator()); splice(__position, __tmp); } /** * @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 %list by one. * * Due to the nature of a %list this operation can be done in * constant time, and only invalidates iterators/references to * the element being removed. The user is also 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 responsibility. */ 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 @a * [first,last) and shorten the %list accordingly. * * This operation is linear time in the size of the range and only * invalidates iterators/references to the element being removed. * The user is also 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 responsibility. */ iterator erase(iterator __first, iterator __last) { while (__first != __last) __first = erase(__first); return __last; } /** * @brief Swaps data with another %list. * @param x A %list of the same element and allocator types. * * This exchanges the elements between two lists in constant * time. Note that the global std::swap() function is * specialized such that std::swap(l1,l2) will feed to this * function. */ void #ifdef __GXX_EXPERIMENTAL_CXX0X__ swap(list&& __x) #else swap(list& __x) #endif { _List_node_base::swap(this->_M_impl._M_node, __x._M_impl._M_node); // _GLIBCXX_RESOLVE_LIB_DEFECTS // 431. Swapping containers with unequal allocators. std::__alloc_swap:: _S_do_it(_M_get_Node_allocator(), __x._M_get_Node_allocator()); } /** * 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 responsibility. */ void clear() { _Base::_M_clear(); _Base::_M_init(); } // [23.2.2.4] list operations /** * @brief Insert contents of another %list. * @param position Iterator referencing the element to insert before. * @param x Source list. * * The elements of @a x are inserted in constant time in front of * the element referenced by @a position. @a x becomes an empty * list. * * Requires this != @a x. */ void #ifdef __GXX_EXPERIMENTAL_CXX0X__ splice(iterator __position, list&& __x) #else splice(iterator __position, list& __x) #endif { if (!__x.empty()) { _M_check_equal_allocators(__x); this->_M_transfer(__position, __x.begin(), __x.end()); } } /** * @brief Insert element from another %list. * @param position Iterator referencing the element to insert before. * @param x Source list. * @param i Iterator referencing the element to move. * * Removes the element in list @a x referenced by @a i and * inserts it into the current list before @a position. */ void #ifdef __GXX_EXPERIMENTAL_CXX0X__ splice(iterator __position, list&& __x, iterator __i) #else splice(iterator __position, list& __x, iterator __i) #endif { iterator __j = __i; ++__j; if (__position == __i || __position == __j) return; if (this != &__x) _M_check_equal_allocators(__x); this->_M_transfer(__position, __i, __j); } /** * @brief Insert range from another %list. * @param position Iterator referencing the element to insert before. * @param x Source list. * @param first Iterator referencing the start of range in x. * @param last Iterator referencing the end of range in x. * * Removes elements in the range [first,last) and inserts them * before @a position in constant time. * * Undefined if @a position is in [first,last). */ void #ifdef __GXX_EXPERIMENTAL_CXX0X__ splice(iterator __position, list&& __x, iterator __first, iterator __last) #else splice(iterator __position, list& __x, iterator __first, iterator __last) #endif { if (__first != __last) { if (this != &__x) _M_check_equal_allocators(__x); this->_M_transfer(__position, __first, __last); } } /** * @brief Remove all elements equal to value. * @param value The value to remove. * * Removes every element in the list equal to @a value. * Remaining elements stay in list order. 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 * responsibility. */ void remove(const _Tp& __value); /** * @brief Remove all elements satisfying a predicate. * @param Predicate Unary predicate function or object. * * Removes every element in the list for which the predicate * returns true. Remaining elements stay in list order. 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 * responsibility. */ template void remove_if(_Predicate); /** * @brief Remove consecutive duplicate elements. * * For each consecutive set of elements with the same value, * remove all but the first one. Remaining elements stay in * list order. 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 responsibility. */ void unique(); /** * @brief Remove consecutive elements satisfying a predicate. * @param BinaryPredicate Binary predicate function or object. * * For each consecutive set of elements [first,last) that * satisfy predicate(first,i) where i is an iterator in * [first,last), remove all but the first one. Remaining * elements stay in list order. 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 responsibility. */ template void unique(_BinaryPredicate); /** * @brief Merge sorted lists. * @param x Sorted list to merge. * * Assumes that both @a x and this list are sorted according to * operator<(). Merges elements of @a x into this list in * sorted order, leaving @a x empty when complete. Elements in * this list precede elements in @a x that are equal. */ void #ifdef __GXX_EXPERIMENTAL_CXX0X__ merge(list&& __x); #else merge(list& __x); #endif /** * @brief Merge sorted lists according to comparison function. * @param x Sorted list to merge. * @param StrictWeakOrdering Comparison function defining * sort order. * * Assumes that both @a x and this list are sorted according to * StrictWeakOrdering. Merges elements of @a x into this list * in sorted order, leaving @a x empty when complete. Elements * in this list precede elements in @a x that are equivalent * according to StrictWeakOrdering(). */ template void #ifdef __GXX_EXPERIMENTAL_CXX0X__ merge(list&&, _StrictWeakOrdering); #else merge(list&, _StrictWeakOrdering); #endif /** * @brief Reverse the elements in list. * * Reverse the order of elements in the list in linear time. */ void reverse() { this->_M_impl._M_node.reverse(); } /** * @brief Sort the elements. * * Sorts the elements of this list in NlogN time. Equivalent * elements remain in list order. */ void sort(); /** * @brief Sort the elements according to comparison function. * * Sorts the elements of this list in NlogN time. Equivalent * elements remain in list order. */ template void sort(_StrictWeakOrdering); protected: // Internal constructor functions follow. // Called by the range constructor to implement [23.1.1]/9 // _GLIBCXX_RESOLVE_LIB_DEFECTS // 438. Ambiguity in the "do the right thing" clause template void _M_initialize_dispatch(_Integer __n, _Integer __x, __true_type) { _M_fill_initialize(static_cast(__n), __x); } // Called by the range constructor to implement [23.1.1]/9 template void _M_initialize_dispatch(_InputIterator __first, _InputIterator __last, __false_type) { for (; __first != __last; ++__first) push_back(*__first); } // Called by list(n,v,a), and the range constructor when it turns out // to be the same thing. void _M_fill_initialize(size_type __n, const value_type& __x) { for (; __n > 0; --__n) push_back(__x); } // Internal assign functions follow. // Called by the range assign to implement [23.1.1]/9 // _GLIBCXX_RESOLVE_LIB_DEFECTS // 438. Ambiguity in the "do the right thing" clause template void _M_assign_dispatch(_Integer __n, _Integer __val, __true_type) { _M_fill_assign(__n, __val); } // Called by the range assign to implement [23.1.1]/9 template void _M_assign_dispatch(_InputIterator __first, _InputIterator __last, __false_type); // 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); // Moves the elements from [first,last) before position. void _M_transfer(iterator __position, iterator __first, iterator __last) { __position._M_node->transfer(__first._M_node, __last._M_node); } // Inserts new element at position given and with value given. #ifndef __GXX_EXPERIMENTAL_CXX0X__ void _M_insert(iterator __position, const value_type& __x) { _Node* __tmp = _M_create_node(__x); __tmp->hook(__position._M_node); } #else template void _M_insert(iterator __position, _Args&&... __args) { _Node* __tmp = _M_create_node(std::forward<_Args>(__args)...); __tmp->hook(__position._M_node); } #endif // Erases element at position given. void _M_erase(iterator __position) { __position._M_node->unhook(); _Node* __n = static_cast<_Node*>(__position._M_node); _M_get_Tp_allocator().destroy(&__n->_M_data); _M_put_node(__n); } // To implement the splice (and merge) bits of N1599. void _M_check_equal_allocators(list& __x) { if (std::__alloc_neq:: _S_do_it(_M_get_Node_allocator(), __x._M_get_Node_allocator())) __throw_runtime_error(__N("list::_M_check_equal_allocators")); } }; /** * @brief List equality comparison. * @param x A %list. * @param y A %list of the same type as @a x. * @return True iff the size and elements of the lists are equal. * * This is an equivalence relation. It is linear in the size of * the lists. Lists are considered equivalent if their sizes are * equal, and if corresponding elements compare equal. */ template inline bool operator==(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) { typedef typename list<_Tp, _Alloc>::const_iterator const_iterator; const_iterator __end1 = __x.end(); const_iterator __end2 = __y.end(); const_iterator __i1 = __x.begin(); const_iterator __i2 = __y.begin(); while (__i1 != __end1 && __i2 != __end2 && *__i1 == *__i2) { ++__i1; ++__i2; } return __i1 == __end1 && __i2 == __end2; } /** * @brief List ordering relation. * @param x A %list. * @param y A %list of the same type as @a x. * @return True iff @a x is lexicographically less than @a y. * * This is a total ordering relation. It is linear in the size of the * lists. The elements must be comparable with @c <. * * See std::lexicographical_compare() for how the determination is made. */ template inline bool operator<(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) { return std::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end()); } /// Based on operator== template inline bool operator!=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) { return !(__x == __y); } /// Based on operator< template inline bool operator>(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) { return __y < __x; } /// Based on operator< template inline bool operator<=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) { return !(__y < __x); } /// Based on operator< template inline bool operator>=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) { return !(__x < __y); } /// See std::list::swap(). template inline void swap(list<_Tp, _Alloc>& __x, list<_Tp, _Alloc>& __y) { __x.swap(__y); } #ifdef __GXX_EXPERIMENTAL_CXX0X__ template inline void swap(list<_Tp, _Alloc>&& __x, list<_Tp, _Alloc>& __y) { __x.swap(__y); } template inline void swap(list<_Tp, _Alloc>& __x, list<_Tp, _Alloc>&& __y) { __x.swap(__y); } #endif _GLIBCXX_END_NESTED_NAMESPACE #endif /* _STL_LIST_H */ // Map implementation -*- C++ -*- // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 // Free Software Foundation, Inc. // // 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 // terms of the GNU General Public License as published by the // Free Software Foundation; either version 2, or (at your option) // any later version. // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License along // with this library; see the file COPYING. If not, write to the Free // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, // USA. // As a special exception, you may use this file as part of a free software // library without restriction. Specifically, if other files instantiate // templates or use macros or inline functions from this file, or you compile // this file and link it with other files to produce an executable, this // file does not by itself cause the resulting executable to be covered by // the GNU General Public License. This exception does not however // invalidate any other reasons why the executable file might be covered by // the GNU General Public License. /* * * Copyright (c) 1994 * Hewlett-Packard Company * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, * provided that the above copyright notice appear in all copies and * that both that copyright notice and this permission notice appear * in supporting documentation. Hewlett-Packard Company makes no * representations about the suitability of this software for any * purpose. It is provided "as is" without express or implied warranty. * * * Copyright (c) 1996,1997 * Silicon Graphics Computer Systems, Inc. * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, * provided that the above copyright notice appear in all copies and * that both that copyright notice and this permission notice appear * in supporting documentation. Silicon Graphics makes no * representations about the suitability of this software for any * purpose. It is provided "as is" without express or implied warranty. */ /** @file stl_map.h * This is an internal header file, included by other library headers. * You should not attempt to use it directly. */ #ifndef _STL_MAP_H #define _STL_MAP_H 1 #include #include _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D) /** * @brief A standard container made up of (key,value) pairs, which can be * retrieved based on a key, in logarithmic time. * * @ingroup Containers * @ingroup Assoc_containers * * Meets the requirements of a container, a * reversible container, and an * associative container (using unique keys). * For a @c map the key_type is Key, the mapped_type is T, and the * value_type is std::pair. * * Maps support bidirectional iterators. * * The private tree data is declared exactly the same way for map and * multimap; the distinction is made entirely in how the tree functions are * called (*_unique versus *_equal, same as the standard). */ template , typename _Alloc = std::allocator > > class map { public: typedef _Key key_type; typedef _Tp mapped_type; typedef std::pair value_type; typedef _Compare key_compare; typedef _Alloc allocator_type; private: // concept requirements typedef typename _Alloc::value_type _Alloc_value_type; __glibcxx_class_requires(_Tp, _SGIAssignableConcept) __glibcxx_class_requires4(_Compare, bool, _Key, _Key, _BinaryFunctionConcept) __glibcxx_class_requires2(value_type, _Alloc_value_type, _SameTypeConcept) public: class value_compare : public std::binary_function { friend class map<_Key, _Tp, _Compare, _Alloc>; protected: _Compare comp; value_compare(_Compare __c) : comp(__c) { } public: bool operator()(const value_type& __x, const value_type& __y) const { return comp(__x.first, __y.first); } }; private: /// This turns a red-black tree into a [multi]map. typedef typename _Alloc::template rebind::other _Pair_alloc_type; typedef _Rb_tree, key_compare, _Pair_alloc_type> _Rep_type; /// The actual tree structure. _Rep_type _M_t; public: // many of these are specified differently in ISO, but the following are // "functionally equivalent" typedef typename _Pair_alloc_type::pointer pointer; typedef typename _Pair_alloc_type::const_pointer const_pointer; typedef typename _Pair_alloc_type::reference reference; typedef typename _Pair_alloc_type::const_reference const_reference; typedef typename _Rep_type::iterator iterator; typedef typename _Rep_type::const_iterator const_iterator; typedef typename _Rep_type::size_type size_type; typedef typename _Rep_type::difference_type difference_type; typedef typename _Rep_type::reverse_iterator reverse_iterator; typedef typename _Rep_type::const_reverse_iterator const_reverse_iterator; // [23.3.1.1] construct/copy/destroy // (get_allocator() is normally listed in this section, but seems to have // been accidentally omitted in the printed standard) /** * @brief Default constructor creates no elements. */ map() : _M_t() { } /** * @brief Creates a %map with no elements. * @param comp A comparison object. * @param a An allocator object. */ explicit map(const _Compare& __comp, const allocator_type& __a = allocator_type()) : _M_t(__comp, __a) { } /** * @brief %Map copy constructor. * @param x A %map of identical element and allocator types. * * The newly-created %map uses a copy of the allocation object * used by @a x. */ map(const map& __x) : _M_t(__x._M_t) { } #ifdef __GXX_EXPERIMENTAL_CXX0X__ /** * @brief %Map move constructor. * @param x A %map of identical element and allocator types. * * The newly-created %map contains the exact contents of @a x. * The contents of @a x are a valid, but unspecified %map. */ map(map&& __x) : _M_t(std::forward<_Rep_type>(__x._M_t)) { } #endif /** * @brief Builds a %map from a range. * @param first An input iterator. * @param last An input iterator. * * 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 * otherwise (where N is distance(first,last)). */ template map(_InputIterator __first, _InputIterator __last) : _M_t() { _M_t._M_insert_unique(__first, __last); } /** * @brief Builds a %map 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 %map 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 map(_InputIterator __first, _InputIterator __last, const _Compare& __comp, const allocator_type& __a = allocator_type()) : _M_t(__comp, __a) { _M_t._M_insert_unique(__first, __last); } // 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 that happen: /** * 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 responsibility. */ /** * @brief %Map assignment operator. * @param x A %map 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. */ map& operator=(const map& __x) { _M_t = __x._M_t; return *this; } #ifdef __GXX_EXPERIMENTAL_CXX0X__ /** * @brief %Map move assignment operator. * @param x A %map of identical element and allocator types. * * The contents of @a x are moved into this map (without copying). * @a x is a valid, but unspecified %map. */ map& operator=(map&& __x) { // NB: DR 675. this->clear(); this->swap(__x); return *this; } #endif /// Get a copy of the memory allocation object. allocator_type get_allocator() const { return _M_t.get_allocator(); } // 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. */ iterator begin() { return _M_t.begin(); } /** * Returns a read-only (constant) iterator that points to the first pair * in the %map. Iteration is done in ascending order according to the * keys. */ const_iterator begin() const { return _M_t.begin(); } /** * 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. */ iterator end() { 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. */ const_iterator end() const { return _M_t.end(); } /** * 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. */ reverse_iterator rbegin() { return _M_t.rbegin(); } /** * Returns a read-only (constant) reverse iterator that points to the * last pair in the %map. Iteration is done in descending order * according to the keys. */ const_reverse_iterator rbegin() const { return _M_t.rbegin(); } /** * Returns a read/write reverse iterator that points to one before the * first pair in the %map. Iteration is done in descending order * according to the keys. */ reverse_iterator rend() { return _M_t.rend(); } /** * Returns a read-only (constant) reverse iterator that points to one * before the first pair in the %map. Iteration is done in descending * order according to the keys. */ const_reverse_iterator rend() const { return _M_t.rend(); } #ifdef __GXX_EXPERIMENTAL_CXX0X__ /** * Returns a read-only (constant) iterator that points to the first¦&§&¨&©&ª&«&¬&­&®&¯&°&±&²&³&´&µ&¶&·& pair * in the %map. Iteration is done in ascending order according to the * keys. */ const_iterator cbegin() const { return _M_t.begin(); } /** * 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. */ const_iterator cend() const { return _M_t.end(); } /** * Returns a read-only (constant) reverse iterator that points to the * last pair in the %map. Iteration is done in descending order * according to the keys. */ const_reverse_iterator crbegin() 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 * order according to the keys. */ const_reverse_iterator crend() const { return _M_t.rend(); } #endif // capacity /** Returns true if the %map is empty. (Thus begin() would equal * end().) */ bool empty() const { return _M_t.empty(); } /** Returns the size of the %map. */ size_type size() const { return _M_t.size(); } /** Returns the maximum size of the %map. */ size_type max_size() const { return _M_t.max_size(); } // [23.3.1.2] element access /** * @brief Subscript ( @c [] ) access to %map data. * @param k The key for which data should be retrieved. * @return A reference to the data of the (key,data) %pair. * * 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) 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())); return (*__i).second; } // _GLIBCXX_RESOLVE_LIB_DEFECTS // DR 464. Suggestion for new member functions in standard containers. /** * @brief Access to %map data. * @param k The key for which data should be retrieved. * @return A reference to the data whose key is equivalent to @a k, if * such a data is present in the %map. * @throw std::out_of_range If no such data is present. */ mapped_type& at(const key_type& __k) { iterator __i = lower_bound(__k); if (__i == end() || key_comp()(__k, (*__i).first)) __throw_out_of_range(__N("map::at")); return (*__i).second; } const mapped_type& at(const key_type& __k) const { const_iterator __i = lower_bound(__k); if (__i == end() || key_comp()(__k, (*__i).first)) __throw_out_of_range(__N("map::at")); return (*__i).second; } // modifiers /** * @brief Attempts to insert a std::pair into the %map. * @param x Pair to be inserted (see std::make_pair for easy creation * of pairs). * @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 is true if the pair was actually inserted. * * 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 * first element (the key) is not already present in the %map. * * Insertion requires logarithmic time. */ std::pair insert(const value_type& __x) { return _M_t._M_insert_unique(__x); } /** * @brief Attempts to insert a std::pair into the %map. * @param position An iterator that serves as a hint as to where the * pair should be inserted. * @param x Pair to be inserted (see std::make_pair for easy creation * of pairs). * @return An iterator that points to the element with key of @a x (may * or may not be the %pair passed in). * * This function is not concerned about whether the insertion * took place, and thus does not return a boolean like the * single-argument insert() does. 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++/manual/bk01pt07ch17.html * 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._M_insert_unique_(__position, __x); } /** * @brief Template function that attempts 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 void insert(_InputIterator __first, _InputIterator __last) { _M_t._M_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 responsibility. */ void erase(iterator __position) { _M_t.erase(__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 the elements located by the given key 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 responsibility. */ size_type erase(const key_type& __x) { return _M_t.erase(__x); } /** * @brief Erases a [first,last) range of elements from a %map. * @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 %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 responsibility. */ void erase(iterator __first, iterator __last) { _M_t.erase(__first, __last); } /** * @brief Swaps data with another %map. * @param x A %map of the same element and allocator types. * * This exchanges the elements between two maps 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(m1,m2) will feed to this function. */ void #ifdef __GXX_EXPERIMENTAL_CXX0X__ swap(map&& __x) #else swap(map& __x) #endif { _M_t.swap(__x._M_t); } /** * Erases all elements in a %map. 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 responsibility. */ void clear() { _M_t.clear(); } // observers /** * Returns the key comparison object out of which the %map was * constructed. */ key_compare key_comp() const { return _M_t.key_comp(); } /** * Returns a value comparison object, built from the key comparison * object out of which the %map was constructed. */ value_compare value_comp() const { return value_compare(_M_t.key_comp()); } // [23.3.1.3] map operations /** * @brief Tries to locate an element in a %map. * @param x Key of (key, value) %pair 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 %pair. If unsuccessful it returns the * past-the-end ( @c end() ) iterator. */ 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 * 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 a constant * iterator pointing to the sought after %pair. If unsuccessful it * returns the past-the-end ( @c end() ) iterator. */ 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. * * 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 { 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. * @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); } /** * @brief Finds the beginning of a subsequence matching given key. * @param x Key of (key, value) pair to be located. * @return Read-only (constant) 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. */ 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 of (key, value) pair 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); } /** * @brief Finds the end of a subsequence matching given key. * @param x Key of (key, value) pair to be located. * @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); } /** * @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 * 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 multimaps. */ std::pair 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. * @return Pair of read-only (constant) 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 multimaps. */ std::pair equal_range(const key_type& __x) const { return _M_t.equal_range(__x); } template friend bool operator==(const map<_K1, _T1, _C1, _A1>&, const map<_K1, _T1, _C1, _A1>&); template friend bool operator<(const map<_K1, _T1, _C1, _A1>&, const map<_K1, _T1, _C1, _A1>&); }; /** * @brief Map equality comparison. * @param x A %map. * @param y A %map of the same type as @a x. * @return True iff the size and elements of the maps are equal. * * This is an equivalence relation. It is linear in the size of the * maps. Maps are considered equivalent if their sizes are equal, * and if corresponding elements compare equal. */ template inline bool operator==(const map<_Key, _Tp, _Compare, _Alloc>& __x, const map<_Key, _Tp, _Compare, _Alloc>& __y) { return __x._M_t == __y._M_t; } /** * @brief Map ordering relation. * @param x A %map. * @param y A %map of the same type as @a x. * @return True iff @a x is lexicographically less than @a y. * * This is a total ordering relation. It is linear in the size of the * maps. The elements must be comparable with @c <. * * See std::lexicographical_compare() for how the determination is made. */ template inline bool operator<(const map<_Key, _Tp, _Compare, _Alloc>& __x, const map<_Key, _Tp, _Compare, _Alloc>& __y) { return __x._M_t < __y._M_t; } /// Based on operator== template inline bool operator!=(const map<_Key, _Tp, _Compare, _Alloc>& __x, const map<_Key, _Tp, _Compare, _Alloc>& __y) { return !(__x == __y); } /// Based on operator< template inline bool operator>(const map<_Key, _Tp, _Compare, _Alloc>& __x, const map<_Key, _Tp, _Compare, _Alloc>& __y) { return __y < __x; } /// Based on operator< template inline bool operator<=(const map<_Key, _Tp, _Compare, _Alloc>& __x, const map<_Key, _Tp, _Compare, _Alloc>& __y) { return !(__y < __x); } /// Based on operator< template inline bool operator>=(const map<_Key, _Tp, _Compare, _Alloc>& __x, const map<_Key, _Tp, _Compare, _Alloc>& __y) { return !(__x < __y); } /// See std::map::swap(). template inline void swap(map<_Key, _Tp, _Compare, _Alloc>& __x, map<_Key, _Tp, _Compare, _Alloc>& __y) { __x.swap(__y); } #ifdef __GXX_EXPERIMENTAL_CXX0X__ template inline void swap(map<_Key, _Tp, _Compare, _Alloc>&& __x, map<_Key, _Tp, _Compare, _Alloc>& __y) { __x.swap(__y); } template inline void swap(map<_Key, _Tp, _Compare, _Alloc>& __x, map<_Key, _Tp, _Compare, _Alloc>&& __y) { __x.swap(__y); } #endif _GLIBCXX_END_NESTED_NAMESPACE #endif /* _STL_MAP_H */ // Locale support -*- C++ -*- // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, // 2006, 2007 // Free Software Foundation, Inc. // // 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 // terms of the GNU General Public License as published by the // Free Software Foundation; either version 2, or (at your option) // any later version. // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License along // with this library; see the file COPYING. If not, write to the Free // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, // USA. // As a special exception, you may use this file as part of a free software // library without restriction. Specifically, if other files instantiate // templates or use macros or inline functions from this file, or you compile // this file and link it with other files to produce an executable, this // file does not by itself cause the resulting executable to be covered by // the GNU General Public License. This exception does not however // invalidate any other reasons why the executable file might be covered by // the GNU General Public License. /** @file locale_facets.h * This is an internal header file, included by other library headers. * You should not attempt to use it directly. */ // // ISO C++ 14882: 22.1 Locales // #ifndef _LOCALE_FACETS_H #define _LOCALE_FACETS_H 1 #pragma GCC system_header #include // For wctype_t #include #include #include #include // For ios_base, ios_base::iostate #include #include #include #include #include _GLIBCXX_BEGIN_NAMESPACE(std) // NB: Don't instantiate required wchar_t facets if no wchar_t support. #ifdef _GLIBCXX_USE_WCHAR_T # define _GLIBCXX_NUM_FACETS 28 #else # define _GLIBCXX_NUM_FACETS 14 #endif // Convert string to numeric value of type _Tv and store results. // NB: This is specialized for all required types, there is no // generic definition. template void __convert_to_v(const char* __in, _Tv& __out, ios_base::iostate& __err, const __c_locale& __cloc); // Explicit specializations for required types. template<> void __convert_to_v(const char*, float&, ios_base::iostate&, const __c_locale&); template<> void __convert_to_v(const char*, double&, ios_base::iostate&, const __c_locale&); template<> void __convert_to_v(const char*, long double&, ios_base::iostate&, const __c_locale&); // NB: __pad is a struct, rather than a function, so it can be // partially-specialized. template struct __pad { static void _S_pad(ios_base& __io, _CharT __fill, _CharT* __news, const _CharT* __olds, const streamsize __newlen, const streamsize __oldlen); }; // Used by both numeric and monetary facets. // Inserts "group separator" characters into an array of characters. // It's recursive, one iteration per group. It moves the characters // in the buffer this way: "xxxx12345" -> "12,345xxx". Call this // only with __gsize != 0. template _CharT* __add_grouping(_CharT* __s, _CharT __sep, const char* __gbeg, size_t __gsize, const _CharT* __first, const _CharT* __last); // This template permits specializing facet output code for // ostreambuf_iterator. For ostreambuf_iterator, sputn is // significantly more efficient than incrementing iterators. template inline ostreambuf_iterator<_CharT> __write(ostreambuf_iterator<_CharT> __s, const _CharT* __ws, int __len) { __s._M_put(__ws, __len); return __s; } // This is the unspecialized form of the template. template inline _OutIter __write(_OutIter __s, const _CharT* __ws, int __len) { for (int __j = 0; __j < __len; __j++, ++__s) *__s = __ws[__j]; return __s; } // 22.2.1.1 Template class ctype // Include host and configuration specific ctype enums for ctype_base. // Common base for ctype<_CharT>. /** * @brief Common base for ctype facet * * This template class provides implementations of the public functions * that forward to the protected virtual functions. * * This template also provides abstract stubs for the protected virtual * functions. */ template class __ctype_abstract_base : public locale::facet, public ctype_base { public: // Types: /// Typedef for the template parameter typedef _CharT char_type; /** * @brief Test char_type classification. * * This function finds a mask M for @a c and compares it to mask @a m. * It does so by returning the value of ctype::do_is(). * * @param c The char_type to compare the mask of. * @param m The mask to compare against. * @return (M & m) != 0. */ bool is(mask __m, char_type __c) const { return this->do_is(__m, __c); } /** * @brief Return a mask array. * * This function finds the mask for each char_type in the range [lo,hi) * and successively writes it to vec. vec must have as many elements * as the char array. It does so by returning the value of * ctype::do_is(). * * @param lo Pointer to start of range. * @param hi Pointer to end of range. * @param vec Pointer to an array of mask storage. * @return @a hi. */ const char_type* is(const char_type *__lo, const char_type *__hi, mask *__vec) const { return this->do_is(__lo, __hi, __vec); } /** * @brief Find char_type matching a mask * * This function searches for and returns the first char_type c in * [lo,hi) for which is(m,c) is true. It does so by returning * ctype::do_scan_is(). * * @param m The mask to compare against. * @param lo Pointer to start of range. * @param hi Pointer to end of range. * @return Pointer to matching char_type if found, else @a hi. */ const char_type* scan_is(mask __m, const char_type* __lo, const char_type* __hi) const { return this->do_scan_is(__m, __lo, __hi); } /** * @brief Find char_type not matching a mask * * This function searches for and returns the first char_type c in * [lo,hi) for which is(m,c) is false. It does so by returning * ctype::do_scan_not(). * * @param m The mask to compare against. * @param lo Pointer to first char in range. * @param hi Pointer to end of range. * @return Pointer to non-matching char if found, else @a hi. */ const char_type* scan_not(mask __m, const char_type* __lo, const char_type* __hi) const { return this->do_scan_not(__m, __lo, __hi); } /** * @brief Convert to uppercase. * * This function converts the argument to uppercase if possible. * If not possible (for example, '2'), returns the argument. It does * so by returning ctype::do_toupper(). * * @param c The char_type to convert. * @return The uppercase char_type if convertible, else @a c. */ char_type toupper(char_type __c) const { return this->do_toupper(__c); } /** * @brief Convert array to uppercase. * * This function converts each char_type in the range [lo,hi) to * uppercase if possible. Other elements remain un