diff options
Diffstat (limited to 'contrib/libstdc++/include/bits')
64 files changed, 7729 insertions, 5923 deletions
diff --git a/contrib/libstdc++/include/bits/allocator.h b/contrib/libstdc++/include/bits/allocator.h index c9200ec..43939c1 100644 --- a/contrib/libstdc++/include/bits/allocator.h +++ b/contrib/libstdc++/include/bits/allocator.h @@ -1,6 +1,7 @@ // Allocators -*- C++ -*- -// Copyright (C) 2001, 2002, 2003, 2004 Free Software Foundation, Inc. +// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 +// 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 @@ -15,7 +16,7 @@ // 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// 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 @@ -51,11 +52,14 @@ // Define the base class to std::allocator. #include <bits/c++allocator.h> -namespace std -{ +#include <bits/cpp_type_traits.h> // for __is_empty + +_GLIBCXX_BEGIN_NAMESPACE(std) + template<typename _Tp> class allocator; + /// allocator<void> specialization. template<> class allocator<void> { @@ -72,12 +76,13 @@ namespace std }; /** - * @brief The "standard" allocator, as per [20.4]. + * @brief The "standard" allocator, as per [20.4]. * - * (See @link Allocators allocators info @endlink for more.) + * Further details: + * http://gcc.gnu.org/onlinedocs/libstdc++/20_util/allocator.html */ template<typename _Tp> - class allocator: public ___glibcxx_base_allocator<_Tp> + class allocator: public __glibcxx_base_allocator<_Tp> { public: typedef size_t size_type; @@ -94,8 +99,8 @@ namespace std allocator() throw() { } - allocator(const allocator& a) throw() - : ___glibcxx_base_allocator<_Tp>(a) { } + allocator(const allocator& __a) throw() + : __glibcxx_base_allocator<_Tp>(__a) { } template<typename _Tp1> allocator(const allocator<_Tp1>&) throw() { } @@ -124,7 +129,25 @@ namespace std #endif // Undefine. -#undef ___glibcxx_base_allocator -} // namespace std +#undef __glibcxx_base_allocator + + // To implement Option 3 of DR 431. + template<typename _Alloc, bool = std::__is_empty<_Alloc>::__value> + struct __alloc_swap + { static void _S_do_it(_Alloc&, _Alloc&) { } }; + + template<typename _Alloc> + struct __alloc_swap<_Alloc, false> + { + static void + _S_do_it(_Alloc& __one, _Alloc& __two) + { + // Precondition: swappable allocators. + if (__one != __two) + swap(__one, __two); + } + }; + +_GLIBCXX_END_NAMESPACE #endif diff --git a/contrib/libstdc++/include/bits/basic_ios.h b/contrib/libstdc++/include/bits/basic_ios.h index 7ffe40e..d078431 100644 --- a/contrib/libstdc++/include/bits/basic_ios.h +++ b/contrib/libstdc++/include/bits/basic_ios.h @@ -1,6 +1,6 @@ // Iostreams base classes -*- C++ -*- -// Copyright (C) 1997, 1998, 1999, 2001, 2002, 2003, 2004 +// Copyright (C) 1997, 1998, 1999, 2001, 2002, 2003, 2004, 2005 // Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free @@ -16,7 +16,7 @@ // 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// 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 @@ -43,8 +43,8 @@ #include <bits/locale_classes.h> #include <bits/locale_facets.h> -namespace std -{ +_GLIBCXX_BEGIN_NAMESPACE(std) + // 27.4.5 Template class basic_ios /** * @brief Virtual base class for all stream classes. @@ -458,7 +458,8 @@ namespace std void _M_cache_locale(const locale& __loc); }; -} // namespace std + +_GLIBCXX_END_NAMESPACE #ifndef _GLIBCXX_EXPORT_TEMPLATE #include <bits/basic_ios.tcc> diff --git a/contrib/libstdc++/include/bits/basic_ios.tcc b/contrib/libstdc++/include/bits/basic_ios.tcc index fcb4b02..e8434a5 100644 --- a/contrib/libstdc++/include/bits/basic_ios.tcc +++ b/contrib/libstdc++/include/bits/basic_ios.tcc @@ -1,6 +1,7 @@ // basic_ios member functions -*- C++ -*- -// Copyright (C) 1999, 2001, 2002, 2003 Free Software Foundation, Inc. +// Copyright (C) 1999, 2001, 2002, 2003, 2004, 2005 +// 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 @@ -15,7 +16,7 @@ // 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// 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 @@ -27,13 +28,18 @@ // invalidate any other reasons why the executable file might be covered by // the GNU General Public License. +/** @file basic_ios.tcc + * This is an internal header file, included by other library headers. + * You should not attempt to use it directly. + */ + #ifndef _BASIC_IOS_TCC #define _BASIC_IOS_TCC 1 #pragma GCC system_header -namespace std -{ +_GLIBCXX_BEGIN_NAMESPACE(std) + template<typename _CharT, typename _Traits> void basic_ios<_CharT, _Traits>::clear(iostate __state) @@ -87,11 +93,6 @@ namespace std _M_callbacks = __cb; for (int __i = 0; __i < __rhs._M_word_size; ++__i) __words[__i] = __rhs._M_word[__i]; - if (_M_word != _M_local_word) - { - delete [] _M_word; - _M_word = 0; - } _M_word = __words; _M_word_size = __rhs._M_word_size; @@ -195,6 +196,7 @@ namespace std extern template class basic_ios<wchar_t>; #endif #endif -} // namespace std + +_GLIBCXX_END_NAMESPACE #endif diff --git a/contrib/libstdc++/include/bits/basic_string.h b/contrib/libstdc++/include/bits/basic_string.h index 04e1500..e4b7a5b 100644 --- a/contrib/libstdc++/include/bits/basic_string.h +++ b/contrib/libstdc++/include/bits/basic_string.h @@ -1,6 +1,7 @@ // Components for manipulating sequences of characters -*- C++ -*- -// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004 +// 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 @@ -16,7 +17,7 @@ // 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// 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 @@ -28,25 +29,25 @@ // invalidate any other reasons why the executable file might be covered by // the GNU General Public License. -// -// ISO C++ 14882: 21 Strings library -// - /** @file basic_string.h * This is an internal header file, included by other library headers. * You should not attempt to use it directly. */ +// +// ISO C++ 14882: 21 Strings library +// + #ifndef _BASIC_STRING_H #define _BASIC_STRING_H 1 #pragma GCC system_header -#include <bits/atomicity.h> +#include <ext/atomicity.h> #include <debug/debug.h> -namespace std -{ +_GLIBCXX_BEGIN_NAMESPACE(std) + /** * @class basic_string basic_string.h <string> * @brief Managing sequences of characters and character-like objects. @@ -109,17 +110,19 @@ namespace std template<typename _CharT, typename _Traits, typename _Alloc> class basic_string { + typedef typename _Alloc::template rebind<_CharT>::other _CharT_alloc_type; + // Types: public: typedef _Traits traits_type; typedef typename _Traits::char_type value_type; typedef _Alloc allocator_type; - typedef typename _Alloc::size_type size_type; - typedef typename _Alloc::difference_type difference_type; - typedef typename _Alloc::reference reference; - typedef typename _Alloc::const_reference const_reference; - typedef typename _Alloc::pointer pointer; - typedef typename _Alloc::const_pointer const_pointer; + typedef typename _CharT_alloc_type::size_type size_type; + typedef typename _CharT_alloc_type::difference_type difference_type; + typedef typename _CharT_alloc_type::reference reference; + typedef typename _CharT_alloc_type::const_reference const_reference; + typedef typename _CharT_alloc_type::pointer pointer; + typedef typename _CharT_alloc_type::const_pointer const_pointer; typedef __gnu_cxx::__normal_iterator<pointer, basic_string> iterator; typedef __gnu_cxx::__normal_iterator<const_pointer, basic_string> const_iterator; @@ -175,7 +178,13 @@ namespace std static _Rep& _S_empty_rep() - { return *reinterpret_cast<_Rep*>(&_S_empty_rep_storage); } + { + // NB: Mild hack to avoid strict-aliasing warnings. Note that + // _S_empty_rep_storage is never modified and the punning should + // be reasonably safe in this case. + void* __p = reinterpret_cast<void*>(&_S_empty_rep_storage); + return *reinterpret_cast<_Rep*>(__p); + } bool _M_is_leaked() const @@ -193,6 +202,16 @@ namespace std _M_set_sharable() { this->_M_refcount = 0; } + void + _M_set_length_and_sharable(size_type __n) + { + this->_M_set_sharable(); // One reference. + this->_M_length = __n; + traits_type::assign(this->_M_refdata()[__n], _S_terminal); + // grrr. (per 21.3.4) + // You cannot leave those LWG people alone for a second. + } + _CharT* _M_refdata() throw() { return reinterpret_cast<_CharT*>(this + 1); } @@ -214,7 +233,8 @@ namespace std #ifndef _GLIBCXX_FULLY_DYNAMIC_STRING if (__builtin_expect(this != &_S_empty_rep(), false)) #endif - if (__gnu_cxx::__exchange_and_add(&this->_M_refcount, -1) <= 0) + if (__gnu_cxx::__exchange_and_add_dispatch(&this->_M_refcount, + -1) <= 0) _M_destroy(__a); } // XXX MT @@ -227,7 +247,7 @@ namespace std #ifndef _GLIBCXX_FULLY_DYNAMIC_STRING if (__builtin_expect(this != &_S_empty_rep(), false)) #endif - __gnu_cxx::__atomic_add(&this->_M_refcount, 1); + __gnu_cxx::__atomic_add_dispatch(&this->_M_refcount, 1); return _M_refdata(); } // XXX MT @@ -248,8 +268,7 @@ namespace std // Data Members (public): // NB: This is an unsigned type, and thus represents the maximum // size that the allocator can hold. - /// @var - /// Value returned by various member functions when they fail. + /// Value returned by various member functions when they fail. static const size_type npos = static_cast<size_type>(-1); private: @@ -271,10 +290,12 @@ namespace std // For the internal use we have functions similar to `begin'/`end' // but they do not call _M_leak. iterator - _M_ibegin() const { return iterator(_M_data()); } + _M_ibegin() const + { return iterator(_M_data()); } iterator - _M_iend() const { return iterator(_M_data() + this->size()); } + _M_iend() const + { return iterator(_M_data() + this->size()); } void _M_leak() // for use in begin() & non-const op[] @@ -291,6 +312,13 @@ namespace std return __pos; } + void + _M_check_length(size_type __n1, size_type __n2, const char* __s) const + { + if (this->max_size() - (this->size() - __n1) < __n2) + __throw_length_error(__N(__s)); + } + // NB: _M_limit doesn't check for a bad __pos value. size_type _M_limit(size_type __pos, size_type __off) const @@ -299,6 +327,43 @@ namespace std return __testoff ? __off : this->size() - __pos; } + // True if _Rep and source do not overlap. + bool + _M_disjunct(const _CharT* __s) const + { + return (less<const _CharT*>()(__s, _M_data()) + || less<const _CharT*>()(_M_data() + this->size(), __s)); + } + + // When __n = 1 way faster than the general multichar + // traits_type::copy/move/assign. + static void + _M_copy(_CharT* __d, const _CharT* __s, size_type __n) + { + if (__n == 1) + traits_type::assign(*__d, *__s); + else + traits_type::copy(__d, __s, __n); + } + + static void + _M_move(_CharT* __d, const _CharT* __s, size_type __n) + { + if (__n == 1) + traits_type::assign(*__d, *__s); + else + traits_type::move(__d, __s, __n); + } + + static void + _M_assign(_CharT* __d, size_type __n, _CharT __c) + { + if (__n == 1) + traits_type::assign(*__d, __c); + else + traits_type::assign(__d, __n, __c); + } + // _S_copy_chars is a separate template to permit specialization // to optimize for the common case of pointers as iterators. template<class _Iterator> @@ -319,11 +384,11 @@ namespace std static void _S_copy_chars(_CharT* __p, _CharT* __k1, _CharT* __k2) - { traits_type::copy(__p, __k1, __k2 - __k1); } + { _M_copy(__p, __k1, __k2 - __k1); } static void _S_copy_chars(_CharT* __p, const _CharT* __k1, const _CharT* __k2) - { traits_type::copy(__p, __k1, __k2 - __k1); } + { _M_copy(__p, __k1, __k2 - __k1); } void _M_mutate(size_type __pos, size_type __len1, size_type __len2); @@ -347,7 +412,7 @@ namespace std basic_string(); /** - * @brief Construct an empty string using allocator a. + * @brief Construct an empty string using allocator @a a. */ explicit basic_string(const _Alloc& __a); @@ -382,7 +447,7 @@ namespace std * @param n Number of characters to copy. * @param a Allocator to use (default is default allocator). * - * NB: s must have at least n characters, '\0' has no special + * NB: @a s must have at least @a n characters, '\0' has no special * meaning. */ basic_string(const _CharT* __s, size_type __n, @@ -423,10 +488,7 @@ namespace std */ basic_string& operator=(const basic_string& __str) - { - this->assign(__str); - return *this; - } + { return this->assign(__str); } /** * @brief Copy contents of @a s into this string. @@ -434,10 +496,7 @@ namespace std */ basic_string& operator=(const _CharT* __s) - { - this->assign(__s); - return *this; - } + { return this->assign(__s); } /** * @brief Set value to string of length 1. @@ -533,16 +592,19 @@ namespace std /// Returns the number of characters in the string, not including any /// null-termination. size_type - size() const { return _M_rep()->_M_length; } + size() const + { return _M_rep()->_M_length; } /// Returns the number of characters in the string, not including any /// null-termination. size_type - length() const { return _M_rep()->_M_length; } + length() const + { return _M_rep()->_M_length; } /// Returns the size() of the largest possible %string. size_type - max_size() const { return _Rep::_S_max_size; } + max_size() const + { return _Rep::_S_max_size; } /** * @brief Resizes the %string to the specified number of characters. @@ -568,20 +630,22 @@ namespace std * setting them to 0. */ void - resize(size_type __n) { this->resize(__n, _CharT()); } + resize(size_type __n) + { this->resize(__n, _CharT()); } /** * Returns the total number of characters that the %string can hold * before needing to allocate more memory. */ size_type - capacity() const { return _M_rep()->_M_capacity; } + capacity() const + { return _M_rep()->_M_capacity; } /** * @brief Attempt to preallocate enough memory for specified number of * characters. - * @param n Number of characters required. - * @throw std::length_error If @a n exceeds @c max_size(). + * @param res_arg Number of characters required. + * @throw std::length_error If @a res_arg exceeds @c max_size(). * * This function attempts to reserve enough memory for the * %string to hold the specified number of characters. If the @@ -601,18 +665,20 @@ namespace std * Erases the string, making it empty. */ void - clear() { _M_mutate(0, this->size(), 0); } + clear() + { _M_mutate(0, this->size(), 0); } /** * Returns true if the %string is empty. Equivalent to *this == "". */ bool - empty() const { return this->size() == 0; } + empty() const + { return this->size() == 0; } // Element access: /** * @brief Subscript access to the data contained in the %string. - * @param n The index of the character to access. + * @param pos The index of the character to access. * @return Read-only (constant) reference to the character. * * This operator allows for easy, array-style, data access. @@ -629,7 +695,7 @@ namespace std /** * @brief Subscript access to the data contained in the %string. - * @param n The index of the character to access. + * @param pos The index of the character to access. * @return Read/write reference to the character. * * This operator allows for easy, array-style, data access. @@ -640,7 +706,10 @@ namespace std reference operator[](size_type __pos) { - _GLIBCXX_DEBUG_ASSERT(__pos < size()); + // allow pos == size() as v3 extension: + _GLIBCXX_DEBUG_ASSERT(__pos <= size()); + // but be strict in pedantic mode: + _GLIBCXX_DEBUG_PEDASSERT(__pos < size()); _M_leak(); return _M_data()[__pos]; } @@ -690,7 +759,8 @@ namespace std * @return Reference to this string. */ basic_string& - operator+=(const basic_string& __str) { return this->append(__str); } + operator+=(const basic_string& __str) + { return this->append(__str); } /** * @brief Append a C string. @@ -698,15 +768,20 @@ namespace std * @return Reference to this string. */ basic_string& - operator+=(const _CharT* __s) { return this->append(__s); } + operator+=(const _CharT* __s) + { return this->append(__s); } /** * @brief Append a character. - * @param s The character to append. + * @param c The character to append. * @return Reference to this string. */ basic_string& - operator+=(_CharT __c) { return this->append(size_type(1), __c); } + operator+=(_CharT __c) + { + this->push_back(__c); + return *this; + } /** * @brief Append a string to this string. @@ -761,8 +836,7 @@ namespace std * Appends n copies of c to this string. */ basic_string& - append(size_type __n, _CharT __c) - { return _M_replace_aux(this->size(), size_type(0), __n, __c); } + append(size_type __n, _CharT __c); /** * @brief Append a range of characters. @@ -783,7 +857,13 @@ namespace std */ void push_back(_CharT __c) - { _M_replace_aux(this->size(), size_type(0), size_type(1), __c); } + { + const size_type __len = 1 + this->size(); + if (__len > this->capacity() || _M_rep()->_M_is_shared()) + this->reserve(__len); + traits_type::assign(_M_data()[this->size()], __c); + _M_rep()->_M_set_length_and_sharable(__len); + } /** * @brief Set value to contents of another string. @@ -894,7 +974,8 @@ namespace std * of the string doesn't change if an error is thrown. */ template<class _InputIterator> - void insert(iterator __p, _InputIterator __beg, _InputIterator __end) + void + insert(iterator __p, _InputIterator __beg, _InputIterator __end) { this->replace(__p, __p, __beg, __end); } /** @@ -1018,7 +1099,7 @@ namespace std const size_type __pos = __p - _M_ibegin(); _M_replace_aux(__pos, size_type(0), size_type(1), __c); _M_rep()->_M_set_leaked(); - return this->_M_ibegin() + __pos; + return iterator(_M_data() + __pos); } /** @@ -1037,8 +1118,11 @@ namespace std */ basic_string& erase(size_type __pos = 0, size_type __n = npos) - { return _M_replace_safe(_M_check(__pos, "basic_string::erase"), - _M_limit(__pos, __n), NULL, size_type(0)); } + { + _M_mutate(_M_check(__pos, "basic_string::erase"), + _M_limit(__pos, __n), size_type(0)); + return *this; + } /** * @brief Remove one character. @@ -1054,9 +1138,9 @@ namespace std _GLIBCXX_DEBUG_PEDASSERT(__position >= _M_ibegin() && __position < _M_iend()); const size_type __pos = __position - _M_ibegin(); - _M_replace_safe(__pos, size_type(1), NULL, size_type(0)); + _M_mutate(__pos, size_type(1), size_type(0)); _M_rep()->_M_set_leaked(); - return _M_ibegin() + __pos; + return iterator(_M_data() + __pos); } /** @@ -1074,9 +1158,9 @@ namespace std _GLIBCXX_DEBUG_PEDASSERT(__first >= _M_ibegin() && __first <= __last && __last <= _M_iend()); const size_type __pos = __first - _M_ibegin(); - _M_replace_safe(__pos, __last - __first, NULL, size_type(0)); + _M_mutate(__pos, __last - __first, size_type(0)); _M_rep()->_M_set_leaked(); - return _M_ibegin() + __pos; + return iterator(_M_data() + __pos); } /** @@ -1128,15 +1212,15 @@ namespace std * @brief Replace characters with value of a C substring. * @param pos Index of first character to replace. * @param n1 Number of characters to be replaced. - * @param str C string to insert. - * @param n2 Number of characters from str to use. + * @param s C string to insert. + * @param n2 Number of characters from @a s to use. * @return Reference to this string. * @throw std::out_of_range If @a pos1 > size(). * @throw std::length_error If new length exceeds @c max_size(). * * Removes the characters in the range [pos,pos + n1) from this string. - * In place, the first @a n2 characters of @a str are inserted, or all - * of @a str if @a n2 is too large. If @a pos is beyond end of string, + * In place, the first @a n2 characters of @a s are inserted, or all + * of @a s if @a n2 is too large. If @a pos is beyond end of string, * out_of_range is thrown. If the length of result exceeds max_size(), * length_error is thrown. The value of the string doesn't change if * an error is thrown. @@ -1149,13 +1233,13 @@ namespace std * @brief Replace characters with value of a C string. * @param pos Index of first character to replace. * @param n1 Number of characters to be replaced. - * @param str C string to insert. + * @param s C string to insert. * @return Reference to this string. * @throw std::out_of_range If @a pos > size(). * @throw std::length_error If new length exceeds @c max_size(). * * Removes the characters in the range [pos,pos + n1) from this string. - * In place, the first @a n characters of @a str are inserted. If @a + * In place, the first @a n characters of @a s are inserted. If @a * pos is beyond end of string, out_of_range is thrown. If the length * of result exceeds max_size(), length_error is thrown. The value of * the string doesn't change if an error is thrown. @@ -1291,54 +1375,54 @@ namespace std _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 && __i2 <= _M_iend()); __glibcxx_requires_valid_range(__k1, __k2); - typedef typename _Is_integer<_InputIterator>::_Integral _Integral; + typedef typename std::__is_integer<_InputIterator>::__type _Integral; return _M_replace_dispatch(__i1, __i2, __k1, __k2, _Integral()); } // Specializations for the common case of pointer and iterator: // useful to avoid the overhead of temporary buffering in _M_replace. basic_string& - replace(iterator __i1, iterator __i2, _CharT* __k1, _CharT* __k2) - { - _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 - && __i2 <= _M_iend()); - __glibcxx_requires_valid_range(__k1, __k2); - return this->replace(__i1 - _M_ibegin(), __i2 - __i1, - __k1, __k2 - __k1); - } + replace(iterator __i1, iterator __i2, _CharT* __k1, _CharT* __k2) + { + _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 + && __i2 <= _M_iend()); + __glibcxx_requires_valid_range(__k1, __k2); + return this->replace(__i1 - _M_ibegin(), __i2 - __i1, + __k1, __k2 - __k1); + } basic_string& - replace(iterator __i1, iterator __i2, - const _CharT* __k1, const _CharT* __k2) - { - _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 - && __i2 <= _M_iend()); - __glibcxx_requires_valid_range(__k1, __k2); - return this->replace(__i1 - _M_ibegin(), __i2 - __i1, - __k1, __k2 - __k1); - } + replace(iterator __i1, iterator __i2, + const _CharT* __k1, const _CharT* __k2) + { + _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 + && __i2 <= _M_iend()); + __glibcxx_requires_valid_range(__k1, __k2); + return this->replace(__i1 - _M_ibegin(), __i2 - __i1, + __k1, __k2 - __k1); + } basic_string& - replace(iterator __i1, iterator __i2, iterator __k1, iterator __k2) - { - _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 - && __i2 <= _M_iend()); - __glibcxx_requires_valid_range(__k1, __k2); - return this->replace(__i1 - _M_ibegin(), __i2 - __i1, - __k1.base(), __k2 - __k1); - } + replace(iterator __i1, iterator __i2, iterator __k1, iterator __k2) + { + _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 + && __i2 <= _M_iend()); + __glibcxx_requires_valid_range(__k1, __k2); + return this->replace(__i1 - _M_ibegin(), __i2 - __i1, + __k1.base(), __k2 - __k1); + } basic_string& - replace(iterator __i1, iterator __i2, - const_iterator __k1, const_iterator __k2) - { - _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 - && __i2 <= _M_iend()); - __glibcxx_requires_valid_range(__k1, __k2); - return this->replace(__i1 - _M_ibegin(), __i2 - __i1, - __k1.base(), __k2 - __k1); - } - + replace(iterator __i1, iterator __i2, + const_iterator __k1, const_iterator __k2) + { + _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 + && __i2 <= _M_iend()); + __glibcxx_requires_valid_range(__k1, __k2); + return this->replace(__i1 - _M_ibegin(), __i2 - __i1, + __k1.base(), __k2 - __k1); + } + private: template<class _Integer> basic_string& @@ -1353,29 +1437,11 @@ namespace std basic_string& _M_replace_aux(size_type __pos1, size_type __n1, size_type __n2, - _CharT __c) - { - if (this->max_size() - (this->size() - __n1) < __n2) - __throw_length_error(__N("basic_string::_M_replace_aux")); - _M_mutate(__pos1, __n1, __n2); - if (__n2 == 1) - _M_data()[__pos1] = __c; - else if (__n2) - traits_type::assign(_M_data() + __pos1, __n2, __c); - return *this; - } + _CharT __c); basic_string& _M_replace_safe(size_type __pos1, size_type __n1, const _CharT* __s, - size_type __n2) - { - _M_mutate(__pos1, __n1, __n2); - if (__n2 == 1) - _M_data()[__pos1] = *__s; - else if (__n2) - traits_type::copy(_M_data() + __pos1, __s, __n2); - return *this; - } + size_type __n2); // _S_construct_aux is used to implement the 21.3.1 para 15 which // requires special behaviour if _InIter is an integral type @@ -1399,7 +1465,7 @@ namespace std static _CharT* _S_construct(_InIterator __beg, _InIterator __end, const _Alloc& __a) { - typedef typename _Is_integer<_InIterator>::_Integral _Integral; + typedef typename std::__is_integer<_InIterator>::__type _Integral; return _S_construct_aux(__beg, __end, __a, _Integral()); } @@ -1453,7 +1519,8 @@ namespace std * happen. */ const _CharT* - c_str() const { return _M_data(); } + c_str() const + { return _M_data(); } /** * @brief Return const pointer to contents. @@ -1462,13 +1529,15 @@ namespace std * happen. */ const _CharT* - data() const { return _M_data(); } + data() const + { return _M_data(); } /** * @brief Return copy of allocator used to construct this string. */ allocator_type - get_allocator() const { return _M_dataplus; } + get_allocator() const + { return _M_dataplus; } /** * @brief Find position of a C substring. @@ -1559,7 +1628,7 @@ namespace std /** * @brief Find last position of a C string. * @param s C string to locate. - * @param pos Index of character to start search at (default 0). + * @param pos Index of character to start search at (default end). * @return Index of start of last occurrence. * * Starting from @a pos, searches backward for the value of @a s within @@ -1576,7 +1645,7 @@ namespace std /** * @brief Find last position of a character. * @param c Character to locate. - * @param pos Index of character to search back from (default 0). + * @param pos Index of character to search back from (default end). * @return Index of last occurrence. * * Starting from @a pos, searches backward for @a c within this string. @@ -2244,7 +2313,7 @@ namespace std inline bool operator<=(const _CharT* __lhs, const basic_string<_CharT, _Traits, _Alloc>& __rhs) - { return __rhs.compare(__lhs) >= 0; } + { return __rhs.compare(__lhs) >= 0; } // operator >= /** @@ -2312,6 +2381,10 @@ namespace std operator>>(basic_istream<_CharT, _Traits>& __is, basic_string<_CharT, _Traits, _Alloc>& __str); + template<> + basic_istream<char>& + operator>>(basic_istream<char>& __is, basic_string<char>& __str); + /** * @brief Write string to a stream. * @param os Output stream. @@ -2322,9 +2395,14 @@ namespace std * writing a C string. */ template<typename _CharT, typename _Traits, typename _Alloc> - basic_ostream<_CharT, _Traits>& + inline basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, - const basic_string<_CharT, _Traits, _Alloc>& __str); + const basic_string<_CharT, _Traits, _Alloc>& __str) + { + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 586. string inserter not a formatted function + return __ostream_insert(__os, __str.data(), __str.size()); + } /** * @brief Read a line from stream into a string. @@ -2340,7 +2418,7 @@ namespace std * delim was encountered, it is extracted but not stored into @a str. */ template<typename _CharT, typename _Traits, typename _Alloc> - basic_istream<_CharT,_Traits>& + basic_istream<_CharT, _Traits>& getline(basic_istream<_CharT, _Traits>& __is, basic_string<_CharT, _Traits, _Alloc>& __str, _CharT __delim); @@ -2357,9 +2435,23 @@ namespace std * encountered, it is extracted but not stored into @a str. */ template<typename _CharT, typename _Traits, typename _Alloc> - inline basic_istream<_CharT,_Traits>& + inline basic_istream<_CharT, _Traits>& getline(basic_istream<_CharT, _Traits>& __is, - basic_string<_CharT, _Traits, _Alloc>& __str); -} // namespace std + basic_string<_CharT, _Traits, _Alloc>& __str) + { return getline(__is, __str, __is.widen('\n')); } + + template<> + basic_istream<char>& + getline(basic_istream<char>& __in, basic_string<char>& __str, + char __delim); + +#ifdef _GLIBCXX_USE_WCHAR_T + template<> + basic_istream<wchar_t>& + getline(basic_istream<wchar_t>& __in, basic_string<wchar_t>& __str, + wchar_t __delim); +#endif + +_GLIBCXX_END_NAMESPACE #endif /* _BASIC_STRING_H */ diff --git a/contrib/libstdc++/include/bits/basic_string.tcc b/contrib/libstdc++/include/bits/basic_string.tcc index fc90111..c2798ef 100644 --- a/contrib/libstdc++/include/bits/basic_string.tcc +++ b/contrib/libstdc++/include/bits/basic_string.tcc @@ -1,6 +1,7 @@ // Components for manipulating sequences of characters -*- C++ -*- -// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004 +// 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 @@ -16,7 +17,7 @@ // 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// 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 @@ -28,13 +29,15 @@ // invalidate any other reasons why the executable file might be covered by // the GNU General Public License. +/** @file basic_string.tcc + * This is an internal header file, included by other library headers. + * You should not attempt to use it directly. + */ + // // ISO C++ 14882: 21 Strings library // -// This file is included by <string>. It is not meant to be included -// separately. - // Written by Jason Merrill based upon the specification by Takanori Adachi // in ANSI X3J16/94-0013R2. Rewritten by Nathan Myers to ISO-14882. @@ -43,8 +46,8 @@ #pragma GCC system_header -namespace std -{ +_GLIBCXX_BEGIN_NAMESPACE(std) + template<typename _Type> inline bool __is_null_pointer(_Type* __ptr) @@ -101,7 +104,7 @@ namespace std ++__beg; } _Rep* __r = _Rep::_S_create(__len, size_type(0), __a); - traits_type::copy(__r->_M_refdata(), __buf, __len); + _M_copy(__r->_M_refdata(), __buf, __len); try { while (__beg != __end) @@ -110,8 +113,7 @@ namespace std { // Allocate more space. _Rep* __another = _Rep::_S_create(__len + 1, __len, __a); - traits_type::copy(__another->_M_refdata(), - __r->_M_refdata(), __len); + _M_copy(__another->_M_refdata(), __r->_M_refdata(), __len); __r->_M_destroy(__a); __r = __another; } @@ -124,8 +126,7 @@ namespace std __r->_M_destroy(__a); __throw_exception_again; } - __r->_M_length = __len; - __r->_M_refdata()[__len] = _Rep::_S_terminal; // grrr. + __r->_M_set_length_and_sharable(__len); return __r->_M_refdata(); } @@ -155,8 +156,7 @@ namespace std __r->_M_destroy(__a); __throw_exception_again; } - __r->_M_length = __dnew; - __r->_M_refdata()[__dnew] = _Rep::_S_terminal; // grrr. + __r->_M_set_length_and_sharable(__dnew); return __r->_M_refdata(); } @@ -172,10 +172,9 @@ namespace std // Check for out_of_range and length_error exceptions. _Rep* __r = _Rep::_S_create(__n, size_type(0), __a); if (__n) - traits_type::assign(__r->_M_refdata(), __n, __c); + _M_assign(__r->_M_refdata(), __n, __c); - __r->_M_length = __n; - __r->_M_refdata()[__n] = _Rep::_S_terminal; // grrr + __r->_M_set_length_and_sharable(__n); return __r->_M_refdata(); } @@ -259,32 +258,107 @@ namespace std return *this; } - template<typename _CharT, typename _Traits, typename _Alloc> - basic_string<_CharT, _Traits, _Alloc>& - basic_string<_CharT, _Traits, _Alloc>:: - assign(const _CharT* __s, size_type __n) - { - __glibcxx_requires_string_len(__s, __n); - if (__n > this->max_size()) - __throw_length_error(__N("basic_string::assign")); - if (_M_rep()->_M_is_shared() || less<const _CharT*>()(__s, _M_data()) - || less<const _CharT*>()(_M_data() + this->size(), __s)) - return _M_replace_safe(size_type(0), this->size(), __s, __n); - else - { - // Work in-place - const size_type __pos = __s - _M_data(); - if (__pos >= __n) - traits_type::copy(_M_data(), __s, __n); - else if (__pos) - traits_type::move(_M_data(), __s, __n); - _M_rep()->_M_set_sharable(); - _M_rep()->_M_length = __n; - _M_data()[__n] = _Rep::_S_terminal; // grr. - return *this; - } + template<typename _CharT, typename _Traits, typename _Alloc> + basic_string<_CharT, _Traits, _Alloc>& + basic_string<_CharT, _Traits, _Alloc>:: + assign(const _CharT* __s, size_type __n) + { + __glibcxx_requires_string_len(__s, __n); + _M_check_length(this->size(), __n, "basic_string::assign"); + if (_M_disjunct(__s) || _M_rep()->_M_is_shared()) + return _M_replace_safe(size_type(0), this->size(), __s, __n); + else + { + // Work in-place. + const size_type __pos = __s - _M_data(); + if (__pos >= __n) + _M_copy(_M_data(), __s, __n); + else if (__pos) + _M_move(_M_data(), __s, __n); + _M_rep()->_M_set_length_and_sharable(__n); + return *this; + } } + template<typename _CharT, typename _Traits, typename _Alloc> + basic_string<_CharT, _Traits, _Alloc>& + basic_string<_CharT, _Traits, _Alloc>:: + append(size_type __n, _CharT __c) + { + if (__n) + { + _M_check_length(size_type(0), __n, "basic_string::append"); + const size_type __len = __n + this->size(); + if (__len > this->capacity() || _M_rep()->_M_is_shared()) + this->reserve(__len); + _M_assign(_M_data() + this->size(), __n, __c); + _M_rep()->_M_set_length_and_sharable(__len); + } + return *this; + } + + template<typename _CharT, typename _Traits, typename _Alloc> + basic_string<_CharT, _Traits, _Alloc>& + basic_string<_CharT, _Traits, _Alloc>:: + append(const _CharT* __s, size_type __n) + { + __glibcxx_requires_string_len(__s, __n); + if (__n) + { + _M_check_length(size_type(0), __n, "basic_string::append"); + const size_type __len = __n + this->size(); + if (__len > this->capacity() || _M_rep()->_M_is_shared()) + { + if (_M_disjunct(__s)) + this->reserve(__len); + else + { + const size_type __off = __s - _M_data(); + this->reserve(__len); + __s = _M_data() + __off; + } + } + _M_copy(_M_data() + this->size(), __s, __n); + _M_rep()->_M_set_length_and_sharable(__len); + } + return *this; + } + + template<typename _CharT, typename _Traits, typename _Alloc> + basic_string<_CharT, _Traits, _Alloc>& + basic_string<_CharT, _Traits, _Alloc>:: + append(const basic_string& __str) + { + const size_type __size = __str.size(); + if (__size) + { + const size_type __len = __size + this->size(); + if (__len > this->capacity() || _M_rep()->_M_is_shared()) + this->reserve(__len); + _M_copy(_M_data() + this->size(), __str._M_data(), __size); + _M_rep()->_M_set_length_and_sharable(__len); + } + return *this; + } + + template<typename _CharT, typename _Traits, typename _Alloc> + basic_string<_CharT, _Traits, _Alloc>& + basic_string<_CharT, _Traits, _Alloc>:: + append(const basic_string& __str, size_type __pos, size_type __n) + { + __str._M_check(__pos, "basic_string::append"); + __n = __str._M_limit(__pos, __n); + if (__n) + { + const size_type __len = __n + this->size(); + if (__len > this->capacity() || _M_rep()->_M_is_shared()) + this->reserve(__len); + _M_copy(_M_data() + this->size(), __str._M_data() + __pos, __n); + _M_rep()->_M_set_length_and_sharable(__len); + } + return *this; + } + template<typename _CharT, typename _Traits, typename _Alloc> basic_string<_CharT, _Traits, _Alloc>& basic_string<_CharT, _Traits, _Alloc>:: @@ -292,29 +366,25 @@ namespace std { __glibcxx_requires_string_len(__s, __n); _M_check(__pos, "basic_string::insert"); - if (this->max_size() - this->size() < __n) - __throw_length_error(__N("basic_string::insert")); - if (_M_rep()->_M_is_shared() || less<const _CharT*>()(__s, _M_data()) - || less<const _CharT*>()(_M_data() + this->size(), __s)) + _M_check_length(size_type(0), __n, "basic_string::insert"); + if (_M_disjunct(__s) || _M_rep()->_M_is_shared()) return _M_replace_safe(__pos, size_type(0), __s, __n); else { - // Work in-place. If _M_mutate reallocates the string, __s - // does not point anymore to valid data, therefore we save its - // offset, then we restore it. + // Work in-place. const size_type __off = __s - _M_data(); _M_mutate(__pos, 0, __n); __s = _M_data() + __off; _CharT* __p = _M_data() + __pos; if (__s + __n <= __p) - traits_type::copy(__p, __s, __n); + _M_copy(__p, __s, __n); else if (__s >= __p) - traits_type::copy(__p, __s + __n, __n); + _M_copy(__p, __s + __n, __n); else { const size_type __nleft = __p - __s; - traits_type::copy(__p, __s, __nleft); - traits_type::copy(__p + __nleft, __p + __n, __n - __nleft); + _M_copy(__p, __s, __nleft); + _M_copy(__p + __nleft, __p + __n, __n - __nleft); } return *this; } @@ -329,24 +399,18 @@ namespace std __glibcxx_requires_string_len(__s, __n2); _M_check(__pos, "basic_string::replace"); __n1 = _M_limit(__pos, __n1); - if (this->max_size() - (this->size() - __n1) < __n2) - __throw_length_error(__N("basic_string::replace")); + _M_check_length(__n1, __n2, "basic_string::replace"); bool __left; - if (_M_rep()->_M_is_shared() || less<const _CharT*>()(__s, _M_data()) - || less<const _CharT*>()(_M_data() + this->size(), __s)) + if (_M_disjunct(__s) || _M_rep()->_M_is_shared()) return _M_replace_safe(__pos, __n1, __s, __n2); else if ((__left = __s + __n2 <= _M_data() + __pos) || _M_data() + __pos + __n1 <= __s) { // Work in-place: non-overlapping case. - const size_type __off = __s - _M_data(); + size_type __off = __s - _M_data(); + __left ? __off : (__off += __n2 - __n1); _M_mutate(__pos, __n1, __n2); - if (__left) - traits_type::copy(_M_data() + __pos, - _M_data() + __off, __n2); - else - traits_type::copy(_M_data() + __pos, - _M_data() + __off + __n2 - __n1, __n2); + _M_copy(_M_data() + __pos, _M_data() + __off, __n2); return *this; } else @@ -362,10 +426,6 @@ namespace std basic_string<_CharT, _Traits, _Alloc>::_Rep:: _M_destroy(const _Alloc& __a) throw () { -#ifndef _GLIBCXX_FULLY_DYNAMIC_STRING - if (this == &_S_empty_rep()) - return; -#endif const size_type __size = sizeof(_Rep_base) + (this->_M_capacity + 1) * sizeof(_CharT); _Raw_bytes_alloc(__a).deallocate(reinterpret_cast<char*>(this), __size); @@ -373,7 +433,8 @@ namespace std template<typename _CharT, typename _Traits, typename _Alloc> void - basic_string<_CharT, _Traits, _Alloc>::_M_leak_hard() + basic_string<_CharT, _Traits, _Alloc>:: + _M_leak_hard() { #ifndef _GLIBCXX_FULLY_DYNAMIC_STRING if (_M_rep() == &_S_empty_rep()) @@ -393,41 +454,37 @@ namespace std const size_type __new_size = __old_size + __len2 - __len1; const size_type __how_much = __old_size - __pos - __len1; - if (__new_size > capacity() || _M_rep()->_M_is_shared()) + if (__new_size > this->capacity() || _M_rep()->_M_is_shared()) { // Must reallocate. const allocator_type __a = get_allocator(); - _Rep* __r = _Rep::_S_create(__new_size, capacity(), __a); + _Rep* __r = _Rep::_S_create(__new_size, this->capacity(), __a); if (__pos) - traits_type::copy(__r->_M_refdata(), _M_data(), __pos); + _M_copy(__r->_M_refdata(), _M_data(), __pos); if (__how_much) - traits_type::copy(__r->_M_refdata() + __pos + __len2, - _M_data() + __pos + __len1, __how_much); + _M_copy(__r->_M_refdata() + __pos + __len2, + _M_data() + __pos + __len1, __how_much); _M_rep()->_M_dispose(__a); _M_data(__r->_M_refdata()); } else if (__how_much && __len1 != __len2) { - // Work in-place - traits_type::move(_M_data() + __pos + __len2, - _M_data() + __pos + __len1, __how_much); + // Work in-place. + _M_move(_M_data() + __pos + __len2, + _M_data() + __pos + __len1, __how_much); } - _M_rep()->_M_set_sharable(); - _M_rep()->_M_length = __new_size; - _M_data()[__new_size] = _Rep::_S_terminal; // grrr. (per 21.3.4) - // You cannot leave those LWG people alone for a second. + _M_rep()->_M_set_length_and_sharable(__new_size); } template<typename _CharT, typename _Traits, typename _Alloc> void - basic_string<_CharT, _Traits, _Alloc>::reserve(size_type __res) + basic_string<_CharT, _Traits, _Alloc>:: + reserve(size_type __res) { if (__res != this->capacity() || _M_rep()->_M_is_shared()) { - if (__res > this->max_size()) - __throw_length_error(__N("basic_string::reserve")); // Make sure we don't shrink below the current size if (__res < this->size()) __res = this->size(); @@ -439,7 +496,9 @@ namespace std } template<typename _CharT, typename _Traits, typename _Alloc> - void basic_string<_CharT, _Traits, _Alloc>::swap(basic_string& __s) + void + basic_string<_CharT, _Traits, _Alloc>:: + swap(basic_string& __s) { if (_M_rep()->_M_is_leaked()) _M_rep()->_M_set_sharable(); @@ -469,7 +528,6 @@ namespace std _S_create(size_type __capacity, size_type __old_capacity, const _Alloc& __alloc) { - typedef basic_string<_CharT, _Traits, _Alloc> __string_type; // _GLIBCXX_RESOLVE_LIB_DEFECTS // 83. String::npos vs. string::max_size() if (__capacity > _S_max_size) @@ -498,9 +556,8 @@ namespace std // low-balling it (especially when this algorithm is used with // malloc implementations that allocate memory blocks rounded up // to a size which is a power of 2). - const size_type __pagesize = 4096; // must be 2^i * __subpagesize - const size_type __subpagesize = 128; // should be >> __malloc_header_size - const size_type __malloc_header_size = 4 * sizeof (void*); + const size_type __pagesize = 4096; + const size_type __malloc_header_size = 4 * sizeof(void*); // The below implements an exponential growth policy, necessary to // meet amortized linear time requirements of the library: see @@ -508,14 +565,7 @@ namespace std // It's active for allocations requiring an amount of memory above // system pagesize. This is consistent with the requirements of the // standard: http://gcc.gnu.org/ml/libstdc++/2001-07/msg00130.html - - // The biggest string which fits in a memory page - const size_type __page_capacity = ((__pagesize - __malloc_header_size - - sizeof(_Rep) - sizeof(_CharT)) - / sizeof(_CharT)); - - if (__capacity > __old_capacity && __capacity < 2 * __old_capacity - && __capacity > __page_capacity) + if (__capacity > __old_capacity && __capacity < 2 * __old_capacity) __capacity = 2 * __old_capacity; // NB: Need an array of char_type[__capacity], plus a terminating @@ -524,7 +574,7 @@ namespace std size_type __size = (__capacity + 1) * sizeof(_CharT) + sizeof(_Rep); const size_type __adj_size = __size + __malloc_header_size; - if (__adj_size > __pagesize) + if (__adj_size > __pagesize && __capacity > __old_capacity) { const size_type __extra = __pagesize - __adj_size % __pagesize; __capacity += __extra / sizeof(_CharT); @@ -533,20 +583,20 @@ namespace std __capacity = _S_max_size; __size = (__capacity + 1) * sizeof(_CharT) + sizeof(_Rep); } - else if (__size > __subpagesize) - { - const size_type __extra = __subpagesize - __adj_size % __subpagesize; - __capacity += __extra / sizeof(_CharT); - __size = (__capacity + 1) * sizeof(_CharT) + sizeof(_Rep); - } // NB: Might throw, but no worries about a leak, mate: _Rep() // does not throw. void* __place = _Raw_bytes_alloc(__alloc).allocate(__size); _Rep *__p = new (__place) _Rep; __p->_M_capacity = __capacity; - __p->_M_set_sharable(); // One reference. - __p->_M_length = 0; + // ABI compatibility - 3.4.x set in _S_create both + // _M_refcount and _M_length. All callers of _S_create + // in basic_string.tcc then set just _M_length. + // In 4.0.x and later both _M_refcount and _M_length + // are initialized in the callers, unfortunately we can + // have 3.4.x compiled code with _S_create callers inlined + // calling 4.0.x+ _S_create. + __p->_M_set_sharable(); return __p; } @@ -560,21 +610,19 @@ namespace std _Rep* __r = _Rep::_S_create(__requested_cap, this->_M_capacity, __alloc); if (this->_M_length) - traits_type::copy(__r->_M_refdata(), _M_refdata(), - this->_M_length); + _M_copy(__r->_M_refdata(), _M_refdata(), this->_M_length); - __r->_M_length = this->_M_length; - __r->_M_refdata()[this->_M_length] = _Rep::_S_terminal; + __r->_M_set_length_and_sharable(this->_M_length); return __r->_M_refdata(); } template<typename _CharT, typename _Traits, typename _Alloc> void - basic_string<_CharT, _Traits, _Alloc>::resize(size_type __n, _CharT __c) + basic_string<_CharT, _Traits, _Alloc>:: + resize(size_type __n, _CharT __c) { - if (__n > max_size()) - __throw_length_error(__N("basic_string::resize")); const size_type __size = this->size(); + _M_check_length(__size, __n, "basic_string::resize"); if (__size < __n) this->append(__n - __size, __c); else if (__n < __size) @@ -591,8 +639,7 @@ namespace std { const basic_string __s(__k1, __k2); const size_type __n1 = __i2 - __i1; - if (this->max_size() - (this->size() - __n1) < __s.size()) - __throw_length_error(__N("basic_string::_M_replace_dispatch")); + _M_check_length(__n1, __s.size(), "basic_string::_M_replace_dispatch"); return _M_replace_safe(__i1 - _M_ibegin(), __n1, __s._M_data(), __s.size()); } @@ -600,48 +647,28 @@ namespace std template<typename _CharT, typename _Traits, typename _Alloc> basic_string<_CharT, _Traits, _Alloc>& basic_string<_CharT, _Traits, _Alloc>:: - append(const basic_string& __str) + _M_replace_aux(size_type __pos1, size_type __n1, size_type __n2, + _CharT __c) { - // Iff appending itself, string needs to pre-reserve the - // correct size so that _M_mutate does not clobber the - // pointer __str._M_data() formed here. - const size_type __size = __str.size(); - const size_type __len = __size + this->size(); - if (__len > this->capacity()) - this->reserve(__len); - return _M_replace_safe(this->size(), size_type(0), __str._M_data(), - __str.size()); + _M_check_length(__n1, __n2, "basic_string::_M_replace_aux"); + _M_mutate(__pos1, __n1, __n2); + if (__n2) + _M_assign(_M_data() + __pos1, __n2, __c); + return *this; } template<typename _CharT, typename _Traits, typename _Alloc> basic_string<_CharT, _Traits, _Alloc>& basic_string<_CharT, _Traits, _Alloc>:: - append(const basic_string& __str, size_type __pos, size_type __n) + _M_replace_safe(size_type __pos1, size_type __n1, const _CharT* __s, + size_type __n2) { - // Iff appending itself, string needs to pre-reserve the - // correct size so that _M_mutate does not clobber the - // pointer __str._M_data() formed here. - __str._M_check(__pos, "basic_string::append"); - __n = __str._M_limit(__pos, __n); - const size_type __len = __n + this->size(); - if (__len > this->capacity()) - this->reserve(__len); - return _M_replace_safe(this->size(), size_type(0), __str._M_data() - + __pos, __n); - } - - template<typename _CharT, typename _Traits, typename _Alloc> - basic_string<_CharT, _Traits, _Alloc>& - basic_string<_CharT, _Traits, _Alloc>:: - append(const _CharT* __s, size_type __n) - { - __glibcxx_requires_string_len(__s, __n); - const size_type __len = __n + this->size(); - if (__len > this->capacity()) - this->reserve(__len); - return _M_replace_safe(this->size(), size_type(0), __s, __n); + _M_mutate(__pos1, __n1, __n2); + if (__n2) + _M_copy(_M_data() + __pos1, __s, __n2); + return *this; } - + template<typename _CharT, typename _Traits, typename _Alloc> basic_string<_CharT, _Traits, _Alloc> operator+(const _CharT* __lhs, @@ -681,7 +708,7 @@ namespace std __n = _M_limit(__pos, __n); __glibcxx_requires_string_len(__s, __n); if (__n) - traits_type::copy(__s, _M_data() + __pos, __n); + _M_copy(__s, _M_data() + __pos, __n); // 21.3.5.7 par 3: do not append null. (good.) return __n; } @@ -694,9 +721,18 @@ namespace std __glibcxx_requires_string_len(__s, __n); const size_type __size = this->size(); const _CharT* __data = _M_data(); - for (; __pos + __n <= __size; ++__pos) - if (traits_type::compare(__data + __pos, __s, __n) == 0) - return __pos; + + if (__n == 0) + return __pos <= __size ? __pos : npos; + + if (__n <= __size) + { + for (; __pos <= __size - __n; ++__pos) + if (traits_type::eq(__data[__pos], __s[0]) + && traits_type::compare(__data + __pos + 1, + __s + 1, __n - 1) == 0) + return __pos; + } return npos; } @@ -705,8 +741,8 @@ namespace std basic_string<_CharT, _Traits, _Alloc>:: find(_CharT __c, size_type __pos) const { - const size_type __size = this->size(); size_type __ret = npos; + const size_type __size = this->size(); if (__pos < __size) { const _CharT* __data = _M_data(); @@ -970,6 +1006,7 @@ namespace std getline(basic_istream<wchar_t>&, wstring&); #endif #endif -} // namespace std + +_GLIBCXX_END_NAMESPACE #endif diff --git a/contrib/libstdc++/include/bits/boost_concept_check.h b/contrib/libstdc++/include/bits/boost_concept_check.h index ff154f7..3d8fe75 100644 --- a/contrib/libstdc++/include/bits/boost_concept_check.h +++ b/contrib/libstdc++/include/bits/boost_concept_check.h @@ -1,4 +1,6 @@ -// Copyright (C) 2004 Free Software Foundation, Inc. +// -*- C++ -*- + +// Copyright (C) 2004, 2005 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 @@ -13,7 +15,7 @@ // 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// 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 @@ -32,13 +34,13 @@ // to its suitability for any purpose. // -// GCC Note: based on version 1.12.0 of the Boost library. - /** @file boost_concept_check.h * This is an internal header file, included by other library headers. * You should not attempt to use it directly. */ +// GCC Note: based on version 1.12.0 of the Boost library. + #ifndef _BOOST_CONCEPT_CHECK_H #define _BOOST_CONCEPT_CHECK_H 1 @@ -48,8 +50,7 @@ #include <bits/stl_iterator_base_types.h> // for traits and tags #include <utility> // for pair<> -namespace __gnu_cxx -{ +_GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) #define _IsUnused __attribute__ ((__unused__)) @@ -923,7 +924,7 @@ struct _Aux_require_same<_Tp,_Tp> { typedef _Tp _Type; }; // HashedAssociativeContainer -} // namespace __gnu_cxx +_GLIBCXX_END_NAMESPACE #undef _IsUnused diff --git a/contrib/libstdc++/include/bits/c++config b/contrib/libstdc++/include/bits/c++config index 15e4b28..cf20c1b 100644 --- a/contrib/libstdc++/include/bits/c++config +++ b/contrib/libstdc++/include/bits/c++config @@ -1,6 +1,7 @@ // Predefined symbols and macros -*- C++ -*- -// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004 +// 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 @@ -16,7 +17,7 @@ // 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// 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 @@ -28,14 +29,137 @@ // invalidate any other reasons why the executable file might be covered by // the GNU General Public License. +/** @file c++config.h + * This is an internal header file, included by other library headers. + * You should not attempt to use it directly. + */ + #ifndef _CXXCONFIG #define _CXXCONFIG 1 // Pick up any OS-specific definitions. #include <bits/os_defines.h> +// Pick up any CPU-specific definitions. +#include <bits/cpu_defines.h> + // The current version of the C++ library in compressed ISO date format. -#define __GLIBCXX__ 20060311 +#define __GLIBCXX__ + +// Macros for visibility. +#define _GLIBCXX_HAVE_ATTRIBUTE_VISIBILITY + +#if _GLIBCXX_HAVE_ATTRIBUTE_VISIBILITY +#define _GLIBCXX_VISIBILITY(V) __attribute__ ((__visibility__ (#V))) +#else +#define _GLIBCXX_VISIBILITY(V) +#endif + +// Macros for controlling various namespace association schemes and modes. +#ifdef _GLIBCXX_DEBUG +# define _GLIBCXX_NAMESPACE_ASSOCIATION_DEBUG 1 +#endif + +#define _GLIBCXX_NAMESPACE_ASSOCIATION_VERSION + +// Macros for namespace scope. +// _GLIBCXX_BEGIN_NAMESPACE +// _GLIBCXX_END_NAMESPACE +// _GLIBCXX_BEGIN_NESTED_NAMESPACE +// _GLIBCXX_END_NESTED_NAMESPACE +#if _GLIBCXX_NAMESPACE_ASSOCIATION_VERSION +# define _GLIBCXX_BEGIN_NESTED_NAMESPACE(X, Y) namespace X { namespace Y _GLIBCXX_VISIBILITY(default) { +# define _GLIBCXX_END_NESTED_NAMESPACE } } +# define _GLIBCXX_BEGIN_NAMESPACE(X) _GLIBCXX_BEGIN_NESTED_NAMESPACE(X, _6) +# define _GLIBCXX_END_NAMESPACE _GLIBCXX_END_NESTED_NAMESPACE +#else +# define _GLIBCXX_BEGIN_NAMESPACE(X) namespace X _GLIBCXX_VISIBILITY(default) { +# define _GLIBCXX_END_NAMESPACE } +# if _GLIBCXX_NAMESPACE_ASSOCIATION_DEBUG +# define _GLIBCXX_BEGIN_NESTED_NAMESPACE(X, Y) namespace X { namespace Y _GLIBCXX_VISIBILITY(default) { +# define _GLIBCXX_END_NESTED_NAMESPACE } } +# else +# define _GLIBCXX_BEGIN_NESTED_NAMESPACE(X, Y) _GLIBCXX_BEGIN_NAMESPACE(X) +# define _GLIBCXX_END_NESTED_NAMESPACE _GLIBCXX_END_NAMESPACE +# endif +#endif + +// Namespace associations for versioning mode. +#if _GLIBCXX_NAMESPACE_ASSOCIATION_VERSION +namespace std +{ + namespace _6 { } + using namespace _6 __attribute__ ((strong)); +} + +// In addition, other supported namespace configurations. +namespace __gnu_cxx +{ + namespace _6 { } + using namespace _6 __attribute__ ((strong)); +} + +namespace std +{ + namespace tr1 + { + namespace _6 { } + using namespace _6 __attribute__ ((strong)); + } +} +#endif + +// Namespace associations for debug mode. +#if _GLIBCXX_NAMESPACE_ASSOCIATION_DEBUG +namespace std +{ + namespace __norm { } + namespace __debug { } + using namespace __debug __attribute__ ((strong)); +} + +namespace __gnu_cxx +{ + namespace __norm { } + namespace __debug { } + using namespace __debug __attribute__ ((strong)); +} + +# define _GLIBCXX_STD __norm +# define _GLIBCXX_EXT __norm +# define _GLIBCXX_EXTERN_TEMPLATE 0 +# if __NO_INLINE__ && !__GXX_WEAK__ +# warning debug mode without inlining may fail due to lack of weak symbols +# endif +#else +#if _GLIBCXX_NAMESPACE_ASSOCIATION_VERSION +# define _GLIBCXX_STD _6 +# define _GLIBCXX_EXT _6 +#else +# define _GLIBCXX_STD std +# define _GLIBCXX_EXT __gnu_cxx +#endif +#endif + +/* Define if compatibility should be provided for -mlong-double-64. */ +#undef _GLIBCXX_LONG_DOUBLE_COMPAT + +// XXX GLIBCXX_ABI Deprecated +// Namespace associations for long double 128 mode. +_GLIBCXX_BEGIN_NAMESPACE(std) +#if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__ +# define _GLIBCXX_LDBL_NAMESPACE __gnu_cxx_ldbl128:: +# define _GLIBCXX_BEGIN_LDBL_NAMESPACE namespace __gnu_cxx_ldbl128 { +# define _GLIBCXX_END_LDBL_NAMESPACE } + namespace __gnu_cxx_ldbl128 { } + using namespace __gnu_cxx_ldbl128 __attribute__((__strong__)); +#else +# define _GLIBCXX_LDBL_NAMESPACE +# define _GLIBCXX_BEGIN_LDBL_NAMESPACE +# define _GLIBCXX_END_LDBL_NAMESPACE +#endif +_GLIBCXX_END_NAMESPACE + // Allow use of "export template." This is currently not a feature // that g++ supports. @@ -51,31 +175,14 @@ # define _GLIBCXX_EXTERN_TEMPLATE 1 #endif -// Debug mode support. Debug mode basic_string is not allowed to be -// associated with std, because of locale and exception link -// dependence. -namespace __gnu_debug_def { } -namespace __gnu_debug -{ - using namespace __gnu_debug_def; -} - -#ifdef _GLIBCXX_DEBUG -# define _GLIBCXX_STD __gnu_norm -namespace __gnu_norm -{ - using namespace std; -} -namespace std -{ - using namespace __gnu_debug_def __attribute__ ((strong)); -} -#else -# define _GLIBCXX_STD std +// Certain function definitions that are meant to be overridable from +// user code are decorated with this macro. For some targets, this +// macro causes these definitions to be weak. +#ifndef _GLIBCXX_WEAK_DEFINITION +# define _GLIBCXX_WEAK_DEFINITION #endif - // The remainder of the prewritten config is automatic; all the // user hooks are listed above. @@ -92,4 +199,8 @@ namespace std // for something else under certain OSes (see BADNAMES). #define __N(msgid) (msgid) +// For example, <windows.h> is known to #define min and max as macros... +#undef min +#undef max + // End of prewritten config; the discovered settings follow. diff --git a/contrib/libstdc++/include/bits/char_traits.h b/contrib/libstdc++/include/bits/char_traits.h index 323fdfb..58cddf6 100644 --- a/contrib/libstdc++/include/bits/char_traits.h +++ b/contrib/libstdc++/include/bits/char_traits.h @@ -1,6 +1,6 @@ // Character Traits for use by standard string and iostream -*- C++ -*- -// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003 +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 // Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free @@ -16,7 +16,7 @@ // 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// 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 @@ -28,15 +28,15 @@ // invalidate any other reasons why the executable file might be covered by // the GNU General Public License. -// -// ISO C++ 14882: 21 Strings library -// - /** @file char_traits.h * This is an internal header file, included by other library headers. * You should not attempt to use it directly. */ +// +// ISO C++ 14882: 21 Strings library +// + #ifndef _CHAR_TRAITS_H #define _CHAR_TRAITS_H 1 @@ -46,12 +46,11 @@ #include <bits/stl_algobase.h>// For copy, lexicographical_compare, fill_n #include <bits/postypes.h> // For streampos -namespace __gnu_cxx -{ +_GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) + /** * @brief Mapping from character type to associated types. * - * * @note This is an implementation class for the generic version * of char_traits. It defines int_type, off_type, pos_type, and * state_type. By default these are unsigned long, streamoff, @@ -82,7 +81,8 @@ namespace __gnu_cxx * * See http://gcc.gnu.org/onlinedocs/libstdc++/21_strings/howto.html#5 * for advice on how to make use of this class for "unusual" character - * types. Also, check out include/ext/pod_char_traits.h. */ + * types. Also, check out include/ext/pod_char_traits.h. + */ template<typename _CharT> struct char_traits { @@ -148,7 +148,7 @@ namespace __gnu_cxx char_traits<_CharT>:: compare(const char_type* __s1, const char_type* __s2, std::size_t __n) { - for (size_t __i = 0; __i < __n; ++__i) + for (std::size_t __i = 0; __i < __n; ++__i) if (lt(__s1[__i], __s2[__i])) return -1; else if (lt(__s2[__i], __s1[__i])) @@ -204,10 +204,11 @@ namespace __gnu_cxx std::fill_n(__s, __n, __a); return __s; } -} -namespace std -{ +_GLIBCXX_END_NAMESPACE + +_GLIBCXX_BEGIN_NAMESPACE(std) + // 21.1 /** * @brief Basis for explicit traits specializations. @@ -222,12 +223,11 @@ namespace std * types. Also, check out include/ext/pod_char_traits.h. */ template<class _CharT> - struct char_traits - : public __gnu_cxx::char_traits<_CharT> + struct char_traits : public __gnu_cxx::char_traits<_CharT> { }; - /// 21.1.3.1 char_traits specializations + /// @brief 21.1.3.1 char_traits specializations template<> struct char_traits<char> { @@ -297,7 +297,7 @@ namespace std #ifdef _GLIBCXX_USE_WCHAR_T - /// 21.1.3.2 char_traits specializations + /// @brief 21.1.3.2 char_traits specializations template<> struct char_traits<wchar_t> { @@ -362,15 +362,6 @@ namespace std }; #endif //_GLIBCXX_USE_WCHAR_T - template<typename _CharT, typename _Traits> - struct _Char_traits_match - { - _CharT _M_c; - _Char_traits_match(_CharT const& __c) : _M_c(__c) { } - - bool - operator()(_CharT const& __a) { return _Traits::eq(_M_c, __a); } - }; -} // namespace std +_GLIBCXX_END_NAMESPACE #endif diff --git a/contrib/libstdc++/include/bits/codecvt.h b/contrib/libstdc++/include/bits/codecvt.h index d31ebf2..d417a6f 100644 --- a/contrib/libstdc++/include/bits/codecvt.h +++ b/contrib/libstdc++/include/bits/codecvt.h @@ -1,6 +1,7 @@ // Locale support (codecvt) -*- C++ -*- -// Copyright (C) 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc. +// Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005 +// 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 @@ -15,7 +16,7 @@ // 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// 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 @@ -27,24 +28,25 @@ // invalidate any other reasons why the executable file might be covered by // the GNU General Public License. +/** @file bits/codecvt.h + * This is an internal header file, included by other library headers. + * You should not attempt to use it directly. + */ + // // ISO C++ 14882: 22.2.1.5 Template class codecvt // -// Written by Benjamin Kosnik <bkoz@cygnus.com> - -/** @file codecvt.h - * This is an internal header file, included by other library headers. - * You should not attempt to use it directly. - */ +// Written by Benjamin Kosnik <bkoz@redhat.com> #ifndef _CODECVT_H #define _CODECVT_H 1 #pragma GCC system_header - // 22.2.1.5 Template class codecvt - /// Base class for codecvt facet providing conversion result enum. +_GLIBCXX_BEGIN_NAMESPACE(std) + + /// @brief Empty base class for codecvt facet [22.2.1.5]. class codecvt_base { public: @@ -57,12 +59,8 @@ }; }; - // Template class __codecvt_abstract_base - // NB: An abstract base class that fills in the public inlines, so - // that the specializations don't have to re-copy the public - // interface. /** - * @brief Common base for codecvt facet + * @brief Common base for codecvt functions. * * This template class provides implementations of the public functions * that forward to the protected virtual functions. @@ -102,11 +100,12 @@ * beginning and carried from a previous call if continuing * conversion. There are no guarantees about how @a state is used. * - * The result returned is a member of codecvt_base::result. If all the - * input is converted, returns codecvt_base::ok. If no conversion is - * necessary, returns codecvt_base::noconv. If the input ends early or - * there is insufficient space in the output, returns codecvt_base::partial. - * Otherwise the conversion failed and codecvt_base::error is returned. + * The result returned is a member of codecvt_base::result. If + * all the input is converted, returns codecvt_base::ok. If no + * conversion is necessary, returns codecvt_base::noconv. If + * the input ends early or there is insufficient space in the + * output, returns codecvt_base::partial. Otherwise the + * conversion failed and codecvt_base::error is returned. * * @param state Persistent conversion state data. * @param from Start of input. @@ -181,11 +180,12 @@ * beginning and carried from a previous call if continuing * conversion. There are no guarantees about how @a state is used. * - * The result returned is a member of codecvt_base::result. If all the - * input is converted, returns codecvt_base::ok. If no conversion is - * necessary, returns codecvt_base::noconv. If the input ends early or - * there is insufficient space in the output, returns codecvt_base::partial. - * Otherwise the conversion failed and codecvt_base::error is returned. + * The result returned is a member of codecvt_base::result. If + * all the input is converted, returns codecvt_base::ok. If no + * conversion is necessary, returns codecvt_base::noconv. If + * the input ends early or there is insufficient space in the + * output, returns codecvt_base::partial. Otherwise the + * conversion failed and codecvt_base::error is returned. * * @param state Persistent conversion state data. * @param from Start of input. @@ -267,8 +267,8 @@ do_max_length() const throw() = 0; }; - // 22.2.1.5 Template class codecvt - // NB: Generic, mostly useless implementation. + /// @brief class codecvt [22.2.1.5]. + /// NB: Generic, mostly useless implementation. template<typename _InternT, typename _ExternT, typename _StateT> class codecvt : public __codecvt_abstract_base<_InternT, _ExternT, _StateT> @@ -330,7 +330,7 @@ template<typename _InternT, typename _ExternT, typename _StateT> locale::id codecvt<_InternT, _ExternT, _StateT>::id; - // codecvt<char, char, mbstate_t> required specialization + /// @brief class codecvt<char, char, mbstate_t> specialization. template<> class codecvt<char, char, mbstate_t> : public __codecvt_abstract_base<char, char, mbstate_t> @@ -388,7 +388,7 @@ }; #ifdef _GLIBCXX_USE_WCHAR_T - // codecvt<wchar_t, char, mbstate_t> required specialization + /// @brief class codecvt<wchar_t, char, mbstate_t> specialization. template<> class codecvt<wchar_t, char, mbstate_t> : public __codecvt_abstract_base<wchar_t, char, mbstate_t> @@ -448,7 +448,7 @@ }; #endif //_GLIBCXX_USE_WCHAR_T - // 22.2.1.6 Template class codecvt_byname + /// @brief class codecvt_byname [22.2.1.6]. template<typename _InternT, typename _ExternT, typename _StateT> class codecvt_byname : public codecvt<_InternT, _ExternT, _StateT> { @@ -469,10 +469,6 @@ ~codecvt_byname() { } }; - // Include host and configuration specific partial specializations - // with additional functionality, if possible. -#ifdef _GLIBCXX_USE_WCHAR_T - #include <bits/codecvt_specializations.h> -#endif +_GLIBCXX_END_NAMESPACE #endif // _CODECVT_H diff --git a/contrib/libstdc++/include/bits/concept_check.h b/contrib/libstdc++/include/bits/concept_check.h index 80c1439..98cb42d 100644 --- a/contrib/libstdc++/include/bits/concept_check.h +++ b/contrib/libstdc++/include/bits/concept_check.h @@ -15,7 +15,7 @@ // 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// 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 diff --git a/contrib/libstdc++/include/bits/cpp_type_traits.h b/contrib/libstdc++/include/bits/cpp_type_traits.h index d4e4ea0..ed9a48a 100644 --- a/contrib/libstdc++/include/bits/cpp_type_traits.h +++ b/contrib/libstdc++/include/bits/cpp_type_traits.h @@ -1,6 +1,7 @@ // The -*- C++ -*- type traits classes for internal use in libstdc++ -// Copyright (C) 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc. +// Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006 +// 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 @@ -15,7 +16,7 @@ // 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// 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 @@ -27,22 +28,24 @@ // invalidate any other reasons why the executable file might be covered by // the GNU General Public License. -// Written by Gabriel Dos Reis <dosreis@cmla.ens-cachan.fr> - /** @file cpp_type_traits.h * This is an internal header file, included by other library headers. * You should not attempt to use it directly. */ +// Written by Gabriel Dos Reis <dosreis@cmla.ens-cachan.fr> + #ifndef _CPP_TYPE_TRAITS_H #define _CPP_TYPE_TRAITS_H 1 #pragma GCC system_header +#include <bits/c++config.h> + // // This file provides some compile-time information about various types. // These representations were designed, on purpose, to be constant-expressions -// and not types as found in <stl/bits/type_traits.h>. In particular, they +// and not types as found in <bits/type_traits.h>. In particular, they // can be used in control structures and the optimizer hopefully will do // the obvious thing. // @@ -63,70 +66,82 @@ // // -- Gaby (dosreis@cmla.ens-cachan.fr) 2000-03-06. // +// Update 2005: types are also provided and <bits/type_traits.h> has been +// removed. +// + +// Forward declaration hack, should really include this from somewhere. +_GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) + + template<typename _Iterator, typename _Container> + class __normal_iterator; + +_GLIBCXX_END_NAMESPACE -// NB: g++ can not compile these if declared within the class -// __is_pod itself. -namespace __gnu_internal +_GLIBCXX_BEGIN_NAMESPACE(std) + +namespace __detail { + // NB: g++ can not compile these if declared within the class + // __is_pod itself. typedef char __one; typedef char __two[2]; - template <typename _Tp> - __one __test_type (int _Tp::*); - template <typename _Tp> - __two& __test_type (...); -} // namespace __gnu_internal + template<typename _Tp> + __one __test_type(int _Tp::*); + template<typename _Tp> + __two& __test_type(...); +} // namespace __detail -namespace std -{ - // Compare for equality of types. - template<typename, typename> - struct __are_same - { - enum - { - _M_type = 0 - }; - }; - template<typename _Tp> - struct __are_same<_Tp, _Tp> + struct __true_type { }; + struct __false_type { }; + + template<bool> + struct __truth_type + { typedef __false_type __type; }; + + template<> + struct __truth_type<true> + { typedef __true_type __type; }; + + // N.B. The conversions to bool are needed due to the issue + // explained in c++/19404. + template<class _Sp, class _Tp> + struct __traitor { - enum - { - _M_type = 1 - }; + enum { __value = bool(_Sp::__value) || bool(_Tp::__value) }; + typedef typename __truth_type<__value>::__type __type; }; - // Define a nested type if some predicate holds. - template<typename, bool> - struct __enable_if + // Compare for equality of types. + template<typename, typename> + struct __are_same { + enum { __value = 0 }; + typedef __false_type __type; }; template<typename _Tp> - struct __enable_if<_Tp, true> + struct __are_same<_Tp, _Tp> { - typedef _Tp _M_type; + enum { __value = 1 }; + typedef __true_type __type; }; // Holds if the template-argument is a void type. template<typename _Tp> struct __is_void { - enum - { - _M_type = 0 - }; + enum { __value = 0 }; + typedef __false_type __type; }; template<> struct __is_void<void> { - enum - { - _M_type = 1 - }; + enum { __value = 1 }; + typedef __true_type __type; }; // @@ -135,10 +150,8 @@ namespace std template<typename _Tp> struct __is_integer { - enum - { - _M_type = 0 - }; + enum { __value = 0 }; + typedef __false_type __type; }; // Thirteen specializations (yes there are eleven standard integer @@ -147,120 +160,94 @@ namespace std template<> struct __is_integer<bool> { - enum - { - _M_type = 1 - }; + enum { __value = 1 }; + typedef __true_type __type; }; template<> struct __is_integer<char> { - enum - { - _M_type = 1 - }; + enum { __value = 1 }; + typedef __true_type __type; }; template<> struct __is_integer<signed char> { - enum - { - _M_type = 1 - }; + enum { __value = 1 }; + typedef __true_type __type; }; template<> struct __is_integer<unsigned char> { - enum - { - _M_type = 1 - }; + enum { __value = 1 }; + typedef __true_type __type; }; # ifdef _GLIBCXX_USE_WCHAR_T template<> struct __is_integer<wchar_t> { - enum - { - _M_type = 1 - }; + enum { __value = 1 }; + typedef __true_type __type; }; # endif template<> struct __is_integer<short> { - enum - { - _M_type = 1 - }; + enum { __value = 1 }; + typedef __true_type __type; }; template<> struct __is_integer<unsigned short> { - enum - { - _M_type = 1 - }; + enum { __value = 1 }; + typedef __true_type __type; }; template<> struct __is_integer<int> { - enum - { - _M_type = 1 - }; + enum { __value = 1 }; + typedef __true_type __type; }; template<> struct __is_integer<unsigned int> { - enum - { - _M_type = 1 - }; + enum { __value = 1 }; + typedef __true_type __type; }; template<> struct __is_integer<long> { - enum - { - _M_type = 1 - }; + enum { __value = 1 }; + typedef __true_type __type; }; template<> struct __is_integer<unsigned long> { - enum - { - _M_type = 1 - }; + enum { __value = 1 }; + typedef __true_type __type; }; template<> struct __is_integer<long long> { - enum - { - _M_type = 1 - }; + enum { __value = 1 }; + typedef __true_type __type; }; template<> struct __is_integer<unsigned long long> { - enum - { - _M_type = 1 - }; + enum { __value = 1 }; + typedef __true_type __type; }; // @@ -269,77 +256,148 @@ namespace std template<typename _Tp> struct __is_floating { - enum - { - _M_type = 0 - }; + enum { __value = 0 }; + typedef __false_type __type; }; // three specializations (float, double and 'long double') template<> struct __is_floating<float> { - enum - { - _M_type = 1 - }; + enum { __value = 1 }; + typedef __true_type __type; }; template<> struct __is_floating<double> { - enum - { - _M_type = 1 - }; + enum { __value = 1 }; + typedef __true_type __type; }; template<> struct __is_floating<long double> { - enum - { - _M_type = 1 - }; + enum { __value = 1 }; + typedef __true_type __type; }; // - // An arithmetic type is an integer type or a floating point type + // Pointer types // template<typename _Tp> - struct __is_arithmetic + struct __is_pointer { - enum - { - _M_type = __is_integer<_Tp>::_M_type || __is_floating<_Tp>::_M_type - }; + enum { __value = 0 }; + typedef __false_type __type; + }; + + template<typename _Tp> + struct __is_pointer<_Tp*> + { + enum { __value = 1 }; + typedef __true_type __type; + }; + + // + // Normal iterator type + // + template<typename _Tp> + struct __is_normal_iterator + { + enum { __value = 0 }; + typedef __false_type __type; }; - + + template<typename _Iterator, typename _Container> + struct __is_normal_iterator< __gnu_cxx::__normal_iterator<_Iterator, + _Container> > + { + enum { __value = 1 }; + typedef __true_type __type; + }; + + // + // An arithmetic type is an integer type or a floating point type + // + template<typename _Tp> + struct __is_arithmetic + : public __traitor<__is_integer<_Tp>, __is_floating<_Tp> > + { }; + // // A fundamental type is `void' or and arithmetic type // template<typename _Tp> struct __is_fundamental + : public __traitor<__is_void<_Tp>, __is_arithmetic<_Tp> > + { }; + + // + // A scalar type is an arithmetic type or a pointer type + // + template<typename _Tp> + struct __is_scalar + : public __traitor<__is_arithmetic<_Tp>, __is_pointer<_Tp> > + { }; + + // For the immediate use, the following is a good approximation. + template<typename _Tp> + struct __is_pod { enum { - _M_type = __is_void<_Tp>::_M_type || __is_arithmetic<_Tp>::_M_type + __value = (sizeof(__detail::__test_type<_Tp>(0)) + != sizeof(__detail::__one)) }; }; // - // For the immediate use, the following is a good approximation + // A stripped-down version of std::tr1::is_empty // template<typename _Tp> - struct __is_pod - { + struct __is_empty + { + private: + template<typename> + struct __first { }; + template<typename _Up> + struct __second + : public _Up { }; + + public: enum { - _M_type = (sizeof(__gnu_internal::__test_type<_Tp>(0)) - != sizeof(__gnu_internal::__one)) + __value = sizeof(__first<_Tp>) == sizeof(__second<_Tp>) }; }; -} // namespace std + // + // For use in std::copy and std::find overloads for streambuf iterators. + // + template<typename _Tp> + struct __is_char + { + enum { __value = 0 }; + typedef __false_type __type; + }; + + template<> + struct __is_char<char> + { + enum { __value = 1 }; + typedef __true_type __type; + }; + +#ifdef _GLIBCXX_USE_WCHAR_T + template<> + struct __is_char<wchar_t> + { + enum { __value = 1 }; + typedef __true_type __type; + }; +#endif + +_GLIBCXX_END_NAMESPACE #endif //_CPP_TYPE_TRAITS_H diff --git a/contrib/libstdc++/include/bits/deque.tcc b/contrib/libstdc++/include/bits/deque.tcc index e8e0438..3f53f20 100644 --- a/contrib/libstdc++/include/bits/deque.tcc +++ b/contrib/libstdc++/include/bits/deque.tcc @@ -1,6 +1,7 @@ // Deque implementation (out of line) -*- C++ -*- -// Copyright (C) 2001, 2002, 2003, 2004 Free Software Foundation, Inc. +// Copyright (C) 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 @@ -15,7 +16,7 @@ // 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// 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 @@ -61,19 +62,19 @@ #ifndef _DEQUE_TCC #define _DEQUE_TCC 1 -namespace _GLIBCXX_STD -{ +_GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD) + template <typename _Tp, typename _Alloc> - deque<_Tp,_Alloc>& - deque<_Tp,_Alloc>:: + deque<_Tp, _Alloc>& + deque<_Tp, _Alloc>:: operator=(const deque& __x) { const size_type __len = size(); if (&__x != this) { if (__len >= __x.size()) - erase(std::copy(__x.begin(), __x.end(), this->_M_impl._M_start), - this->_M_impl._M_finish); + _M_erase_at_end(std::copy(__x.begin(), __x.end(), + this->_M_impl._M_start)); else { const_iterator __mid = __x.begin() + difference_type(__len); @@ -85,16 +86,16 @@ namespace _GLIBCXX_STD } template <typename _Tp, typename _Alloc> - typename deque<_Tp,_Alloc>::iterator - deque<_Tp,_Alloc>:: - insert(iterator position, const value_type& __x) + typename deque<_Tp, _Alloc>::iterator + deque<_Tp, _Alloc>:: + insert(iterator __position, const value_type& __x) { - if (position._M_cur == this->_M_impl._M_start._M_cur) + if (__position._M_cur == this->_M_impl._M_start._M_cur) { push_front(__x); return this->_M_impl._M_start; } - else if (position._M_cur == this->_M_impl._M_finish._M_cur) + else if (__position._M_cur == this->_M_impl._M_finish._M_cur) { push_back(__x); iterator __tmp = this->_M_impl._M_finish; @@ -102,109 +103,81 @@ namespace _GLIBCXX_STD return __tmp; } else - return _M_insert_aux(position, __x); + return _M_insert_aux(__position, __x); } template <typename _Tp, typename _Alloc> - typename deque<_Tp,_Alloc>::iterator - deque<_Tp,_Alloc>:: + typename deque<_Tp, _Alloc>::iterator + deque<_Tp, _Alloc>:: erase(iterator __position) { iterator __next = __position; ++__next; - size_type __index = __position - this->_M_impl._M_start; - if (__index < (size() >> 1)) + const difference_type __index = __position - begin(); + if (static_cast<size_type>(__index) < (size() >> 1)) { - std::copy_backward(this->_M_impl._M_start, __position, __next); + if (__position != begin()) + std::copy_backward(begin(), __position, __next); pop_front(); } else { - std::copy(__next, this->_M_impl._M_finish, __position); + if (__next != end()) + std::copy(__next, end(), __position); pop_back(); } - return this->_M_impl._M_start + __index; + return begin() + __index; } template <typename _Tp, typename _Alloc> - typename deque<_Tp,_Alloc>::iterator - deque<_Tp,_Alloc>:: + typename deque<_Tp, _Alloc>::iterator + deque<_Tp, _Alloc>:: erase(iterator __first, iterator __last) { - if (__first == this->_M_impl._M_start && __last == this->_M_impl._M_finish) + if (__first == begin() && __last == end()) { clear(); - return this->_M_impl._M_finish; + return end(); } else { const difference_type __n = __last - __first; - const difference_type __elems_before = __first - this->_M_impl._M_start; - if (static_cast<size_type>(__elems_before) < (size() - __n) / 2) + const difference_type __elems_before = __first - begin(); + if (static_cast<size_type>(__elems_before) <= (size() - __n) / 2) { - std::copy_backward(this->_M_impl._M_start, __first, __last); - iterator __new_start = this->_M_impl._M_start + __n; - std::_Destroy(this->_M_impl._M_start, __new_start); - _M_destroy_nodes(this->_M_impl._M_start._M_node, __new_start._M_node); - this->_M_impl._M_start = __new_start; + if (__first != begin()) + std::copy_backward(begin(), __first, __last); + _M_erase_at_begin(begin() + __n); } else { - std::copy(__last, this->_M_impl._M_finish, __first); - iterator __new_finish = this->_M_impl._M_finish - __n; - std::_Destroy(__new_finish, this->_M_impl._M_finish); - _M_destroy_nodes(__new_finish._M_node + 1, - this->_M_impl._M_finish._M_node + 1); - this->_M_impl._M_finish = __new_finish; + if (__last != end()) + std::copy(__last, end(), __first); + _M_erase_at_end(end() - __n); } - return this->_M_impl._M_start + __elems_before; - } - } - - template <typename _Tp, typename _Alloc> - void - deque<_Tp,_Alloc>:: - clear() - { - for (_Map_pointer __node = this->_M_impl._M_start._M_node + 1; - __node < this->_M_impl._M_finish._M_node; - ++__node) - { - std::_Destroy(*__node, *__node + _S_buffer_size()); - _M_deallocate_node(*__node); - } - - if (this->_M_impl._M_start._M_node != this->_M_impl._M_finish._M_node) - { - std::_Destroy(this->_M_impl._M_start._M_cur, this->_M_impl._M_start._M_last); - std::_Destroy(this->_M_impl._M_finish._M_first, this->_M_impl._M_finish._M_cur); - _M_deallocate_node(this->_M_impl._M_finish._M_first); + return begin() + __elems_before; } - else - std::_Destroy(this->_M_impl._M_start._M_cur, this->_M_impl._M_finish._M_cur); - - this->_M_impl._M_finish = this->_M_impl._M_start; } template <typename _Tp, class _Alloc> template <typename _InputIterator> void - deque<_Tp,_Alloc> - ::_M_assign_aux(_InputIterator __first, _InputIterator __last, - input_iterator_tag) + deque<_Tp, _Alloc>:: + _M_assign_aux(_InputIterator __first, _InputIterator __last, + std::input_iterator_tag) { iterator __cur = begin(); - for ( ; __first != __last && __cur != end(); ++__cur, ++__first) + for (; __first != __last && __cur != end(); ++__cur, ++__first) *__cur = *__first; if (__first == __last) - erase(__cur, end()); + _M_erase_at_end(__cur); else insert(end(), __first, __last); } template <typename _Tp, typename _Alloc> void - deque<_Tp,_Alloc>:: + deque<_Tp, _Alloc>:: _M_fill_insert(iterator __pos, size_type __n, const value_type& __x) { if (__pos._M_cur == this->_M_impl._M_start._M_cur) @@ -212,12 +185,14 @@ namespace _GLIBCXX_STD iterator __new_start = _M_reserve_elements_at_front(__n); try { - std::uninitialized_fill(__new_start, this->_M_impl._M_start, __x); + std::__uninitialized_fill_a(__new_start, this->_M_impl._M_start, + __x, _M_get_Tp_allocator()); this->_M_impl._M_start = __new_start; } catch(...) { - _M_destroy_nodes(__new_start._M_node, this->_M_impl._M_start._M_node); + _M_destroy_nodes(__new_start._M_node, + this->_M_impl._M_start._M_node); __throw_exception_again; } } @@ -226,7 +201,9 @@ namespace _GLIBCXX_STD iterator __new_finish = _M_reserve_elements_at_back(__n); try { - std::uninitialized_fill(this->_M_impl._M_finish, __new_finish, __x); + std::__uninitialized_fill_a(this->_M_impl._M_finish, + __new_finish, __x, + _M_get_Tp_allocator()); this->_M_impl._M_finish = __new_finish; } catch(...) @@ -242,7 +219,7 @@ namespace _GLIBCXX_STD template <typename _Tp, typename _Alloc> void - deque<_Tp,_Alloc>:: + deque<_Tp, _Alloc>:: _M_fill_initialize(const value_type& __value) { _Map_pointer __cur; @@ -251,14 +228,16 @@ namespace _GLIBCXX_STD for (__cur = this->_M_impl._M_start._M_node; __cur < this->_M_impl._M_finish._M_node; ++__cur) - std::uninitialized_fill(*__cur, *__cur + _S_buffer_size(), __value); - std::uninitialized_fill(this->_M_impl._M_finish._M_first, - this->_M_impl._M_finish._M_cur, - __value); + std::__uninitialized_fill_a(*__cur, *__cur + _S_buffer_size(), + __value, _M_get_Tp_allocator()); + std::__uninitialized_fill_a(this->_M_impl._M_finish._M_first, + this->_M_impl._M_finish._M_cur, + __value, _M_get_Tp_allocator()); } catch(...) { - std::_Destroy(this->_M_impl._M_start, iterator(*__cur, __cur)); + std::_Destroy(this->_M_impl._M_start, iterator(*__cur, __cur), + _M_get_Tp_allocator()); __throw_exception_again; } } @@ -266,14 +245,14 @@ namespace _GLIBCXX_STD template <typename _Tp, typename _Alloc> template <typename _InputIterator> void - deque<_Tp,_Alloc>:: + deque<_Tp, _Alloc>:: _M_range_initialize(_InputIterator __first, _InputIterator __last, - input_iterator_tag) + std::input_iterator_tag) { this->_M_initialize_map(0); try { - for ( ; __first != __last; ++__first) + for (; __first != __last; ++__first) push_back(*__first); } catch(...) @@ -286,9 +265,9 @@ namespace _GLIBCXX_STD template <typename _Tp, typename _Alloc> template <typename _ForwardIterator> void - deque<_Tp,_Alloc>:: + deque<_Tp, _Alloc>:: _M_range_initialize(_ForwardIterator __first, _ForwardIterator __last, - forward_iterator_tag) + std::forward_iterator_tag) { const size_type __n = std::distance(__first, __last); this->_M_initialize_map(__n); @@ -299,17 +278,22 @@ namespace _GLIBCXX_STD for (__cur_node = this->_M_impl._M_start._M_node; __cur_node < this->_M_impl._M_finish._M_node; ++__cur_node) - { - _ForwardIterator __mid = __first; - std::advance(__mid, _S_buffer_size()); - std::uninitialized_copy(__first, __mid, *__cur_node); - __first = __mid; - } - std::uninitialized_copy(__first, __last, this->_M_impl._M_finish._M_first); + { + _ForwardIterator __mid = __first; + std::advance(__mid, _S_buffer_size()); + std::__uninitialized_copy_a(__first, __mid, *__cur_node, + _M_get_Tp_allocator()); + __first = __mid; + } + std::__uninitialized_copy_a(__first, __last, + this->_M_impl._M_finish._M_first, + _M_get_Tp_allocator()); } catch(...) { - std::_Destroy(this->_M_impl._M_start, iterator(*__cur_node, __cur_node)); + std::_Destroy(this->_M_impl._M_start, + iterator(*__cur_node, __cur_node), + _M_get_Tp_allocator()); __throw_exception_again; } } @@ -317,7 +301,7 @@ namespace _GLIBCXX_STD // Called only if _M_impl._M_finish._M_cur == _M_impl._M_finish._M_last - 1. template <typename _Tp, typename _Alloc> void - deque<_Tp,_Alloc>:: + deque<_Tp, _Alloc>:: _M_push_back_aux(const value_type& __t) { value_type __t_copy = __t; @@ -325,8 +309,9 @@ namespace _GLIBCXX_STD *(this->_M_impl._M_finish._M_node + 1) = this->_M_allocate_node(); try { - std::_Construct(this->_M_impl._M_finish._M_cur, __t_copy); - this->_M_impl._M_finish._M_set_node(this->_M_impl._M_finish._M_node + 1); + this->_M_impl.construct(this->_M_impl._M_finish._M_cur, __t_copy); + this->_M_impl._M_finish._M_set_node(this->_M_impl._M_finish._M_node + + 1); this->_M_impl._M_finish._M_cur = this->_M_impl._M_finish._M_first; } catch(...) @@ -339,7 +324,7 @@ namespace _GLIBCXX_STD // Called only if _M_impl._M_start._M_cur == _M_impl._M_start._M_first. template <typename _Tp, typename _Alloc> void - deque<_Tp,_Alloc>:: + deque<_Tp, _Alloc>:: _M_push_front_aux(const value_type& __t) { value_type __t_copy = __t; @@ -347,9 +332,10 @@ namespace _GLIBCXX_STD *(this->_M_impl._M_start._M_node - 1) = this->_M_allocate_node(); try { - this->_M_impl._M_start._M_set_node(this->_M_impl._M_start._M_node - 1); + this->_M_impl._M_start._M_set_node(this->_M_impl._M_start._M_node + - 1); this->_M_impl._M_start._M_cur = this->_M_impl._M_start._M_last - 1; - std::_Construct(this->_M_impl._M_start._M_cur, __t_copy); + this->_M_impl.construct(this->_M_impl._M_start._M_cur, __t_copy); } catch(...) { @@ -361,24 +347,25 @@ namespace _GLIBCXX_STD // Called only if _M_impl._M_finish._M_cur == _M_impl._M_finish._M_first. template <typename _Tp, typename _Alloc> - void deque<_Tp,_Alloc>:: + void deque<_Tp, _Alloc>:: _M_pop_back_aux() { _M_deallocate_node(this->_M_impl._M_finish._M_first); this->_M_impl._M_finish._M_set_node(this->_M_impl._M_finish._M_node - 1); this->_M_impl._M_finish._M_cur = this->_M_impl._M_finish._M_last - 1; - std::_Destroy(this->_M_impl._M_finish._M_cur); + this->_M_impl.destroy(this->_M_impl._M_finish._M_cur); } - // Called only if _M_impl._M_start._M_cur == _M_impl._M_start._M_last - 1. Note that - // if the deque has at least one element (a precondition for this member - // function), and if _M_impl._M_start._M_cur == _M_impl._M_start._M_last, then the deque - // must have at least two nodes. + // Called only if _M_impl._M_start._M_cur == _M_impl._M_start._M_last - 1. + // Note that if the deque has at least one element (a precondition for this + // member function), and if + // _M_impl._M_start._M_cur == _M_impl._M_start._M_last, + // then the deque must have at least two nodes. template <typename _Tp, typename _Alloc> - void deque<_Tp,_Alloc>:: + void deque<_Tp, _Alloc>:: _M_pop_front_aux() { - std::_Destroy(this->_M_impl._M_start._M_cur); + this->_M_impl.destroy(this->_M_impl._M_start._M_cur); _M_deallocate_node(this->_M_impl._M_start._M_first); this->_M_impl._M_start._M_set_node(this->_M_impl._M_start._M_node + 1); this->_M_impl._M_start._M_cur = this->_M_impl._M_start._M_first; @@ -387,32 +374,34 @@ namespace _GLIBCXX_STD template <typename _Tp, typename _Alloc> template <typename _InputIterator> void - deque<_Tp,_Alloc>:: + deque<_Tp, _Alloc>:: _M_range_insert_aux(iterator __pos, _InputIterator __first, _InputIterator __last, - input_iterator_tag) + std::input_iterator_tag) { std::copy(__first, __last, std::inserter(*this, __pos)); } template <typename _Tp, typename _Alloc> template <typename _ForwardIterator> void - deque<_Tp,_Alloc>:: + deque<_Tp, _Alloc>:: _M_range_insert_aux(iterator __pos, _ForwardIterator __first, _ForwardIterator __last, - forward_iterator_tag) + std::forward_iterator_tag) { - size_type __n = std::distance(__first, __last); + const size_type __n = std::distance(__first, __last); if (__pos._M_cur == this->_M_impl._M_start._M_cur) { iterator __new_start = _M_reserve_elements_at_front(__n); try { - std::uninitialized_copy(__first, __last, __new_start); + std::__uninitialized_copy_a(__first, __last, __new_start, + _M_get_Tp_allocator()); this->_M_impl._M_start = __new_start; } catch(...) { - _M_destroy_nodes(__new_start._M_node, this->_M_impl._M_start._M_node); + _M_destroy_nodes(__new_start._M_node, + this->_M_impl._M_start._M_node); __throw_exception_again; } } @@ -421,7 +410,9 @@ namespace _GLIBCXX_STD iterator __new_finish = _M_reserve_elements_at_back(__n); try { - std::uninitialized_copy(__first, __last, this->_M_impl._M_finish); + std::__uninitialized_copy_a(__first, __last, + this->_M_impl._M_finish, + _M_get_Tp_allocator()); this->_M_impl._M_finish = __new_finish; } catch(...) @@ -437,7 +428,7 @@ namespace _GLIBCXX_STD template <typename _Tp, typename _Alloc> typename deque<_Tp, _Alloc>::iterator - deque<_Tp,_Alloc>:: + deque<_Tp, _Alloc>:: _M_insert_aux(iterator __pos, const value_type& __x) { difference_type __index = __pos - this->_M_impl._M_start; @@ -470,11 +461,11 @@ namespace _GLIBCXX_STD template <typename _Tp, typename _Alloc> void - deque<_Tp,_Alloc>:: + deque<_Tp, _Alloc>:: _M_insert_aux(iterator __pos, size_type __n, const value_type& __x) { const difference_type __elems_before = __pos - this->_M_impl._M_start; - size_type __length = this->size(); + const size_type __length = this->size(); value_type __x_copy = __x; if (__elems_before < difference_type(__length / 2)) { @@ -485,25 +476,30 @@ namespace _GLIBCXX_STD { if (__elems_before >= difference_type(__n)) { - iterator __start_n = this->_M_impl._M_start + difference_type(__n); - std::uninitialized_copy(this->_M_impl._M_start, __start_n, - __new_start); + iterator __start_n = (this->_M_impl._M_start + + difference_type(__n)); + std::__uninitialized_copy_a(this->_M_impl._M_start, + __start_n, __new_start, + _M_get_Tp_allocator()); this->_M_impl._M_start = __new_start; std::copy(__start_n, __pos, __old_start); - fill(__pos - difference_type(__n), __pos, __x_copy); + std::fill(__pos - difference_type(__n), __pos, __x_copy); } else { - std::__uninitialized_copy_fill(this->_M_impl._M_start, __pos, - __new_start, - this->_M_impl._M_start, __x_copy); + std::__uninitialized_copy_fill(this->_M_impl._M_start, + __pos, __new_start, + this->_M_impl._M_start, + __x_copy, + _M_get_Tp_allocator()); this->_M_impl._M_start = __new_start; std::fill(__old_start, __pos, __x_copy); } } catch(...) { - _M_destroy_nodes(__new_start._M_node, this->_M_impl._M_start._M_node); + _M_destroy_nodes(__new_start._M_node, + this->_M_impl._M_start._M_node); __throw_exception_again; } } @@ -518,9 +514,12 @@ namespace _GLIBCXX_STD { if (__elems_after > difference_type(__n)) { - iterator __finish_n = this->_M_impl._M_finish - difference_type(__n); - std::uninitialized_copy(__finish_n, this->_M_impl._M_finish, - this->_M_impl._M_finish); + iterator __finish_n = (this->_M_impl._M_finish + - difference_type(__n)); + std::__uninitialized_copy_a(__finish_n, + this->_M_impl._M_finish, + this->_M_impl._M_finish, + _M_get_Tp_allocator()); this->_M_impl._M_finish = __new_finish; std::copy_backward(__pos, __finish_n, __old_finish); std::fill(__pos, __pos + difference_type(__n), __x_copy); @@ -530,7 +529,8 @@ namespace _GLIBCXX_STD std::__uninitialized_fill_copy(this->_M_impl._M_finish, __pos + difference_type(__n), __x_copy, __pos, - this->_M_impl._M_finish); + this->_M_impl._M_finish, + _M_get_Tp_allocator()); this->_M_impl._M_finish = __new_finish; std::fill(__pos, __old_finish, __x_copy); } @@ -547,13 +547,13 @@ namespace _GLIBCXX_STD template <typename _Tp, typename _Alloc> template <typename _ForwardIterator> void - deque<_Tp,_Alloc>:: + deque<_Tp, _Alloc>:: _M_insert_aux(iterator __pos, _ForwardIterator __first, _ForwardIterator __last, size_type __n) { const difference_type __elemsbefore = __pos - this->_M_impl._M_start; - size_type __length = size(); + const size_type __length = size(); if (static_cast<size_type>(__elemsbefore) < __length / 2) { iterator __new_start = _M_reserve_elements_at_front(__n); @@ -563,9 +563,11 @@ namespace _GLIBCXX_STD { if (__elemsbefore >= difference_type(__n)) { - iterator __start_n = this->_M_impl._M_start + difference_type(__n); - std::uninitialized_copy(this->_M_impl._M_start, __start_n, - __new_start); + iterator __start_n = (this->_M_impl._M_start + + difference_type(__n)); + std::__uninitialized_copy_a(this->_M_impl._M_start, + __start_n, __new_start, + _M_get_Tp_allocator()); this->_M_impl._M_start = __new_start; std::copy(__start_n, __pos, __old_start); std::copy(__first, __last, __pos - difference_type(__n)); @@ -574,15 +576,18 @@ namespace _GLIBCXX_STD { _ForwardIterator __mid = __first; std::advance(__mid, difference_type(__n) - __elemsbefore); - std::__uninitialized_copy_copy(this->_M_impl._M_start, __pos, - __first, __mid, __new_start); + std::__uninitialized_copy_copy(this->_M_impl._M_start, + __pos, __first, __mid, + __new_start, + _M_get_Tp_allocator()); this->_M_impl._M_start = __new_start; std::copy(__mid, __last, __old_start); } } catch(...) { - _M_destroy_nodes(__new_start._M_node, this->_M_impl._M_start._M_node); + _M_destroy_nodes(__new_start._M_node, + this->_M_impl._M_start._M_node); __throw_exception_again; } } @@ -597,10 +602,12 @@ namespace _GLIBCXX_STD { if (__elemsafter > difference_type(__n)) { - iterator __finish_n = this->_M_impl._M_finish - difference_type(__n); - std::uninitialized_copy(__finish_n, - this->_M_impl._M_finish, - this->_M_impl._M_finish); + iterator __finish_n = (this->_M_impl._M_finish + - difference_type(__n)); + std::__uninitialized_copy_a(__finish_n, + this->_M_impl._M_finish, + this->_M_impl._M_finish, + _M_get_Tp_allocator()); this->_M_impl._M_finish = __new_finish; std::copy_backward(__pos, __finish_n, __old_finish); std::copy(__first, __last, __pos); @@ -611,7 +618,8 @@ namespace _GLIBCXX_STD std::advance(__mid, __elemsafter); std::__uninitialized_copy_copy(__mid, __last, __pos, this->_M_impl._M_finish, - this->_M_impl._M_finish); + this->_M_impl._M_finish, + _M_get_Tp_allocator()); this->_M_impl._M_finish = __new_finish; std::copy(__first, __mid, __pos); } @@ -625,13 +633,38 @@ namespace _GLIBCXX_STD } } + template<typename _Tp, typename _Alloc> + void + deque<_Tp, _Alloc>:: + _M_destroy_data_aux(iterator __first, iterator __last) + { + for (_Map_pointer __node = __first._M_node + 1; + __node < __last._M_node; ++__node) + std::_Destroy(*__node, *__node + _S_buffer_size(), + _M_get_Tp_allocator()); + + if (__first._M_node != __last._M_node) + { + std::_Destroy(__first._M_cur, __first._M_last, + _M_get_Tp_allocator()); + std::_Destroy(__last._M_first, __last._M_cur, + _M_get_Tp_allocator()); + } + else + std::_Destroy(__first._M_cur, __last._M_cur, + _M_get_Tp_allocator()); + } + template <typename _Tp, typename _Alloc> void - deque<_Tp,_Alloc>:: + deque<_Tp, _Alloc>:: _M_new_elements_at_front(size_type __new_elems) { - size_type __new_nodes - = (__new_elems + _S_buffer_size() - 1) / _S_buffer_size(); + if (this->max_size() - this->size() < __new_elems) + __throw_length_error(__N("deque::_M_new_elements_at_front")); + + const size_type __new_nodes = ((__new_elems + _S_buffer_size() - 1) + / _S_buffer_size()); _M_reserve_map_at_front(__new_nodes); size_type __i; try @@ -649,11 +682,14 @@ namespace _GLIBCXX_STD template <typename _Tp, typename _Alloc> void - deque<_Tp,_Alloc>:: + deque<_Tp, _Alloc>:: _M_new_elements_at_back(size_type __new_elems) { - size_type __new_nodes - = (__new_elems + _S_buffer_size() - 1) / _S_buffer_size(); + if (this->max_size() - this->size() < __new_elems) + __throw_length_error(__N("deque::_M_new_elements_at_back")); + + const size_type __new_nodes = ((__new_elems + _S_buffer_size() - 1) + / _S_buffer_size()); _M_reserve_map_at_back(__new_nodes); size_type __i; try @@ -671,12 +707,12 @@ namespace _GLIBCXX_STD template <typename _Tp, typename _Alloc> void - deque<_Tp,_Alloc>:: + deque<_Tp, _Alloc>:: _M_reallocate_map(size_type __nodes_to_add, bool __add_at_front) { - size_type __old_num_nodes + const size_type __old_num_nodes = this->_M_impl._M_finish._M_node - this->_M_impl._M_start._M_node + 1; - size_type __new_num_nodes = __old_num_nodes + __nodes_to_add; + const size_type __new_num_nodes = __old_num_nodes + __nodes_to_add; _Map_pointer __new_nstart; if (this->_M_impl._M_map_size > 2 * __new_num_nodes) @@ -686,8 +722,8 @@ namespace _GLIBCXX_STD + (__add_at_front ? __nodes_to_add : 0); if (__new_nstart < this->_M_impl._M_start._M_node) std::copy(this->_M_impl._M_start._M_node, - this->_M_impl._M_finish._M_node + 1, - __new_nstart); + this->_M_impl._M_finish._M_node + 1, + __new_nstart); else std::copy_backward(this->_M_impl._M_start._M_node, this->_M_impl._M_finish._M_node + 1, @@ -714,6 +750,29 @@ namespace _GLIBCXX_STD this->_M_impl._M_start._M_set_node(__new_nstart); this->_M_impl._M_finish._M_set_node(__new_nstart + __old_num_nodes - 1); } -} // namespace std + + // Overload for deque::iterators, exploiting the "segmented-iterator + // optimization". NB: leave const_iterators alone! + template<typename _Tp> + void + fill(const _Deque_iterator<_Tp, _Tp&, _Tp*>& __first, + const _Deque_iterator<_Tp, _Tp&, _Tp*>& __last, const _Tp& __value) + { + typedef typename _Deque_iterator<_Tp, _Tp&, _Tp*>::_Self _Self; + + for (typename _Self::_Map_pointer __node = __first._M_node + 1; + __node < __last._M_node; ++__node) + std::fill(*__node, *__node + _Self::_S_buffer_size(), __value); + + if (__first._M_node != __last._M_node) + { + std::fill(__first._M_cur, __first._M_last, __value); + std::fill(__last._M_first, __last._M_cur, __value); + } + else + std::fill(__first._M_cur, __last._M_cur, __value); + } + +_GLIBCXX_END_NESTED_NAMESPACE #endif diff --git a/contrib/libstdc++/include/bits/fstream.tcc b/contrib/libstdc++/include/bits/fstream.tcc index 3b433ea..5520f9b 100644 --- a/contrib/libstdc++/include/bits/fstream.tcc +++ b/contrib/libstdc++/include/bits/fstream.tcc @@ -1,6 +1,6 @@ // File based streams -*- C++ -*- -// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004 +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 // Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free @@ -16,7 +16,7 @@ // 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// 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 @@ -28,6 +28,11 @@ // invalidate any other reasons why the executable file might be covered by // the GNU General Public License. +/** @file fstream.tcc + * This is an internal header file, included by other library headers. + * You should not attempt to use it directly. + */ + // // ISO C++ 14882: 27.8 File-based streams // @@ -37,8 +42,8 @@ #pragma GCC system_header -namespace std -{ +_GLIBCXX_BEGIN_NAMESPACE(std) + template<typename _CharT, typename _Traits> void basic_filebuf<_CharT, _Traits>:: @@ -46,9 +51,9 @@ namespace std { // Allocate internal buffer only if one doesn't already exist // (either allocated or provided by the user via setbuf). - if (!_M_buf_allocated && !this->_M_buf) + if (!_M_buf_allocated && !_M_buf) { - this->_M_buf = new char_type[this->_M_buf_size]; + _M_buf = new char_type[_M_buf_size]; _M_buf_allocated = true; } } @@ -60,8 +65,8 @@ namespace std { if (_M_buf_allocated) { - delete [] this->_M_buf; - this->_M_buf = NULL; + delete [] _M_buf; + _M_buf = NULL; _M_buf_allocated = false; } delete [] _M_ext_buf; @@ -97,7 +102,7 @@ namespace std if (this->is_open()) { _M_allocate_internal_buffer(); - this->_M_mode = __mode; + _M_mode = __mode; // Setup initial buffer to 'uncommitted' mode. _M_reading = false; @@ -137,8 +142,8 @@ namespace std { __testfail = true; } // NB: Do this here so that re-opened filebufs will be cool... - this->_M_mode = ios_base::openmode(0); - this->_M_pback_init = false; + _M_mode = ios_base::openmode(0); + _M_pback_init = false; _M_destroy_internal_buffer(); _M_reading = false; _M_writing = false; @@ -160,13 +165,21 @@ namespace std showmanyc() { streamsize __ret = -1; - const bool __testin = this->_M_mode & ios_base::in; + const bool __testin = _M_mode & ios_base::in; if (__testin && this->is_open()) { // For a stateful encoding (-1) the pending sequence might be just // shift and unshift prefixes with no actual character. __ret = this->egptr() - this->gptr(); + +#if _GLIBCXX_HAVE_DOS_BASED_FILESYSTEM + // About this workaround, see libstdc++/20806. + const bool __testbinary = _M_mode & ios_base::binary; + if (__check_facet(_M_codecvt).encoding() >= 0 + && __testbinary) +#else if (__check_facet(_M_codecvt).encoding() >= 0) +#endif __ret += _M_file.showmanyc() / _M_codecvt->max_length(); } return __ret; @@ -178,7 +191,7 @@ namespace std underflow() { int_type __ret = traits_type::eof(); - const bool __testin = this->_M_mode & ios_base::in; + const bool __testin = _M_mode & ios_base::in; if (__testin && !_M_writing) { // Check for pback madness, and if so swich back to the @@ -190,8 +203,7 @@ namespace std return traits_type::to_int_type(*this->gptr()); // Get and convert input sequence. - const size_t __buflen = this->_M_buf_size > 1 - ? this->_M_buf_size - 1 : 1; + const size_t __buflen = _M_buf_size > 1 ? _M_buf_size - 1 : 1; // Will be set to true if ::read() returns 0 indicating EOF. bool __got_eof = false; @@ -328,12 +340,12 @@ namespace std pbackfail(int_type __i) { int_type __ret = traits_type::eof(); - const bool __testin = this->_M_mode & ios_base::in; + const bool __testin = _M_mode & ios_base::in; if (__testin && !_M_writing) { // Remember whether the pback buffer is active, otherwise below // we may try to store in it a second char (libstdc++/9761). - const bool __testpb = this->_M_pback_init; + const bool __testpb = _M_pback_init; const bool __testeof = traits_type::eq_int_type(__i, __ret); int_type __tmp; if (this->eback() < this->gptr()) @@ -381,7 +393,7 @@ namespace std { int_type __ret = traits_type::eof(); const bool __testeof = traits_type::eq_int_type(__c, __ret); - const bool __testout = this->_M_mode & ios_base::out; + const bool __testout = _M_mode & ios_base::out; if (__testout && !_M_reading) { if (this->pbase() < this->pptr()) @@ -402,7 +414,7 @@ namespace std __ret = traits_type::not_eof(__c); } } - else if (this->_M_buf_size > 1) + else if (_M_buf_size > 1) { // Overflow in 'uncommitted' mode: set _M_writing, set // the buffer to the initial 'write' mode, and put __c @@ -500,7 +512,7 @@ namespace std { // Clear out pback buffer before going on to the real deal... streamsize __ret = 0; - if (this->_M_pback_init) + if (_M_pback_init) { if (__n > 0 && this->gptr() == this->eback()) { @@ -515,9 +527,9 @@ namespace std // Optimization in the always_noconv() case, to be generalized in the // future: when __n > __buflen we read directly instead of using the // buffer repeatedly. - const bool __testin = this->_M_mode & ios_base::in; - const streamsize __buflen = this->_M_buf_size > 1 ? this->_M_buf_size - 1 - : 1; + const bool __testin = _M_mode & ios_base::in; + const streamsize __buflen = _M_buf_size > 1 ? _M_buf_size - 1 : 1; + if (__n > __buflen && __check_facet(_M_codecvt).always_noconv() && __testin && !_M_writing) { @@ -585,7 +597,7 @@ namespace std // future: when __n is sufficiently large we write directly instead of // using the buffer. streamsize __ret = 0; - const bool __testout = this->_M_mode & ios_base::out; + const bool __testout = _M_mode & ios_base::out; if (__check_facet(_M_codecvt).always_noconv() && __testout && !_M_reading) { @@ -594,8 +606,8 @@ namespace std streamsize __bufavail = this->epptr() - this->pptr(); // Don't mistake 'uncommitted' mode buffered with unbuffered. - if (!_M_writing && this->_M_buf_size > 1) - __bufavail = this->_M_buf_size - 1; + if (!_M_writing && _M_buf_size > 1) + __bufavail = _M_buf_size - 1; const streamsize __limit = std::min(__chunk, __bufavail); if (__n >= __limit) @@ -630,7 +642,7 @@ namespace std { if (!this->is_open()) if (__s == 0 && __n == 0) - this->_M_buf_size = 1; + _M_buf_size = 1; else if (__s && __n > 0) { // This is implementation-defined behavior, and assumes that @@ -641,8 +653,8 @@ namespace std // position to host the overflow char of a full put area. // When __n == 1, 1 position will be used for the get area // and 0 for the put area, as in the unbuffered case above. - this->_M_buf = __s; - this->_M_buf_size = __n; + _M_buf = __s; + _M_buf_size = __n; } return this; } @@ -728,12 +740,15 @@ namespace std { // Returns pos_type(off_type(-1)) in case of failure. __ret = pos_type(_M_file.seekoff(__off, __way)); - _M_reading = false; - _M_writing = false; - _M_ext_next = _M_ext_end = _M_ext_buf; - _M_set_buffer(-1); - _M_state_cur = __state; - __ret.state(_M_state_cur); + if (__ret != pos_type(off_type(-1))) + { + _M_reading = false; + _M_writing = false; + _M_ext_next = _M_ext_end = _M_ext_buf; + _M_set_buffer(-1); + _M_state_cur = __state; + __ret.state(_M_state_cur); + } } return __ret; } @@ -841,7 +856,7 @@ namespace std { if (_M_codecvt_tmp && !__check_facet(_M_codecvt_tmp).always_noconv()) - __testvalid = this->seekoff(0, ios_base::cur, this->_M_mode) + __testvalid = this->seekoff(0, ios_base::cur, _M_mode) != pos_type(off_type(-1)); } else @@ -887,6 +902,7 @@ namespace std extern template class basic_fstream<wchar_t>; #endif #endif -} // namespace std + +_GLIBCXX_END_NAMESPACE #endif diff --git a/contrib/libstdc++/include/bits/functexcept.h b/contrib/libstdc++/include/bits/functexcept.h index 8b1d16c..59358c4 100644 --- a/contrib/libstdc++/include/bits/functexcept.h +++ b/contrib/libstdc++/include/bits/functexcept.h @@ -1,6 +1,6 @@ // Function-Based Exception Support -*- C++ -*- -// Copyright (C) 2001 Free Software Foundation, Inc. +// Copyright (C) 2001, 2004, 2005 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 @@ -15,7 +15,7 @@ // 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// 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 @@ -27,59 +27,69 @@ // invalidate any other reasons why the executable file might be covered by // the GNU General Public License. +/** @file functexcept.h + * This header provides support for -fno-exceptions. + */ + // // ISO C++ 14882: 19.1 Exception classes // +#ifndef _FUNCTEXCEPT_H +#define _FUNCTEXCEPT_H 1 + +#include <bits/c++config.h> #include <exception_defines.h> -namespace std -{ +_GLIBCXX_BEGIN_NAMESPACE(std) + // Helper for exception objects in <except> void - __throw_bad_exception(void); + __throw_bad_exception(void) __attribute__((__noreturn__)); // Helper for exception objects in <new> void - __throw_bad_alloc(void); + __throw_bad_alloc(void) __attribute__((__noreturn__)); // Helper for exception objects in <typeinfo> void - __throw_bad_cast(void); + __throw_bad_cast(void) __attribute__((__noreturn__)); void - __throw_bad_typeid(void); + __throw_bad_typeid(void) __attribute__((__noreturn__)); // Helpers for exception objects in <stdexcept> void - __throw_logic_error(const char* __s); + __throw_logic_error(const char*) __attribute__((__noreturn__)); void - __throw_domain_error(const char* __s); + __throw_domain_error(const char*) __attribute__((__noreturn__)); void - __throw_invalid_argument(const char* __s); + __throw_invalid_argument(const char*) __attribute__((__noreturn__)); void - __throw_length_error(const char* __s); + __throw_length_error(const char*) __attribute__((__noreturn__)); void - __throw_out_of_range(const char* __s); + __throw_out_of_range(const char*) __attribute__((__noreturn__)); void - __throw_runtime_error(const char* __s); + __throw_runtime_error(const char*) __attribute__((__noreturn__)); void - __throw_range_error(const char* __s); + __throw_range_error(const char*) __attribute__((__noreturn__)); void - __throw_overflow_error(const char* __s); + __throw_overflow_error(const char*) __attribute__((__noreturn__)); void - __throw_underflow_error(const char* __s); + __throw_underflow_error(const char*) __attribute__((__noreturn__)); // Helpers for exception objects in basic_ios void - __throw_ios_failure(const char* __s); -} // namespace std + __throw_ios_failure(const char*) __attribute__((__noreturn__)); + +_GLIBCXX_END_NAMESPACE +#endif diff --git a/contrib/libstdc++/include/bits/gslice.h b/contrib/libstdc++/include/bits/gslice.h index 78f8a67..12bfc32 100644 --- a/contrib/libstdc++/include/bits/gslice.h +++ b/contrib/libstdc++/include/bits/gslice.h @@ -1,6 +1,6 @@ // The template and inlines for the -*- C++ -*- gslice class. -// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2004 +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2004, 2005 // Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free @@ -16,7 +16,7 @@ // 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// 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 @@ -28,19 +28,19 @@ // invalidate any other reasons why the executable file might be covered by // the GNU General Public License. -// Written by Gabriel Dos Reis <Gabriel.Dos-Reis@DPTMaths.ENS-Cachan.Fr> - /** @file gslice.h * This is an internal header file, included by other library headers. * You should not attempt to use it directly. */ +// Written by Gabriel Dos Reis <Gabriel.Dos-Reis@DPTMaths.ENS-Cachan.Fr> + #ifndef _GSLICE_H #define _GSLICE_H 1 #pragma GCC system_header -namespace std { +_GLIBCXX_BEGIN_NAMESPACE(std) /** * @brief Class defining multi-dimensional subset of an array. @@ -60,106 +60,111 @@ namespace std { * slice[0,2]==array[9], slice[1,0]==array[14], slice[1,1]==array[17], * slice[1,2]==array[20]. */ - class gslice + class gslice + { + public: + /// Construct an empty slice. + gslice (); + + /** + * @brief Construct a slice. + * + * Constructs a slice with as many dimensions as the length of the @a l + * and @a s arrays. + * + * @param o Offset in array of first element. + * @param l Array of dimension lengths. + * @param s Array of dimension strides between array elements. + */ + gslice(size_t, const valarray<size_t>&, const valarray<size_t>&); + + // XXX: the IS says the copy-ctor and copy-assignment operators are + // synthetized by the compiler but they are just unsuitable + // for a ref-counted semantic + /// Copy constructor. + gslice(const gslice&); + + /// Destructor. + ~gslice(); + + // XXX: See the note above. + /// Assignment operator. + gslice& operator=(const gslice&); + + /// Return array offset of first slice element. + size_t start() const; + + /// Return array of sizes of slice dimensions. + valarray<size_t> size() const; + + /// Return array of array strides for each dimension. + valarray<size_t> stride() const; + + private: + struct _Indexer { - public: - /// Construct an empty slice. - gslice (); - - /** - * @brief Construct a slice. - * - * Constructs a slice with as many dimensions as the length of the @a l - * and @a s arrays. - * - * @param o Offset in array of first element. - * @param l Array of dimension lengths. - * @param s Array of dimension strides between array elements. - */ - gslice(size_t, const valarray<size_t>&, const valarray<size_t>&); - - // XXX: the IS says the copy-ctor and copy-assignment operators are - // synthetized by the compiler but they are just unsuitable - // for a ref-counted semantic - /// Copy constructor. - gslice(const gslice&); - - /// Destructor. - ~gslice(); - - // XXX: See the note above. - /// Assignment operator. - gslice& operator=(const gslice&); - - /// Return array offset of first slice element. - size_t start() const; - - /// Return array of sizes of slice dimensions. - valarray<size_t> size() const; - - /// Return array of array strides for each dimension. - valarray<size_t> stride() const; - - private: - struct _Indexer { - size_t _M_count; - size_t _M_start; - valarray<size_t> _M_size; - valarray<size_t> _M_stride; - valarray<size_t> _M_index; // Linear array of referenced indices - _Indexer(size_t, const valarray<size_t>&, - const valarray<size_t>&); - void _M_increment_use() { ++_M_count; } - size_t _M_decrement_use() { return --_M_count; } - }; - - _Indexer* _M_index; - - template<typename _Tp> friend class valarray; + size_t _M_count; + size_t _M_start; + valarray<size_t> _M_size; + valarray<size_t> _M_stride; + valarray<size_t> _M_index; // Linear array of referenced indices + _Indexer(size_t, const valarray<size_t>&, + const valarray<size_t>&); + void + _M_increment_use() + { ++_M_count; } + + size_t + _M_decrement_use() + { return --_M_count; } }; - inline size_t - gslice::start () const - { return _M_index ? _M_index->_M_start : 0; } + _Indexer* _M_index; - inline valarray<size_t> - gslice::size () const - { return _M_index ? _M_index->_M_size : valarray<size_t>(); } + template<typename _Tp> friend class valarray; + }; - inline valarray<size_t> - gslice::stride () const - { return _M_index ? _M_index->_M_stride : valarray<size_t>(); } + inline size_t + gslice::start () const + { return _M_index ? _M_index->_M_start : 0; } - inline gslice::gslice () : _M_index(0) {} + inline valarray<size_t> + gslice::size () const + { return _M_index ? _M_index->_M_size : valarray<size_t>(); } - inline - gslice::gslice(size_t __o, const valarray<size_t>& __l, - const valarray<size_t>& __s) - : _M_index(new gslice::_Indexer(__o, __l, __s)) {} + inline valarray<size_t> + gslice::stride () const + { return _M_index ? _M_index->_M_stride : valarray<size_t>(); } - inline - gslice::gslice(const gslice& __g) : _M_index(__g._M_index) - { if (_M_index) _M_index->_M_increment_use(); } + inline gslice::gslice () : _M_index(0) {} - inline - gslice::~gslice() - { if (_M_index && _M_index->_M_decrement_use() == 0) delete _M_index; } + inline + gslice::gslice(size_t __o, const valarray<size_t>& __l, + const valarray<size_t>& __s) + : _M_index(new gslice::_Indexer(__o, __l, __s)) {} - inline gslice& - gslice::operator= (const gslice& __g) - { - if (__g._M_index) __g._M_index->_M_increment_use(); - if (_M_index && _M_index->_M_decrement_use() == 0) delete _M_index; - _M_index = __g._M_index; - return *this; - } + inline + gslice::gslice(const gslice& __g) : _M_index(__g._M_index) + { if (_M_index) _M_index->_M_increment_use(); } + inline + gslice::~gslice() + { + if (_M_index && _M_index->_M_decrement_use() == 0) + delete _M_index; + } -} // std:: + inline gslice& + gslice::operator= (const gslice& __g) + { + if (__g._M_index) + __g._M_index->_M_increment_use(); + if (_M_index && _M_index->_M_decrement_use() == 0) + delete _M_index; + _M_index = __g._M_index; + return *this; + } +_GLIBCXX_END_NAMESPACE #endif /* _GSLICE_H */ - -// Local Variables: -// mode:c++ -// End: diff --git a/contrib/libstdc++/include/bits/gslice_array.h b/contrib/libstdc++/include/bits/gslice_array.h index 7e2e684..55ddc3b 100644 --- a/contrib/libstdc++/include/bits/gslice_array.h +++ b/contrib/libstdc++/include/bits/gslice_array.h @@ -1,6 +1,6 @@ // The template and inlines for the -*- C++ -*- gslice_array class. -// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2004 +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2004, 2005 // Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free @@ -16,7 +16,7 @@ // 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// 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 @@ -28,19 +28,19 @@ // invalidate any other reasons why the executable file might be covered by // the GNU General Public License. -// Written by Gabriel Dos Reis <Gabriel.Dos-Reis@DPTMaths.ENS-Cachan.Fr> - /** @file gslice_array.h * This is an internal header file, included by other library headers. * You should not attempt to use it directly. */ +// Written by Gabriel Dos Reis <Gabriel.Dos-Reis@DPTMaths.ENS-Cachan.Fr> + #ifndef _GSLICE_ARRAY_H #define _GSLICE_ARRAY_H 1 #pragma GCC system_header -namespace std { +_GLIBCXX_BEGIN_NAMESPACE(std) /** * @brief Reference to multi-dimensional subset of an array. @@ -97,27 +97,27 @@ namespace std { void operator=(const _Tp&) const; template<class _Dom> - void operator=(const _Expr<_Dom,_Tp>&) const; + void operator=(const _Expr<_Dom, _Tp>&) const; template<class _Dom> - void operator*=(const _Expr<_Dom,_Tp>&) const; + void operator*=(const _Expr<_Dom, _Tp>&) const; template<class _Dom> - void operator/=(const _Expr<_Dom,_Tp>&) const; + void operator/=(const _Expr<_Dom, _Tp>&) const; template<class _Dom> - void operator%=(const _Expr<_Dom,_Tp>&) const; + void operator%=(const _Expr<_Dom, _Tp>&) const; template<class _Dom> - void operator+=(const _Expr<_Dom,_Tp>&) const; + void operator+=(const _Expr<_Dom, _Tp>&) const; template<class _Dom> - void operator-=(const _Expr<_Dom,_Tp>&) const; + void operator-=(const _Expr<_Dom, _Tp>&) const; template<class _Dom> - void operator^=(const _Expr<_Dom,_Tp>&) const; + void operator^=(const _Expr<_Dom, _Tp>&) const; template<class _Dom> - void operator&=(const _Expr<_Dom,_Tp>&) const; + void operator&=(const _Expr<_Dom, _Tp>&) const; template<class _Dom> - void operator|=(const _Expr<_Dom,_Tp>&) const; + void operator|=(const _Expr<_Dom, _Tp>&) const; template<class _Dom> - void operator<<=(const _Expr<_Dom,_Tp>&) const; + void operator<<=(const _Expr<_Dom, _Tp>&) const; template<class _Dom> - void operator>>=(const _Expr<_Dom,_Tp>&) const; + void operator>>=(const _Expr<_Dom, _Tp>&) const; private: _Array<_Tp> _M_array; @@ -137,13 +137,11 @@ namespace std { const valarray<size_t>& __i) : _M_array(__a), _M_index(__i) {} - template<typename _Tp> inline gslice_array<_Tp>::gslice_array(const gslice_array<_Tp>& __a) : _M_array(__a._M_array), _M_index(__a._M_index) {} - template<typename _Tp> inline gslice_array<_Tp>& gslice_array<_Tp>::operator=(const gslice_array<_Tp>& __a) @@ -186,7 +184,7 @@ namespace std { gslice_array<_Tp>::operator _Op##=(const valarray<_Tp>& __v) const \ { \ _Array_augmented_##_Name(_M_array, _Array<size_t>(_M_index), \ - _Array<_Tp>(__v), __v.size()); \ + _Array<_Tp>(__v), __v.size()); \ } \ \ template<typename _Tp> \ @@ -211,10 +209,6 @@ _DEFINE_VALARRAY_OPERATOR(>>, __shift_right) #undef _DEFINE_VALARRAY_OPERATOR -} // std:: +_GLIBCXX_END_NAMESPACE #endif /* _GSLICE_ARRAY_H */ - -// Local Variables: -// mode:c++ -// End: diff --git a/contrib/libstdc++/include/bits/indirect_array.h b/contrib/libstdc++/include/bits/indirect_array.h index 912f522..d43d801 100644 --- a/contrib/libstdc++/include/bits/indirect_array.h +++ b/contrib/libstdc++/include/bits/indirect_array.h @@ -1,6 +1,6 @@ // The template and inlines for the -*- C++ -*- indirect_array class. -// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2004 +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2004, 2005 // Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free @@ -16,7 +16,7 @@ // 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// 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 @@ -28,28 +28,28 @@ // invalidate any other reasons why the executable file might be covered by // the GNU General Public License. -// Written by Gabriel Dos Reis <Gabriel.Dos-Reis@DPTMaths.ENS-Cachan.Fr> - /** @file indirect_array.h * This is an internal header file, included by other library headers. * You should not attempt to use it directly. */ +// Written by Gabriel Dos Reis <Gabriel.Dos-Reis@DPTMaths.ENS-Cachan.Fr> + #ifndef _INDIRECT_ARRAY_H #define _INDIRECT_ARRAY_H 1 #pragma GCC system_header -namespace std -{ +_GLIBCXX_BEGIN_NAMESPACE(std) + /** * @brief Reference to arbitrary subset of an array. * * An indirect_array is a reference to the actual elements of an array - * specified by an ordered array of indices. The way to get an indirect_array is to - * call operator[](valarray<size_t>) on a valarray. The returned - * indirect_array then permits carrying operations out on the referenced - * subset of elements in the original valarray. + * specified by an ordered array of indices. The way to get an + * indirect_array is to call operator[](valarray<size_t>) on a valarray. + * The returned indirect_array then permits carrying operations out on the + * referenced subset of elements in the original valarray. * * For example, if an indirect_array is obtained using the array (4,2,0) as * an argument, and then assigned to an array containing (1,2,3), then the @@ -143,35 +143,35 @@ namespace std : _M_sz(__a._M_sz), _M_index(__a._M_index), _M_array(__a._M_array) {} template<typename _Tp> - inline - indirect_array<_Tp>::indirect_array(_Array<_Tp> __a, size_t __s, - _Array<size_t> __i) - : _M_sz(__s), _M_index(__i), _M_array(__a) {} + inline + indirect_array<_Tp>::indirect_array(_Array<_Tp> __a, size_t __s, + _Array<size_t> __i) + : _M_sz(__s), _M_index(__i), _M_array(__a) {} template<typename _Tp> - inline indirect_array<_Tp>& - indirect_array<_Tp>::operator=(const indirect_array<_Tp>& __a) - { - std::__valarray_copy(__a._M_array, _M_sz, __a._M_index, _M_array, _M_index); - return *this; - } - + inline indirect_array<_Tp>& + indirect_array<_Tp>::operator=(const indirect_array<_Tp>& __a) + { + std::__valarray_copy(__a._M_array, _M_sz, __a._M_index, _M_array, + _M_index); + return *this; + } template<typename _Tp> - inline void - indirect_array<_Tp>::operator=(const _Tp& __t) const - { std::__valarray_fill(_M_array, _M_index, _M_sz, __t); } + inline void + indirect_array<_Tp>::operator=(const _Tp& __t) const + { std::__valarray_fill(_M_array, _M_index, _M_sz, __t); } template<typename _Tp> - inline void - indirect_array<_Tp>::operator=(const valarray<_Tp>& __v) const - { std::__valarray_copy(_Array<_Tp>(__v), _M_sz, _M_array, _M_index); } + inline void + indirect_array<_Tp>::operator=(const valarray<_Tp>& __v) const + { std::__valarray_copy(_Array<_Tp>(__v), _M_sz, _M_array, _M_index); } template<typename _Tp> - template<class _Dom> - inline void - indirect_array<_Tp>::operator=(const _Expr<_Dom,_Tp>& __e) const - { std::__valarray_copy(__e, _M_sz, _M_array, _M_index); } + template<class _Dom> + inline void + indirect_array<_Tp>::operator=(const _Expr<_Dom, _Tp>& __e) const + { std::__valarray_copy(__e, _M_sz, _M_array, _M_index); } #undef _DEFINE_VALARRAY_OPERATOR #define _DEFINE_VALARRAY_OPERATOR(_Op, _Name) \ @@ -203,10 +203,6 @@ _DEFINE_VALARRAY_OPERATOR(>>, __shift_right) #undef _DEFINE_VALARRAY_OPERATOR -} // std:: +_GLIBCXX_END_NAMESPACE #endif /* _INDIRECT_ARRAY_H */ - -// Local Variables: -// mode:c++ -// End: diff --git a/contrib/libstdc++/include/bits/ios_base.h b/contrib/libstdc++/include/bits/ios_base.h index 08c952d..33dc256 100644 --- a/contrib/libstdc++/include/bits/ios_base.h +++ b/contrib/libstdc++/include/bits/ios_base.h @@ -1,6 +1,6 @@ // Iostreams base classes -*- C++ -*- -// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004 +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 // Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free @@ -16,7 +16,7 @@ // 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// 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 @@ -28,26 +28,26 @@ // invalidate any other reasons why the executable file might be covered by // the GNU General Public License. -// -// ISO C++ 14882: 27.4 Iostreams base classes -// - /** @file ios_base.h * This is an internal header file, included by other library headers. * You should not attempt to use it directly. */ +// +// ISO C++ 14882: 27.4 Iostreams base classes +// + #ifndef _IOS_BASE_H #define _IOS_BASE_H 1 #pragma GCC system_header -#include <bits/atomicity.h> +#include <ext/atomicity.h> #include <bits/localefwd.h> #include <bits/locale_classes.h> -namespace std -{ +_GLIBCXX_BEGIN_NAMESPACE(std) + // The following definitions of bitmask types are enums, not ints, // as permitted (but not required) in the standard, in order to provide // better type safety in iostream calls. A side effect is that @@ -191,7 +191,7 @@ namespace std // 27.4.2 Class ios_base /** - * @brief The very top of the I/O class hierarchy. + * @brief The base of the I/O class hierarchy. * * This class defines everything that can be defined about I/O that does * not depend on the type of characters being input or output. Most @@ -253,65 +253,65 @@ namespace std typedef _Ios_Fmtflags fmtflags; /// Insert/extract @c bool in alphabetic rather than numeric format. - static const fmtflags boolalpha = fmtflags(__ios_flags::_S_boolalpha); + static const fmtflags boolalpha = _S_boolalpha; /// Converts integer input or generates integer output in decimal base. - static const fmtflags dec = fmtflags(__ios_flags::_S_dec); + static const fmtflags dec = _S_dec; /// Generate floating-point output in fixed-point notation. - static const fmtflags fixed = fmtflags(__ios_flags::_S_fixed); + static const fmtflags fixed = _S_fixed; /// Converts integer input or generates integer output in hexadecimal base. - static const fmtflags hex = fmtflags(__ios_flags::_S_hex); + static const fmtflags hex = _S_hex; /// Adds fill characters at a designated internal point in certain /// generated output, or identical to @c right if no such point is /// designated. - static const fmtflags internal = fmtflags(__ios_flags::_S_internal); + static const fmtflags internal = _S_internal; /// Adds fill characters on the right (final positions) of certain /// generated output. (I.e., the thing you print is flush left.) - static const fmtflags left = fmtflags(__ios_flags::_S_left); + static const fmtflags left = _S_left; /// Converts integer input or generates integer output in octal base. - static const fmtflags oct = fmtflags(__ios_flags::_S_oct); + static const fmtflags oct = _S_oct; /// Adds fill characters on the left (initial positions) of certain /// generated output. (I.e., the thing you print is flush right.) - static const fmtflags right = fmtflags(__ios_flags::_S_right); + static const fmtflags right = _S_right; /// Generates floating-point output in scientific notation. - static const fmtflags scientific = fmtflags(__ios_flags::_S_scientific); + static const fmtflags scientific = _S_scientific; /// Generates a prefix indicating the numeric base of generated integer /// output. - static const fmtflags showbase = fmtflags(__ios_flags::_S_showbase); + static const fmtflags showbase = _S_showbase; /// Generates a decimal-point character unconditionally in generated /// floating-point output. - static const fmtflags showpoint = fmtflags(__ios_flags::_S_showpoint); + static const fmtflags showpoint = _S_showpoint; /// Generates a + sign in non-negative generated numeric output. - static const fmtflags showpos = fmtflags(__ios_flags::_S_showpos); + static const fmtflags showpos = _S_showpos; /// Skips leading white space before certain input operations. - static const fmtflags skipws = fmtflags(__ios_flags::_S_skipws); + static const fmtflags skipws = _S_skipws; /// Flushes output after each output operation. - static const fmtflags unitbuf = fmtflags(__ios_flags::_S_unitbuf); + static const fmtflags unitbuf = _S_unitbuf; /// Replaces certain lowercase letters with their uppercase equivalents /// in generated output. - static const fmtflags uppercase = fmtflags(__ios_flags::_S_uppercase); + static const fmtflags uppercase = _S_uppercase; /// A mask of left|right|internal. Useful for the 2-arg form of @c setf. - static const fmtflags adjustfield = fmtflags(__ios_flags::_S_adjustfield); + static const fmtflags adjustfield = _S_adjustfield; /// A mask of dec|oct|hex. Useful for the 2-arg form of @c setf. - static const fmtflags basefield = fmtflags(__ios_flags::_S_basefield); + static const fmtflags basefield = _S_basefield; /// A mask of scientific|fixed. Useful for the 2-arg form of @c setf. - static const fmtflags floatfield = fmtflags(__ios_flags::_S_floatfield); + static const fmtflags floatfield = _S_floatfield; // 27.4.2.1.3 Type ios_base::iostate /** @@ -329,18 +329,18 @@ namespace std /// Indicates a loss of integrity in an input or output sequence (such /// as an irrecoverable read error from a file). - static const iostate badbit = iostate(__ios_flags::_S_badbit); + static const iostate badbit = _S_badbit; /// Indicates that an input operation reached the end of an input sequence. - static const iostate eofbit = iostate(__ios_flags::_S_eofbit); + static const iostate eofbit = _S_eofbit; /// Indicates that an input operation failed to read the expected /// characters, or that an output operation failed to generate the /// desired characters. - static const iostate failbit = iostate(__ios_flags::_S_failbit); + static const iostate failbit = _S_failbit; /// Indicates all is well. - static const iostate goodbit = iostate(0); + static const iostate goodbit = _S_goodbit; // 27.4.2.1.4 Type ios_base::openmode /** @@ -359,25 +359,25 @@ namespace std typedef _Ios_Openmode openmode; /// Seek to end before each write. - static const openmode app = openmode(__ios_flags::_S_app); + static const openmode app = _S_app; /// Open and seek to end immediately after opening. - static const openmode ate = openmode(__ios_flags::_S_ate); + static const openmode ate = _S_ate; /// Perform input and output in binary mode (as opposed to text mode). /// This is probably not what you think it is; see /// http://gcc.gnu.org/onlinedocs/libstdc++/27_io/howto.html#3 and /// http://gcc.gnu.org/onlinedocs/libstdc++/27_io/howto.html#7 for more. - static const openmode binary = openmode(__ios_flags::_S_bin); + static const openmode binary = _S_bin; /// Open for input. Default for @c ifstream and fstream. - static const openmode in = openmode(__ios_flags::_S_in); + static const openmode in = _S_in; /// Open for output. Default for @c ofstream and fstream. - static const openmode out = openmode(__ios_flags::_S_out); + static const openmode out = _S_out; /// Open for input. Default for @c ofstream. - static const openmode trunc = openmode(__ios_flags::_S_trunc); + static const openmode trunc = _S_trunc; // 27.4.2.1.5 Type ios_base::seekdir /** @@ -392,15 +392,14 @@ namespace std typedef _Ios_Seekdir seekdir; /// Request a seek relative to the beginning of the stream. - static const seekdir beg = seekdir(0); + static const seekdir beg = _S_beg; /// Request a seek relative to the current position within the sequence. - static const seekdir cur = seekdir(SEEK_CUR); + static const seekdir cur = _S_cur; /// Request a seek relative to the current end of the sequence. - static const seekdir end = seekdir(SEEK_END); + static const seekdir end = _S_end; -#ifdef _GLIBCXX_DEPRECATED // Annex D.6 typedef int io_state; typedef int open_mode; @@ -408,7 +407,6 @@ namespace std typedef std::streampos streampos; typedef std::streamoff streamoff; -#endif // Callbacks; /** @@ -478,12 +476,12 @@ namespace std : _M_next(__cb), _M_fn(__fn), _M_index(__index), _M_refcount(0) { } void - _M_add_reference() { __gnu_cxx::__atomic_add(&_M_refcount, 1); } + _M_add_reference() { __gnu_cxx::__atomic_add_dispatch(&_M_refcount, 1); } // 0 => OK to delete. int _M_remove_reference() - { return __gnu_cxx::__exchange_and_add(&_M_refcount, -1); } + { return __gnu_cxx::__exchange_and_add_dispatch(&_M_refcount, -1); } }; _Callback_list* _M_callbacks; @@ -507,7 +505,7 @@ namespace std // Guaranteed storage. // The first 5 iword and pword slots are reserved for internal use. - static const int _S_local_word_size = 8; + enum { _S_local_word_size = 8 }; _Words _M_local_word[_S_local_word_size]; // Allocated storage. @@ -963,7 +961,8 @@ namespace std __base.setf(ios_base::scientific, ios_base::floatfield); return __base; } -} // namespace std + +_GLIBCXX_END_NAMESPACE #endif /* _IOS_BASE_H */ diff --git a/contrib/libstdc++/include/bits/istream.tcc b/contrib/libstdc++/include/bits/istream.tcc index 9decce3..13facc4 100644 --- a/contrib/libstdc++/include/bits/istream.tcc +++ b/contrib/libstdc++/include/bits/istream.tcc @@ -1,6 +1,7 @@ // istream classes -*- C++ -*- -// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004 +// 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 @@ -16,7 +17,7 @@ // 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// 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 @@ -28,6 +29,11 @@ // invalidate any other reasons why the executable file might be covered by // the GNU General Public License. +/** @file istream.tcc + * This is an internal header file, included by other library headers. + * You should not attempt to use it directly. + */ + // // ISO C++ 14882: 27.6.1 Input streams // @@ -40,8 +46,8 @@ #include <locale> #include <ostream> // For flush() -namespace std -{ +_GLIBCXX_BEGIN_NAMESPACE(std) + template<typename _CharT, typename _Traits> basic_istream<_CharT, _Traits>::sentry:: sentry(basic_istream<_CharT, _Traits>& __in, bool __noskip) : _M_ok(false) @@ -81,331 +87,64 @@ namespace std } template<typename _CharT, typename _Traits> - basic_istream<_CharT, _Traits>& - basic_istream<_CharT, _Traits>:: - operator>>(__istream_type& (*__pf)(__istream_type&)) - { return __pf(*this); } - - template<typename _CharT, typename _Traits> - basic_istream<_CharT, _Traits>& - basic_istream<_CharT, _Traits>:: - operator>>(__ios_type& (*__pf)(__ios_type&)) - { - __pf(*this); - return *this; - } - - template<typename _CharT, typename _Traits> - basic_istream<_CharT, _Traits>& - basic_istream<_CharT, _Traits>:: - operator>>(ios_base& (*__pf)(ios_base&)) - { - __pf(*this); - return *this; - } - - template<typename _CharT, typename _Traits> - basic_istream<_CharT, _Traits>& - basic_istream<_CharT, _Traits>:: - operator>>(bool& __n) - { - sentry __cerb(*this, false); - if (__cerb) - { - ios_base::iostate __err = ios_base::iostate(ios_base::goodbit); - try - { - const __num_get_type& __ng = __check_facet(this->_M_num_get); - __ng.get(*this, 0, *this, __err, __n); - } - catch(...) - { this->_M_setstate(ios_base::badbit); } - if (__err) - this->setstate(__err); - } - return *this; - } + template<typename _ValueT> + basic_istream<_CharT, _Traits>& + basic_istream<_CharT, _Traits>:: + _M_extract(_ValueT& __v) + { + sentry __cerb(*this, false); + if (__cerb) + { + ios_base::iostate __err = ios_base::iostate(ios_base::goodbit); + try + { + const __num_get_type& __ng = __check_facet(this->_M_num_get); + __ng.get(*this, 0, *this, __err, __v); + } + catch(...) + { this->_M_setstate(ios_base::badbit); } + if (__err) + this->setstate(__err); + } + return *this; + } template<typename _CharT, typename _Traits> basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>:: operator>>(short& __n) { - sentry __cerb(*this, false); - if (__cerb) - { - ios_base::iostate __err = ios_base::iostate(ios_base::goodbit); - try - { - long __l; - const __num_get_type& __ng = __check_facet(this->_M_num_get); - __ng.get(*this, 0, *this, __err, __l); - // _GLIBCXX_RESOLVE_LIB_DEFECTS - // 118. basic_istream uses nonexistent num_get member functions. - if (!(__err & ios_base::failbit) - && (numeric_limits<short>::min() <= __l - && __l <= numeric_limits<short>::max())) - __n = __l; - else - __err |= ios_base::failbit; - } - catch(...) - { this->_M_setstate(ios_base::badbit); } - if (__err) - this->setstate(__err); - } - return *this; - } - - template<typename _CharT, typename _Traits> - basic_istream<_CharT, _Traits>& - basic_istream<_CharT, _Traits>:: - operator>>(unsigned short& __n) - { - sentry __cerb(*this, false); - if (__cerb) + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 118. basic_istream uses nonexistent num_get member functions. + long __l; + _M_extract(__l); + if (!this->fail()) { - ios_base::iostate __err = ios_base::iostate(ios_base::goodbit); - try - { - const __num_get_type& __ng = __check_facet(this->_M_num_get); - __ng.get(*this, 0, *this, __err, __n); - } - catch(...) - { this->_M_setstate(ios_base::badbit); } - if (__err) - this->setstate(__err); + if (numeric_limits<short>::min() <= __l + && __l <= numeric_limits<short>::max()) + __n = __l; + else + this->setstate(ios_base::failbit); } return *this; } - + template<typename _CharT, typename _Traits> basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>:: operator>>(int& __n) { - sentry __cerb(*this, false); - if (__cerb) - { - ios_base::iostate __err = ios_base::iostate(ios_base::goodbit); - try - { - long __l; - const __num_get_type& __ng = __check_facet(this->_M_num_get); - __ng.get(*this, 0, *this, __err, __l); - // _GLIBCXX_RESOLVE_LIB_DEFECTS - // 118. basic_istream uses nonexistent num_get member functions. - if (!(__err & ios_base::failbit) - && (numeric_limits<int>::min() <= __l - && __l <= numeric_limits<int>::max())) - __n = __l; - else - __err |= ios_base::failbit; - } - catch(...) - { this->_M_setstate(ios_base::badbit); } - if (__err) - this->setstate(__err); - } - return *this; - } - - template<typename _CharT, typename _Traits> - basic_istream<_CharT, _Traits>& - basic_istream<_CharT, _Traits>:: - operator>>(unsigned int& __n) - { - sentry __cerb(*this, false); - if (__cerb) - { - ios_base::iostate __err = ios_base::iostate(ios_base::goodbit); - try - { - const __num_get_type& __ng = __check_facet(this->_M_num_get); - __ng.get(*this, 0, *this, __err, __n); - } - catch(...) - { this->_M_setstate(ios_base::badbit); } - if (__err) - this->setstate(__err); - } - return *this; - } - - template<typename _CharT, typename _Traits> - basic_istream<_CharT, _Traits>& - basic_istream<_CharT, _Traits>:: - operator>>(long& __n) - { - sentry __cerb(*this, false); - if (__cerb) - { - ios_base::iostate __err = ios_base::iostate(ios_base::goodbit); - try - { - const __num_get_type& __ng = __check_facet(this->_M_num_get); - __ng.get(*this, 0, *this, __err, __n); - } - catch(...) - { this->_M_setstate(ios_base::badbit); } - if (__err) - this->setstate(__err); - } - return *this; - } - - template<typename _CharT, typename _Traits> - basic_istream<_CharT, _Traits>& - basic_istream<_CharT, _Traits>:: - operator>>(unsigned long& __n) - { - sentry __cerb(*this, false); - if (__cerb) - { - ios_base::iostate __err = ios_base::iostate(ios_base::goodbit); - try - { - const __num_get_type& __ng = __check_facet(this->_M_num_get); - __ng.get(*this, 0, *this, __err, __n); - } - catch(...) - { this->_M_setstate(ios_base::badbit); } - if (__err) - this->setstate(__err); - } - return *this; - } - -#ifdef _GLIBCXX_USE_LONG_LONG - template<typename _CharT, typename _Traits> - basic_istream<_CharT, _Traits>& - basic_istream<_CharT, _Traits>:: - operator>>(long long& __n) - { - sentry __cerb(*this, false); - if (__cerb) - { - ios_base::iostate __err = ios_base::iostate(ios_base::goodbit); - try - { - const __num_get_type& __ng = __check_facet(this->_M_num_get); - __ng.get(*this, 0, *this, __err, __n); - } - catch(...) - { this->_M_setstate(ios_base::badbit); } - if (__err) - this->setstate(__err); - } - return *this; - } - - template<typename _CharT, typename _Traits> - basic_istream<_CharT, _Traits>& - basic_istream<_CharT, _Traits>:: - operator>>(unsigned long long& __n) - { - sentry __cerb(*this, false); - if (__cerb) - { - ios_base::iostate __err = ios_base::iostate(ios_base::goodbit); - try - { - const __num_get_type& __ng = __check_facet(this->_M_num_get); - __ng.get(*this, 0, *this, __err, __n); - } - catch(...) - { this->_M_setstate(ios_base::badbit); } - if (__err) - this->setstate(__err); - } - return *this; - } -#endif - - template<typename _CharT, typename _Traits> - basic_istream<_CharT, _Traits>& - basic_istream<_CharT, _Traits>:: - operator>>(float& __n) - { - sentry __cerb(*this, false); - if (__cerb) - { - ios_base::iostate __err = ios_base::iostate(ios_base::goodbit); - try - { - const __num_get_type& __ng = __check_facet(this->_M_num_get); - __ng.get(*this, 0, *this, __err, __n); - } - catch(...) - { this->_M_setstate(ios_base::badbit); } - if (__err) - this->setstate(__err); - } - return *this; - } - - template<typename _CharT, typename _Traits> - basic_istream<_CharT, _Traits>& - basic_istream<_CharT, _Traits>:: - operator>>(double& __n) - { - sentry __cerb(*this, false); - if (__cerb) - { - ios_base::iostate __err = ios_base::iostate(ios_base::goodbit); - try - { - const __num_get_type& __ng = __check_facet(this->_M_num_get); - __ng.get(*this, 0, *this, __err, __n); - } - catch(...) - { this->_M_setstate(ios_base::badbit); } - if (__err) - this->setstate(__err); - } - return *this; - } - - template<typename _CharT, typename _Traits> - basic_istream<_CharT, _Traits>& - basic_istream<_CharT, _Traits>:: - operator>>(long double& __n) - { - sentry __cerb(*this, false); - if (__cerb) - { - ios_base::iostate __err = ios_base::iostate(ios_base::goodbit); - try - { - const __num_get_type& __ng = __check_facet(this->_M_num_get); - __ng.get(*this, 0, *this, __err, __n); - } - catch(...) - { this->_M_setstate(ios_base::badbit); } - if (__err) - this->setstate(__err); - } - return *this; - } - - template<typename _CharT, typename _Traits> - basic_istream<_CharT, _Traits>& - basic_istream<_CharT, _Traits>:: - operator>>(void*& __n) - { - sentry __cerb(*this, false); - if (__cerb) + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 118. basic_istream uses nonexistent num_get member functions. + long __l; + _M_extract(__l); + if (!this->fail()) { - ios_base::iostate __err = ios_base::iostate(ios_base::goodbit); - try - { - const __num_get_type& __ng = __check_facet(this->_M_num_get); - __ng.get(*this, 0, *this, __err, __n); - } - catch(...) - { this->_M_setstate(ios_base::badbit); } - if (__err) - this->setstate(__err); + if (numeric_limits<int>::min() <= __l + && __l <= numeric_limits<int>::max()) + __n = __l; + else + this->setstate(ios_base::failbit); } return *this; } @@ -421,8 +160,11 @@ namespace std { try { - if (!__copy_streambufs(this->rdbuf(), __sbout)) + bool __ineof; + if (!__copy_streambufs_eof(this->rdbuf(), __sbout, __ineof)) __err |= ios_base::failbit; + if (__ineof) + __err |= ios_base::eofbit; } catch(...) { this->_M_setstate(ios_base::failbit); } @@ -528,7 +270,10 @@ namespace std catch(...) { this->_M_setstate(ios_base::badbit); } } - *__s = char_type(); + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 243. get and getline when sentry reports failure. + if (__n > 0) + *__s = char_type(); if (!_M_gcount) __err |= ios_base::failbit; if (__err) @@ -584,90 +329,71 @@ namespace std ios_base::iostate __err = ios_base::iostate(ios_base::goodbit); sentry __cerb(*this, true); if (__cerb) - { + { try - { - const int_type __idelim = traits_type::to_int_type(__delim); - const int_type __eof = traits_type::eof(); - __streambuf_type* __sb = this->rdbuf(); - int_type __c = __sb->sgetc(); - - while (_M_gcount + 1 < __n - && !traits_type::eq_int_type(__c, __eof) - && !traits_type::eq_int_type(__c, __idelim)) - { - streamsize __size = std::min(streamsize(__sb->egptr() - - __sb->gptr()), - __n - _M_gcount - 1); - if (__size > 1) - { - const char_type* __p = traits_type::find(__sb->gptr(), - __size, - __delim); - if (__p) - __size = __p - __sb->gptr(); - traits_type::copy(__s, __sb->gptr(), __size); - __s += __size; - __sb->gbump(__size); - _M_gcount += __size; - __c = __sb->sgetc(); - } - else - { - *__s++ = traits_type::to_char_type(__c); - ++_M_gcount; - __c = __sb->snextc(); - } - } - - if (traits_type::eq_int_type(__c, __eof)) - __err |= ios_base::eofbit; - else if (traits_type::eq_int_type(__c, __idelim)) - { - ++_M_gcount; - __sb->sbumpc(); - } - else - __err |= ios_base::failbit; - } - catch(...) - { this->_M_setstate(ios_base::badbit); } - } - *__s = char_type(); + { + const int_type __idelim = traits_type::to_int_type(__delim); + const int_type __eof = traits_type::eof(); + __streambuf_type* __sb = this->rdbuf(); + int_type __c = __sb->sgetc(); + + while (_M_gcount + 1 < __n + && !traits_type::eq_int_type(__c, __eof) + && !traits_type::eq_int_type(__c, __idelim)) + { + *__s++ = traits_type::to_char_type(__c); + __c = __sb->snextc(); + ++_M_gcount; + } + if (traits_type::eq_int_type(__c, __eof)) + __err |= ios_base::eofbit; + else + { + if (traits_type::eq_int_type(__c, __idelim)) + { + __sb->sbumpc(); + ++_M_gcount; + } + else + __err |= ios_base::failbit; + } + } + catch(...) + { this->_M_setstate(ios_base::badbit); } + } + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 243. get and getline when sentry reports failure. + if (__n > 0) + *__s = char_type(); if (!_M_gcount) - __err |= ios_base::failbit; + __err |= ios_base::failbit; if (__err) - this->setstate(__err); + this->setstate(__err); return *this; } + // We provide three overloads, since the first two are much simpler + // than the general case. Also, the latter two can thus adopt the + // same "batchy" strategy used by getline above. template<typename _CharT, typename _Traits> basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>:: - ignore(streamsize __n, int_type __delim) + ignore(void) { _M_gcount = 0; sentry __cerb(*this, true); - if (__cerb && __n > 0) + if (__cerb) { ios_base::iostate __err = ios_base::iostate(ios_base::goodbit); try { const int_type __eof = traits_type::eof(); __streambuf_type* __sb = this->rdbuf(); - int_type __c; - if (__n != numeric_limits<streamsize>::max()) - --__n; - while (_M_gcount <= __n - && !traits_type::eq_int_type(__c = __sb->sbumpc(), __eof)) - { - ++_M_gcount; - if (traits_type::eq_int_type(__c, __delim)) - break; - } - if (traits_type::eq_int_type(__c, __eof)) + if (traits_type::eq_int_type(__sb->sbumpc(), __eof)) __err |= ios_base::eofbit; + else + _M_gcount = 1; } catch(...) { this->_M_setstate(ios_base::badbit); } @@ -678,6 +404,120 @@ namespace std } template<typename _CharT, typename _Traits> + basic_istream<_CharT, _Traits>& + basic_istream<_CharT, _Traits>:: + ignore(streamsize __n) + { + _M_gcount = 0; + sentry __cerb(*this, true); + if (__cerb && __n > 0) + { + ios_base::iostate __err = ios_base::iostate(ios_base::goodbit); + try + { + const int_type __eof = traits_type::eof(); + __streambuf_type* __sb = this->rdbuf(); + int_type __c = __sb->sgetc(); + + // N.B. On LFS-enabled platforms streamsize is still 32 bits + // wide: if we want to implement the standard mandated behavior + // for n == max() (see 27.6.1.3/24) we are at risk of signed + // integer overflow: thus these contortions. Also note that, + // by definition, when more than 2G chars are actually ignored, + // _M_gcount (the return value of gcount, that is) cannot be + // really correct, being unavoidably too small. + bool __large_ignore = false; + while (true) + { + while (_M_gcount < __n + && !traits_type::eq_int_type(__c, __eof)) + { + ++_M_gcount; + __c = __sb->snextc(); + } + if (__n == numeric_limits<streamsize>::max() + && !traits_type::eq_int_type(__c, __eof)) + { + _M_gcount = numeric_limits<streamsize>::min(); + __large_ignore = true; + } + else + break; + } + + if (__large_ignore) + _M_gcount = numeric_limits<streamsize>::max(); + + if (traits_type::eq_int_type(__c, __eof)) + __err |= ios_base::eofbit; + } + catch(...) + { this->_M_setstate(ios_base::badbit); } + if (__err) + this->setstate(__err); + } + return *this; + } + + template<typename _CharT, typename _Traits> + basic_istream<_CharT, _Traits>& + basic_istream<_CharT, _Traits>:: + ignore(streamsize __n, int_type __delim) + { + _M_gcount = 0; + sentry __cerb(*this, true); + if (__cerb && __n > 0) + { + ios_base::iostate __err = ios_base::iostate(ios_base::goodbit); + try + { + const int_type __eof = traits_type::eof(); + __streambuf_type* __sb = this->rdbuf(); + int_type __c = __sb->sgetc(); + + // See comment above. + bool __large_ignore = false; + while (true) + { + while (_M_gcount < __n + && !traits_type::eq_int_type(__c, __eof) + && !traits_type::eq_int_type(__c, __delim)) + { + ++_M_gcount; + __c = __sb->snextc(); + } + if (__n == numeric_limits<streamsize>::max() + && !traits_type::eq_int_type(__c, __eof) + && !traits_type::eq_int_type(__c, __delim)) + { + _M_gcount = numeric_limits<streamsize>::min(); + __large_ignore = true; + } + else + break; + } + + if (__large_ignore) + _M_gcount = numeric_limits<streamsize>::max(); + + if (traits_type::eq_int_type(__c, __eof)) + __err |= ios_base::eofbit; + else if (traits_type::eq_int_type(__c, __delim)) + { + if (_M_gcount < numeric_limits<streamsize>::max()) + ++_M_gcount; + __sb->sbumpc(); + } + } + catch(...) + { this->_M_setstate(ios_base::badbit); } + if (__err) + this->setstate(__err); + } + return *this; + } + + template<typename _CharT, typename _Traits> typename basic_istream<_CharT, _Traits>::int_type basic_istream<_CharT, _Traits>:: peek(void) @@ -851,7 +691,8 @@ namespace std try { if (!this->fail()) - __ret = this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::in); + __ret = this->rdbuf()->pubseekoff(0, ios_base::cur, + ios_base::in); } catch(...) { this->_M_setstate(ios_base::badbit); } @@ -873,8 +714,8 @@ namespace std // 136. seekp, seekg setting wrong streams? const pos_type __p = this->rdbuf()->pubseekpos(__pos, ios_base::in); - - // 129. Need error indication from seekp() and seekg() + + // 129. Need error indication from seekp() and seekg() if (__p == pos_type(off_type(-1))) __err |= ios_base::failbit; } @@ -901,8 +742,8 @@ namespace std // 136. seekp, seekg setting wrong streams? const pos_type __p = this->rdbuf()->pubseekoff(__off, __dir, ios_base::in); - - // 129. Need error indication from seekp() and seekg() + + // 129. Need error indication from seekp() and seekg() if (__p == pos_type(off_type(-1))) __err |= ios_base::failbit; } @@ -1108,10 +949,7 @@ namespace std { try { - // Avoid reallocation for common case. __str.erase(); - _CharT __buf[128]; - __size_type __len = 0; const __int_type __idelim = _Traits::to_int_type(__delim); const __int_type __eof = _Traits::eof(); __streambuf_type* __sb = __in.rdbuf(); @@ -1121,16 +959,10 @@ namespace std && !_Traits::eq_int_type(__c, __eof) && !_Traits::eq_int_type(__c, __idelim)) { - if (__len == sizeof(__buf) / sizeof(_CharT)) - { - __str.append(__buf, sizeof(__buf) / sizeof(_CharT)); - __len = 0; - } - __buf[__len++] = _Traits::to_char_type(__c); + __str += _Traits::to_char_type(__c); ++__extracted; __c = __sb->snextc(); } - __str.append(__buf, __len); if (_Traits::eq_int_type(__c, __eof)) __err |= ios_base::eofbit; @@ -1157,12 +989,6 @@ namespace std return __in; } - template<class _CharT, class _Traits, class _Alloc> - inline basic_istream<_CharT,_Traits>& - getline(basic_istream<_CharT, _Traits>& __in, - basic_string<_CharT,_Traits,_Alloc>& __str) - { return getline(__in, __str, __in.widen('\n')); } - // Inhibit implicit instantiations for required instantiations, // which are defined via explicit instantiations elsewhere. // NB: This syntax is a GNU extension. @@ -1176,6 +1002,20 @@ namespace std extern template istream& operator>>(istream&, unsigned char*); extern template istream& operator>>(istream&, signed char*); + extern template istream& istream::_M_extract(unsigned short&); + extern template istream& istream::_M_extract(unsigned int&); + extern template istream& istream::_M_extract(long&); + extern template istream& istream::_M_extract(unsigned long&); + extern template istream& istream::_M_extract(bool&); +#ifdef _GLIBCXX_USE_LONG_LONG + extern template istream& istream::_M_extract(long long&); + extern template istream& istream::_M_extract(unsigned long long&); +#endif + extern template istream& istream::_M_extract(float&); + extern template istream& istream::_M_extract(double&); + extern template istream& istream::_M_extract(long double&); + extern template istream& istream::_M_extract(void*&); + extern template class basic_iostream<char>; #ifdef _GLIBCXX_USE_WCHAR_T @@ -1184,9 +1024,24 @@ namespace std extern template wistream& operator>>(wistream&, wchar_t&); extern template wistream& operator>>(wistream&, wchar_t*); + extern template wistream& wistream::_M_extract(unsigned short&); + extern template wistream& wistream::_M_extract(unsigned int&); + extern template wistream& wistream::_M_extract(long&); + extern template wistream& wistream::_M_extract(unsigned long&); + extern template wistream& wistream::_M_extract(bool&); +#ifdef _GLIBCXX_USE_LONG_LONG + extern template wistream& wistream::_M_extract(long long&); + extern template wistream& wistream::_M_extract(unsigned long long&); +#endif + extern template wistream& wistream::_M_extract(float&); + extern template wistream& wistream::_M_extract(double&); + extern template wistream& wistream::_M_extract(long double&); + extern template wistream& wistream::_M_extract(void*&); + extern template class basic_iostream<wchar_t>; #endif #endif -} // namespace std + +_GLIBCXX_END_NAMESPACE #endif diff --git a/contrib/libstdc++/include/bits/list.tcc b/contrib/libstdc++/include/bits/list.tcc index aaaa8c3..f2849fb 100644 --- a/contrib/libstdc++/include/bits/list.tcc +++ b/contrib/libstdc++/include/bits/list.tcc @@ -1,6 +1,7 @@ // List implementation (out of line) -*- C++ -*- -// Copyright (C) 2001, 2002, 2003, 2004 Free Software Foundation, Inc. +// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 +// 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 @@ -15,7 +16,7 @@ // 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// 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 @@ -61,52 +62,52 @@ #ifndef _LIST_TCC #define _LIST_TCC 1 -namespace _GLIBCXX_STD -{ +_GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD) + template<typename _Tp, typename _Alloc> void - _List_base<_Tp,_Alloc>:: + _List_base<_Tp, _Alloc>:: _M_clear() { typedef _List_node<_Tp> _Node; _Node* __cur = static_cast<_Node*>(this->_M_impl._M_node._M_next); while (__cur != &this->_M_impl._M_node) - { - _Node* __tmp = __cur; - __cur = static_cast<_Node*>(__cur->_M_next); - std::_Destroy(&__tmp->_M_data); - _M_put_node(__tmp); - } + { + _Node* __tmp = __cur; + __cur = static_cast<_Node*>(__cur->_M_next); + _M_get_Tp_allocator().destroy(&__tmp->_M_data); + _M_put_node(__tmp); + } } template<typename _Tp, typename _Alloc> - typename list<_Tp,_Alloc>::iterator - list<_Tp,_Alloc>:: + typename list<_Tp, _Alloc>::iterator + list<_Tp, _Alloc>:: insert(iterator __position, const value_type& __x) { _Node* __tmp = _M_create_node(__x); __tmp->hook(__position._M_node); - return __tmp; + return iterator(__tmp); } template<typename _Tp, typename _Alloc> - typename list<_Tp,_Alloc>::iterator - list<_Tp,_Alloc>:: + typename list<_Tp, _Alloc>::iterator + list<_Tp, _Alloc>:: erase(iterator __position) { - iterator __ret = __position._M_node->_M_next; + iterator __ret = iterator(__position._M_node->_M_next); _M_erase(__position); return __ret; } template<typename _Tp, typename _Alloc> void - list<_Tp,_Alloc>:: - resize(size_type __new_size, const value_type& __x) + list<_Tp, _Alloc>:: + resize(size_type __new_size, value_type __x) { iterator __i = begin(); size_type __len = 0; - for ( ; __i != end() && __len < __new_size; ++__i, ++__len) + for (; __i != end() && __len < __new_size; ++__i, ++__len) ; if (__len == __new_size) erase(__i, end()); @@ -115,8 +116,8 @@ namespace _GLIBCXX_STD } template<typename _Tp, typename _Alloc> - list<_Tp,_Alloc>& - list<_Tp,_Alloc>:: + list<_Tp, _Alloc>& + list<_Tp, _Alloc>:: operator=(const list& __x) { if (this != &__x) @@ -125,8 +126,9 @@ namespace _GLIBCXX_STD iterator __last1 = end(); const_iterator __first2 = __x.begin(); const_iterator __last2 = __x.end(); - while (__first1 != __last1 && __first2 != __last2) - *__first1++ = *__first2++; + for (; __first1 != __last1 && __first2 != __last2; + ++__first1, ++__first2) + *__first1 = *__first2; if (__first2 == __last2) erase(__first1, __last1); else @@ -137,11 +139,11 @@ namespace _GLIBCXX_STD template<typename _Tp, typename _Alloc> void - list<_Tp,_Alloc>:: + list<_Tp, _Alloc>:: _M_fill_assign(size_type __n, const value_type& __val) { iterator __i = begin(); - for ( ; __i != end() && __n > 0; ++__i, --__n) + for (; __i != end() && __n > 0; ++__i, --__n) *__i = __val; if (__n > 0) insert(end(), __n, __val); @@ -152,7 +154,7 @@ namespace _GLIBCXX_STD template<typename _Tp, typename _Alloc> template <typename _InputIterator> void - list<_Tp,_Alloc>:: + list<_Tp, _Alloc>:: _M_assign_dispatch(_InputIterator __first2, _InputIterator __last2, __false_type) { @@ -169,24 +171,24 @@ namespace _GLIBCXX_STD template<typename _Tp, typename _Alloc> void - list<_Tp,_Alloc>:: + list<_Tp, _Alloc>:: remove(const value_type& __value) { iterator __first = begin(); iterator __last = end(); while (__first != __last) - { - iterator __next = __first; - ++__next; - if (*__first == __value) - _M_erase(__first); - __first = __next; - } + { + iterator __next = __first; + ++__next; + if (*__first == __value) + _M_erase(__first); + __first = __next; + } } template<typename _Tp, typename _Alloc> void - list<_Tp,_Alloc>:: + list<_Tp, _Alloc>:: unique() { iterator __first = begin(); @@ -195,24 +197,26 @@ namespace _GLIBCXX_STD return; iterator __next = __first; while (++__next != __last) - { - if (*__first == *__next) - _M_erase(__next); - else - __first = __next; - __next = __first; - } + { + if (*__first == *__next) + _M_erase(__next); + else + __first = __next; + __next = __first; + } } template<typename _Tp, typename _Alloc> void - list<_Tp,_Alloc>:: + list<_Tp, _Alloc>:: merge(list& __x) { // _GLIBCXX_RESOLVE_LIB_DEFECTS // 300. list::merge() specification incomplete if (this != &__x) { + _M_check_equal_allocators(__x); + iterator __first1 = begin(); iterator __last1 = end(); iterator __first2 = __x.begin(); @@ -232,8 +236,38 @@ namespace _GLIBCXX_STD } template<typename _Tp, typename _Alloc> + template <typename _StrictWeakOrdering> + void + list<_Tp, _Alloc>:: + merge(list& __x, _StrictWeakOrdering __comp) + { + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 300. list::merge() specification incomplete + if (this != &__x) + { + _M_check_equal_allocators(__x); + + iterator __first1 = begin(); + iterator __last1 = end(); + iterator __first2 = __x.begin(); + iterator __last2 = __x.end(); + while (__first1 != __last1 && __first2 != __last2) + if (__comp(*__first2, *__first1)) + { + iterator __next = __first2; + _M_transfer(__first1, __first2, ++__next); + __first2 = __next; + } + else + ++__first1; + if (__first2 != __last2) + _M_transfer(__last1, __first2, __last2); + } + } + + template<typename _Tp, typename _Alloc> void - list<_Tp,_Alloc>:: + list<_Tp, _Alloc>:: sort() { // Do nothing if the list has length 0 or 1. @@ -250,7 +284,7 @@ namespace _GLIBCXX_STD __carry.splice(__carry.begin(), *this, begin()); for(__counter = &__tmp[0]; - (__counter != __fill) && !__counter->empty(); + __counter != __fill && !__counter->empty(); ++__counter) { __counter->merge(__carry); @@ -262,82 +296,55 @@ namespace _GLIBCXX_STD } while ( !empty() ); - for (__counter = &__tmp[1]; __counter != __fill; ++__counter) - __counter->merge( *(__counter-1) ); - swap( *(__fill-1) ); + for (__counter = &__tmp[1]; __counter != __fill; ++__counter) + __counter->merge(*(__counter - 1)); + swap( *(__fill - 1) ); } } template<typename _Tp, typename _Alloc> template <typename _Predicate> void - list<_Tp,_Alloc>:: + list<_Tp, _Alloc>:: remove_if(_Predicate __pred) { iterator __first = begin(); iterator __last = end(); while (__first != __last) - { - iterator __next = __first; - ++__next; - if (__pred(*__first)) - _M_erase(__first); - __first = __next; - } + { + iterator __next = __first; + ++__next; + if (__pred(*__first)) + _M_erase(__first); + __first = __next; + } } template<typename _Tp, typename _Alloc> template <typename _BinaryPredicate> void - list<_Tp,_Alloc>:: + list<_Tp, _Alloc>:: unique(_BinaryPredicate __binary_pred) { iterator __first = begin(); iterator __last = end(); - if (__first == __last) return; + if (__first == __last) + return; iterator __next = __first; while (++__next != __last) - { - if (__binary_pred(*__first, *__next)) - _M_erase(__next); - else - __first = __next; - __next = __first; - } - } - - template<typename _Tp, typename _Alloc> - template <typename _StrictWeakOrdering> - void - list<_Tp,_Alloc>:: - merge(list& __x, _StrictWeakOrdering __comp) - { - // _GLIBCXX_RESOLVE_LIB_DEFECTS - // 300. list::merge() specification incomplete - if (this != &__x) { - iterator __first1 = begin(); - iterator __last1 = end(); - iterator __first2 = __x.begin(); - iterator __last2 = __x.end(); - while (__first1 != __last1 && __first2 != __last2) - if (__comp(*__first2, *__first1)) - { - iterator __next = __first2; - _M_transfer(__first1, __first2, ++__next); - __first2 = __next; - } - else - ++__first1; - if (__first2 != __last2) - _M_transfer(__last1, __first2, __last2); + if (__binary_pred(*__first, *__next)) + _M_erase(__next); + else + __first = __next; + __next = __first; } } template<typename _Tp, typename _Alloc> template <typename _StrictWeakOrdering> void - list<_Tp,_Alloc>:: + list<_Tp, _Alloc>:: sort(_StrictWeakOrdering __comp) { // Do nothing if the list has length 0 or 1. @@ -354,7 +361,7 @@ namespace _GLIBCXX_STD __carry.splice(__carry.begin(), *this, begin()); for(__counter = &__tmp[0]; - (__counter != __fill) && !__counter->empty(); + __counter != __fill && !__counter->empty(); ++__counter) { __counter->merge(__carry, __comp); @@ -366,12 +373,13 @@ namespace _GLIBCXX_STD } while ( !empty() ); - for (__counter = &__tmp[1]; __counter != __fill; ++__counter) - __counter->merge( *(__counter-1), __comp ); - swap( *(__fill-1) ); + for (__counter = &__tmp[1]; __counter != __fill; ++__counter) + __counter->merge(*(__counter - 1), __comp); + swap(*(__fill - 1)); } } -} // namespace std + +_GLIBCXX_END_NESTED_NAMESPACE #endif /* _LIST_TCC */ diff --git a/contrib/libstdc++/include/bits/locale_classes.h b/contrib/libstdc++/include/bits/locale_classes.h index 95d9c03..547e21d 100644 --- a/contrib/libstdc++/include/bits/locale_classes.h +++ b/contrib/libstdc++/include/bits/locale_classes.h @@ -1,6 +1,6 @@ // Locale support -*- C++ -*- -// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004 +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 // Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free @@ -16,7 +16,7 @@ // 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// 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 @@ -28,15 +28,15 @@ // invalidate any other reasons why the executable file might be covered by // the GNU General Public License. -// -// ISO C++ 14882: 22.1 Locales -// - -/** @file localefwd.h +/** @file locale_classes.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_CLASSES_H #define _LOCALE_CLASSES_H 1 @@ -45,11 +45,10 @@ #include <bits/localefwd.h> #include <cstring> // For strcmp. #include <string> -#include <bits/atomicity.h> -#include <bits/gthr.h> +#include <ext/atomicity.h> + +_GLIBCXX_BEGIN_NAMESPACE(std) -namespace std -{ // 22.1.1 Class locale /** * @brief Container class for localization functionality. @@ -307,7 +306,7 @@ namespace std // macros. For GNU systems, the following are also valid: // LC_PAPER, LC_NAME, LC_ADDRESS, LC_TELEPHONE, LC_MEASUREMENT, // and LC_IDENTIFICATION. - static const size_t _S_categories_size = 6 + _GLIBCXX_NUM_CATEGORIES; + enum { _S_categories_size = 6 + _GLIBCXX_NUM_CATEGORIES }; #ifdef __GTHREADS static __gthread_once_t _S_once; @@ -400,12 +399,12 @@ namespace std private: inline void _M_add_reference() const throw() - { __gnu_cxx::__atomic_add(&_M_refcount, 1); } + { __gnu_cxx::__atomic_add_dispatch(&_M_refcount, 1); } inline void _M_remove_reference() const throw() { - if (__gnu_cxx::__exchange_and_add(&_M_refcount, -1) == 1) + if (__gnu_cxx::__exchange_and_add_dispatch(&_M_refcount, -1) == 1) { try { delete this; } @@ -505,12 +504,12 @@ namespace std inline void _M_add_reference() throw() - { __gnu_cxx::__atomic_add(&_M_refcount, 1); } + { __gnu_cxx::__atomic_add_dispatch(&_M_refcount, 1); } inline void _M_remove_reference() throw() { - if (__gnu_cxx::__exchange_and_add(&_M_refcount, -1) == 1) + if (__gnu_cxx::__exchange_and_add_dispatch(&_M_refcount, -1) == 1) { try { delete this; } @@ -534,8 +533,10 @@ namespace std _M_check_same_name() { bool __ret = true; - for (size_t __i = 0; __ret && __i < _S_categories_size - 1; ++__i) - __ret = std::strcmp(_M_names[__i], _M_names[__i + 1]) == 0; + if (_M_names[1]) + // We must actually compare all the _M_names: can be all equal! + for (size_t __i = 0; __ret && __i < _S_categories_size - 1; ++__i) + __ret = std::strcmp(_M_names[__i], _M_names[__i + 1]) == 0; return __ret; } @@ -557,11 +558,7 @@ namespace std { _M_install_facet(&_Facet::id, __facet); } void - _M_install_cache(const facet* __cache, size_t __index) throw() - { - __cache->_M_add_reference(); - _M_caches[__index] = __cache; - } + _M_install_cache(const facet*, size_t); }; template<typename _Facet> @@ -569,31 +566,17 @@ namespace std { _M_impl = new _Impl(*__other._M_impl, 1); - char* _M_tmp_names[_S_categories_size]; - size_t __i = 0; try - { - for (; __i < _S_categories_size; ++__i) - { - _M_tmp_names[__i] = new char[2]; - std::strcpy(_M_tmp_names[__i], "*"); - } - _M_impl->_M_install_facet(&_Facet::id, __f); - } + { _M_impl->_M_install_facet(&_Facet::id, __f); } catch(...) { _M_impl->_M_remove_reference(); - for (size_t __j = 0; __j < __i; ++__j) - delete [] _M_tmp_names[__j]; __throw_exception_again; } - - for (size_t __k = 0; __k < _S_categories_size; ++__k) - { - delete [] _M_impl->_M_names[__k]; - _M_impl->_M_names[__k] = _M_tmp_names[__k]; - } + delete [] _M_impl->_M_names[0]; + _M_impl->_M_names[0] = 0; // Unnamed. } -} // namespace std + +_GLIBCXX_END_NAMESPACE #endif diff --git a/contrib/libstdc++/include/bits/locale_facets.h b/contrib/libstdc++/include/bits/locale_facets.h index db0e951..e31ae17 100644 --- a/contrib/libstdc++/include/bits/locale_facets.h +++ b/contrib/libstdc++/include/bits/locale_facets.h @@ -1,6 +1,6 @@ // Locale support -*- C++ -*- -// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 // Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free @@ -16,7 +16,7 @@ // 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// 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 @@ -28,15 +28,15 @@ // invalidate any other reasons why the executable file might be covered by // the GNU General Public License. -// -// ISO C++ 14882: 22.1 Locales -// - /** @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 @@ -44,12 +44,14 @@ #include <ctime> // For struct tm #include <cwctype> // For wctype_t +#include <bits/ctype_base.h> #include <iosfwd> #include <bits/ios_base.h> // For ios_base, ios_base::iostate #include <streambuf> +#include <bits/cpp_type_traits.h> + +_GLIBCXX_BEGIN_NAMESPACE(std) -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 @@ -129,7 +131,6 @@ namespace std // 22.2.1.1 Template class ctype // Include host and configuration specific ctype enums for ctype_base. - #include <bits/ctype_base.h> // Common base for ctype<_CharT>. /** @@ -1504,10 +1505,7 @@ namespace std use_facet<ctype<wchar_t> >(const locale& __loc); #endif //_GLIBCXX_USE_WCHAR_T - // Include host and configuration specific ctype inlines. - #include <bits/ctype_inline.h> - - // 22.2.1.2 Template class ctype_byname + /// @brief class ctype_byname [22.2.1.2]. template<typename _CharT> class ctype_byname : public ctype<_CharT> { @@ -1522,15 +1520,22 @@ namespace std ~ctype_byname() { }; }; - // 22.2.1.4 Class ctype_byname specializations. + /// 22.2.1.4 Class ctype_byname specializations. template<> ctype_byname<char>::ctype_byname(const char*, size_t refs); template<> ctype_byname<wchar_t>::ctype_byname(const char*, size_t refs); - // 22.2.1.5 Template class codecvt - #include <bits/codecvt.h> +_GLIBCXX_END_NAMESPACE + +// Include host and configuration specific ctype inlines. +#include <bits/ctype_inline.h> + +// 22.2.1.5 Template class codecvt +#include <bits/codecvt.h> + +_GLIBCXX_BEGIN_NAMESPACE(std) // 22.2.2 The numeric category. class __num_base @@ -1884,6 +1889,7 @@ namespace std numpunct<wchar_t>::_M_initialize_numpunct(__c_locale __cloc); #endif + /// @brief class numpunct_byname [22.2.3.2]. template<typename _CharT> class numpunct_byname : public numpunct<_CharT> { @@ -1909,6 +1915,7 @@ namespace std ~numpunct_byname() { } }; +_GLIBCXX_BEGIN_LDBL_NAMESPACE /** * @brief Facet for parsing number strings. * @@ -1949,7 +1956,7 @@ namespace std * @brief Numeric parsing. * * Parses the input stream into the bool @a v. It does so by calling - * num_put::do_put(). + * num_get::do_get(). * * If ios_base::boolalpha is set, attempts to read * ctype<CharT>::truename() or ctype<CharT>::falsename(). Sets @@ -1978,7 +1985,7 @@ namespace std * @brief Numeric parsing. * * Parses the input stream into the integral variable @a v. It does so - * by calling num_put::do_put(). + * by calling num_get::do_get(). * * Parsing is affected by the flag settings in @a io. * @@ -2042,7 +2049,7 @@ namespace std * @brief Numeric parsing. * * Parses the input stream into the integral variable @a v. It does so - * by calling num_put::do_put(). + * by calling num_get::do_get(). * * The input characters are parsed like the scanf %g specifier. The * matching type length modifier is also used. @@ -2083,7 +2090,7 @@ namespace std * @brief Numeric parsing. * * Parses the input stream into the pointer variable @a v. It does so - * by calling num_put::do_put(). + * by calling num_get::do_get(). * * The input characters are parsed like the scanf %p specifier. * @@ -2123,6 +2130,44 @@ namespace std _M_extract_int(iter_type, iter_type, ios_base&, ios_base::iostate&, _ValueT& __v) const; + template<typename _CharT2> + typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value, int>::__type + _M_find(const _CharT2*, size_t __len, _CharT2 __c) const + { + int __ret = -1; + if (__len <= 10) + { + if (__c >= _CharT2('0') && __c < _CharT2(_CharT2('0') + __len)) + __ret = __c - _CharT2('0'); + } + else + { + if (__c >= _CharT2('0') && __c <= _CharT2('9')) + __ret = __c - _CharT2('0'); + else if (__c >= _CharT2('a') && __c <= _CharT2('f')) + __ret = 10 + (__c - _CharT2('a')); + else if (__c >= _CharT2('A') && __c <= _CharT2('F')) + __ret = 10 + (__c - _CharT2('A')); + } + return __ret; + } + + template<typename _CharT2> + typename __gnu_cxx::__enable_if<!__is_char<_CharT2>::__value, + int>::__type + _M_find(const _CharT2* __zero, size_t __len, _CharT2 __c) const + { + int __ret = -1; + const char_type* __q = char_traits<_CharT2>::find(__zero, __len, __c); + if (__q) + { + __ret = __q - __zero; + if (__ret > 15) + __ret -= 6; + } + return __ret; + } + //@{ /** * @brief Numeric parsing. @@ -2175,13 +2220,27 @@ namespace std do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err, double&) const; + // XXX GLIBCXX_ABI Deprecated +#if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__ + virtual iter_type + __do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err, + double&) const; +#else virtual iter_type do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err, long double&) const; +#endif virtual iter_type do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err, void*&) const; + + // XXX GLIBCXX_ABI Deprecated +#if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__ + virtual iter_type + do_get(iter_type, iter_type, ios_base&, ios_base::iostate& __err, + long double&) const; +#endif //@} }; @@ -2437,17 +2496,30 @@ namespace std virtual iter_type do_put(iter_type, ios_base&, char_type __fill, double __v) const; + // XXX GLIBCXX_ABI Deprecated +#if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__ + virtual iter_type + __do_put(iter_type, ios_base&, char_type __fill, double __v) const; +#else virtual iter_type do_put(iter_type, ios_base&, char_type __fill, long double __v) const; +#endif virtual iter_type do_put(iter_type, ios_base&, char_type __fill, const void* __v) const; + + // XXX GLIBCXX_ABI Deprecated +#if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__ + virtual iter_type + do_put(iter_type, ios_base&, char_type __fill, long double __v) const; +#endif //@} }; template <typename _CharT, typename _OutIter> locale::id num_put<_CharT, _OutIter>::id; +_GLIBCXX_END_LDBL_NAMESPACE /** * @brief Facet for localized string comparison. @@ -2636,6 +2708,7 @@ namespace std collate<wchar_t>::_M_transform(wchar_t*, const wchar_t*, size_t) const; #endif + /// @brief class collate_byname [22.2.4.2]. template<typename _CharT> class collate_byname : public collate<_CharT> { @@ -2830,6 +2903,8 @@ namespace std explicit __timepunct(__c_locale __cloc, const char* __s, size_t __refs = 0); + // FIXME: for error checking purposes _M_put should return the return + // value of strftime/wcsftime. void _M_put(_CharT* __s, size_t __maxlen, const _CharT* __format, const tm* __tm) const; @@ -2959,9 +3034,13 @@ namespace std const tm*) const; #endif +_GLIBCXX_END_NAMESPACE + // Include host and configuration specific timepunct functions. #include <bits/time_members.h> +_GLIBCXX_BEGIN_NAMESPACE(std) + /** * @brief Facet for parsing dates and times. * @@ -3286,6 +3365,7 @@ namespace std template<typename _CharT, typename _InIter> locale::id time_get<_CharT, _InIter>::id; + /// @brief class time_get_byname [22.2.5.2]. template<typename _CharT, typename _InIter> class time_get_byname : public time_get<_CharT, _InIter> { @@ -3409,6 +3489,7 @@ namespace std template<typename _CharT, typename _OutIter> locale::id time_put<_CharT, _OutIter>::id; + /// @brief class time_put_byname [22.2.5.4]. template<typename _CharT, typename _OutIter> class time_put_byname : public time_put<_CharT, _OutIter> { @@ -3916,6 +3997,7 @@ namespace std const char*); #endif + /// @brief class moneypunct_byname [22.2.6.4]. template<typename _CharT, bool _Intl> class moneypunct_byname : public moneypunct<_CharT, _Intl> { @@ -3946,6 +4028,7 @@ namespace std template<typename _CharT, bool _Intl> const bool moneypunct_byname<_CharT, _Intl>::intl; +_GLIBCXX_BEGIN_LDBL_NAMESPACE /** * @brief Facet for parsing monetary amounts. * @@ -4057,9 +4140,16 @@ namespace std * value. This function is a hook for derived classes to change the * value returned. @see get() for details. */ + // XXX GLIBCXX_ABI Deprecated +#if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__ + virtual iter_type + __do_get(iter_type __s, iter_type __end, bool __intl, ios_base& __io, + ios_base::iostate& __err, double& __units) const; +#else virtual iter_type do_get(iter_type __s, iter_type __end, bool __intl, ios_base& __io, ios_base::iostate& __err, long double& __units) const; +#endif /** * @brief Read and parse a monetary value. @@ -4072,6 +4162,13 @@ namespace std do_get(iter_type __s, iter_type __end, bool __intl, ios_base& __io, ios_base::iostate& __err, string_type& __digits) const; + // XXX GLIBCXX_ABI Deprecated +#if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__ + virtual iter_type + do_get(iter_type __s, iter_type __end, bool __intl, ios_base& __io, + ios_base::iostate& __err, long double& __units) const; +#endif + template<bool _Intl> iter_type _M_extract(iter_type __s, iter_type __end, ios_base& __io, @@ -4184,9 +4281,16 @@ namespace std * @param units Place to store result of parsing. * @return Iterator after writing. */ + // XXX GLIBCXX_ABI Deprecated +#if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__ + virtual iter_type + __do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill, + double __units) const; +#else virtual iter_type do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill, long double __units) const; +#endif /** * @brief Format and output a monetary value. @@ -4210,6 +4314,13 @@ namespace std do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill, const string_type& __digits) const; + // XXX GLIBCXX_ABI Deprecated +#if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__ + virtual iter_type + do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill, + long double __units) const; +#endif + template<bool _Intl> iter_type _M_insert(iter_type __s, ios_base& __io, char_type __fill, @@ -4219,6 +4330,8 @@ namespace std template<typename _CharT, typename _OutIter> locale::id money_put<_CharT, _OutIter>::id; +_GLIBCXX_END_LDBL_NAMESPACE + /** * @brief Messages facet base class providing catalog typedef. */ @@ -4463,7 +4576,8 @@ namespace std messages<wchar_t>::do_get(catalog, int, int, const wstring&) const; #endif - template<typename _CharT> + /// @brief class messages_byname [22.2.7.2]. + template<typename _CharT> class messages_byname : public messages<_CharT> { public: @@ -4479,80 +4593,96 @@ namespace std { } }; +_GLIBCXX_END_NAMESPACE + // Include host and configuration specific messages functions. #include <bits/messages_members.h> +_GLIBCXX_BEGIN_NAMESPACE(std) // Subclause convenience interfaces, inlines. // NB: These are inline because, when used in a loop, some compilers // can hoist the body out of the loop; then it's just as fast as the // C is*() function. - //@{ - /// Convenience interface to ctype.is(). + + /// Convenience interface to ctype.is(ctype_base::space, __c). template<typename _CharT> inline bool isspace(_CharT __c, const locale& __loc) { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::space, __c); } + /// Convenience interface to ctype.is(ctype_base::print, __c). template<typename _CharT> inline bool isprint(_CharT __c, const locale& __loc) { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::print, __c); } + /// Convenience interface to ctype.is(ctype_base::cntrl, __c). template<typename _CharT> inline bool iscntrl(_CharT __c, const locale& __loc) { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::cntrl, __c); } + /// Convenience interface to ctype.is(ctype_base::upper, __c). template<typename _CharT> inline bool isupper(_CharT __c, const locale& __loc) { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::upper, __c); } + /// Convenience interface to ctype.is(ctype_base::lower, __c). template<typename _CharT> - inline bool islower(_CharT __c, const locale& __loc) + inline bool + islower(_CharT __c, const locale& __loc) { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::lower, __c); } + /// Convenience interface to ctype.is(ctype_base::alpha, __c). template<typename _CharT> inline bool isalpha(_CharT __c, const locale& __loc) { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::alpha, __c); } + /// Convenience interface to ctype.is(ctype_base::digit, __c). template<typename _CharT> inline bool isdigit(_CharT __c, const locale& __loc) { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::digit, __c); } + /// Convenience interface to ctype.is(ctype_base::punct, __c). template<typename _CharT> inline bool ispunct(_CharT __c, const locale& __loc) { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::punct, __c); } + /// Convenience interface to ctype.is(ctype_base::xdigit, __c). template<typename _CharT> inline bool isxdigit(_CharT __c, const locale& __loc) { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::xdigit, __c); } + /// Convenience interface to ctype.is(ctype_base::alnum, __c). template<typename _CharT> inline bool isalnum(_CharT __c, const locale& __loc) { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::alnum, __c); } + /// Convenience interface to ctype.is(ctype_base::graph, __c). template<typename _CharT> inline bool isgraph(_CharT __c, const locale& __loc) { return use_facet<ctype<_CharT> >(__loc).is(ctype_base::graph, __c); } + /// Convenience interface to ctype.toupper(__c). template<typename _CharT> inline _CharT toupper(_CharT __c, const locale& __loc) { return use_facet<ctype<_CharT> >(__loc).toupper(__c); } + /// Convenience interface to ctype.tolower(__c). template<typename _CharT> inline _CharT tolower(_CharT __c, const locale& __loc) { return use_facet<ctype<_CharT> >(__loc).tolower(__c); } - //@} -} // namespace std + +_GLIBCXX_END_NAMESPACE #endif diff --git a/contrib/libstdc++/include/bits/locale_facets.tcc b/contrib/libstdc++/include/bits/locale_facets.tcc index 4f65844..d3c47ff 100644 --- a/contrib/libstdc++/include/bits/locale_facets.tcc +++ b/contrib/libstdc++/include/bits/locale_facets.tcc @@ -1,6 +1,6 @@ // Locale support -*- C++ -*- -// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004 +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 // Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free @@ -16,7 +16,7 @@ // 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// 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 @@ -28,7 +28,10 @@ // invalidate any other reasons why the executable file might be covered by // the GNU General Public License. -// Warning: this file is not meant for user inclusion. Use <locale>. +/** @file locale_facets.tcc + * This is an internal header file, included by other library headers. + * You should not attempt to use it directly. + */ #ifndef _LOCALE_FACETS_TCC #define _LOCALE_FACETS_TCC 1 @@ -38,9 +41,10 @@ #include <limits> // For numeric_limits #include <typeinfo> // For bad_cast. #include <bits/streambuf_iterator.h> +#include <ext/type_traits.h> + +_GLIBCXX_BEGIN_NAMESPACE(std) -namespace std -{ template<typename _Facet> locale locale::combine(const locale& __other) const @@ -190,7 +194,8 @@ namespace std char* __grouping = new char[_M_grouping_size]; __np.grouping().copy(__grouping, _M_grouping_size); _M_grouping = __grouping; - _M_use_grouping = _M_grouping_size && __np.grouping()[0] != 0; + _M_use_grouping = (_M_grouping_size + && static_cast<signed char>(__np.grouping()[0]) > 0); _M_truename_size = __np.truename().size(); _CharT* __truename = new _CharT[_M_truename_size]; @@ -225,7 +230,8 @@ namespace std char* __grouping = new char[_M_grouping_size]; __mp.grouping().copy(__grouping, _M_grouping_size); _M_grouping = __grouping; - _M_use_grouping = _M_grouping_size && __mp.grouping()[0] != 0; + _M_use_grouping = (_M_grouping_size + && static_cast<signed char>(__mp.grouping()[0]) > 0); _M_decimal_point = __mp.decimal_point(); _M_thousands_sep = __mp.thousands_sep(); @@ -267,6 +273,8 @@ namespace std __verify_grouping(const char* __grouping, size_t __grouping_size, const string& __grouping_tmp); +_GLIBCXX_BEGIN_LDBL_NAMESPACE + template<typename _CharT, typename _InIter> _InIter num_get<_CharT, _InIter>:: @@ -274,33 +282,38 @@ namespace std ios_base::iostate& __err, string& __xtrc) const { typedef char_traits<_CharT> __traits_type; - typedef typename numpunct<_CharT>::__cache_type __cache_type; + typedef __numpunct_cache<_CharT> __cache_type; __use_cache<__cache_type> __uc; const locale& __loc = __io._M_getloc(); const __cache_type* __lc = __uc(__loc); const _CharT* __lit = __lc->_M_atoms_in; + char_type __c = char_type(); - // True if a mantissa is found. - bool __found_mantissa = false; + // True if __beg becomes equal to __end. + bool __testeof = __beg == __end; // First check for sign. - if (__beg != __end) + if (!__testeof) { - const char_type __c = *__beg; + __c = *__beg; const bool __plus = __c == __lit[__num_base::_S_iplus]; if ((__plus || __c == __lit[__num_base::_S_iminus]) && !(__lc->_M_use_grouping && __c == __lc->_M_thousands_sep) && !(__c == __lc->_M_decimal_point)) { __xtrc += __plus ? '+' : '-'; - ++__beg; + if (++__beg != __end) + __c = *__beg; + else + __testeof = true; } } // Next, look for leading zeros. - while (__beg != __end) + bool __found_mantissa = false; + int __sep_pos = 0; + while (!__testeof) { - const char_type __c = *__beg; if (__lc->_M_use_grouping && __c == __lc->_M_thousands_sep || __c == __lc->_M_decimal_point) break; @@ -311,7 +324,12 @@ namespace std __xtrc += '0'; __found_mantissa = true; } - ++__beg; + ++__sep_pos; + + if (++__beg != __end) + __c = *__beg; + else + __testeof = true; } else break; @@ -323,90 +341,150 @@ namespace std string __found_grouping; if (__lc->_M_use_grouping) __found_grouping.reserve(32); - int __sep_pos = 0; const char_type* __lit_zero = __lit + __num_base::_S_izero; - const char_type* __q; - while (__beg != __end) - { - // According to 22.2.2.1.2, p8-9, first look for thousands_sep - // and decimal_point. - const char_type __c = *__beg; - if (__lc->_M_use_grouping && __c == __lc->_M_thousands_sep) - { - if (!__found_dec && !__found_sci) - { - // NB: Thousands separator at the beginning of a string - // is a no-no, as is two consecutive thousands separators. - if (__sep_pos) - { - __found_grouping += static_cast<char>(__sep_pos); - __sep_pos = 0; - ++__beg; - } - else - { - __err |= ios_base::failbit; - break; - } - } - else - break; - } - else if (__c == __lc->_M_decimal_point) - { - if (!__found_dec && !__found_sci) - { - // If no grouping chars are seen, no grouping check - // is applied. Therefore __found_grouping is adjusted - // only if decimal_point comes after some thousands_sep. - if (__found_grouping.size()) - __found_grouping += static_cast<char>(__sep_pos); - __xtrc += '.'; - __found_dec = true; - ++__beg; - } - else - break; - } - else if (__q = __traits_type::find(__lit_zero, 10, __c)) - { - __xtrc += __num_base::_S_atoms_in[__q - __lit]; - __found_mantissa = true; - ++__sep_pos; - ++__beg; - } - else if ((__c == __lit[__num_base::_S_ie] - || __c == __lit[__num_base::_S_iE]) - && __found_mantissa && !__found_sci) - { - // Scientific notation. - if (__found_grouping.size() && !__found_dec) - __found_grouping += static_cast<char>(__sep_pos); - __xtrc += 'e'; - __found_sci = true; - // Remove optional plus or minus sign, if they exist. - if (++__beg != __end) - { - const bool __plus = *__beg == __lit[__num_base::_S_iplus]; - if ((__plus || *__beg == __lit[__num_base::_S_iminus]) - && !(__lc->_M_use_grouping - && *__beg == __lc->_M_thousands_sep) - && !(*__beg == __lc->_M_decimal_point)) - { + if (!__lc->_M_allocated) + // "C" locale + while (!__testeof) + { + const int __digit = _M_find(__lit_zero, 10, __c); + if (__digit != -1) + { + __xtrc += '0' + __digit; + __found_mantissa = true; + } + else if (__c == __lc->_M_decimal_point + && !__found_dec && !__found_sci) + { + __xtrc += '.'; + __found_dec = true; + } + else if ((__c == __lit[__num_base::_S_ie] + || __c == __lit[__num_base::_S_iE]) + && !__found_sci && __found_mantissa) + { + // Scientific notation. + __xtrc += 'e'; + __found_sci = true; + + // Remove optional plus or minus sign, if they exist. + if (++__beg != __end) + { + __c = *__beg; + const bool __plus = __c == __lit[__num_base::_S_iplus]; + if (__plus || __c == __lit[__num_base::_S_iminus]) __xtrc += __plus ? '+' : '-'; - ++__beg; - } - } - } - else - // Not a valid input item. - break; - } + else + continue; + } + else + { + __testeof = true; + break; + } + } + else + break; + + if (++__beg != __end) + __c = *__beg; + else + __testeof = true; + } + else + while (!__testeof) + { + // According to 22.2.2.1.2, p8-9, first look for thousands_sep + // and decimal_point. + if (__lc->_M_use_grouping && __c == __lc->_M_thousands_sep) + { + if (!__found_dec && !__found_sci) + { + // NB: Thousands separator at the beginning of a string + // is a no-no, as is two consecutive thousands separators. + if (__sep_pos) + { + __found_grouping += static_cast<char>(__sep_pos); + __sep_pos = 0; + } + else + { + // NB: __convert_to_v will not assign __v and will + // set the failbit. + __xtrc.clear(); + break; + } + } + else + break; + } + else if (__c == __lc->_M_decimal_point) + { + if (!__found_dec && !__found_sci) + { + // If no grouping chars are seen, no grouping check + // is applied. Therefore __found_grouping is adjusted + // only if decimal_point comes after some thousands_sep. + if (__found_grouping.size()) + __found_grouping += static_cast<char>(__sep_pos); + __xtrc += '.'; + __found_dec = true; + } + else + break; + } + else + { + const char_type* __q = + __traits_type::find(__lit_zero, 10, __c); + if (__q) + { + __xtrc += '0' + (__q - __lit_zero); + __found_mantissa = true; + ++__sep_pos; + } + else if ((__c == __lit[__num_base::_S_ie] + || __c == __lit[__num_base::_S_iE]) + && !__found_sci && __found_mantissa) + { + // Scientific notation. + if (__found_grouping.size() && !__found_dec) + __found_grouping += static_cast<char>(__sep_pos); + __xtrc += 'e'; + __found_sci = true; + + // Remove optional plus or minus sign, if they exist. + if (++__beg != __end) + { + __c = *__beg; + const bool __plus = __c == __lit[__num_base::_S_iplus]; + if ((__plus || __c == __lit[__num_base::_S_iminus]) + && !(__lc->_M_use_grouping + && __c == __lc->_M_thousands_sep) + && !(__c == __lc->_M_decimal_point)) + __xtrc += __plus ? '+' : '-'; + else + continue; + } + else + { + __testeof = true; + break; + } + } + else + break; + } + + if (++__beg != __end) + __c = *__beg; + else + __testeof = true; + } // Digit grouping is checked. If grouping and found_grouping don't // match, then get very very upset, and set failbit. - if (__lc->_M_use_grouping && __found_grouping.size()) + if (__found_grouping.size()) { // Add the ending grouping if a decimal or 'e'/'E' wasn't found. if (!__found_dec && !__found_sci) @@ -419,11 +497,15 @@ namespace std } // Finish up. - if (__beg == __end) + if (__testeof) __err |= ios_base::eofbit; return __beg; } +_GLIBCXX_END_LDBL_NAMESPACE + +_GLIBCXX_BEGIN_LDBL_NAMESPACE + template<typename _CharT, typename _InIter> template<typename _ValueT> _InIter @@ -431,12 +513,15 @@ namespace std _M_extract_int(_InIter __beg, _InIter __end, ios_base& __io, ios_base::iostate& __err, _ValueT& __v) const { - typedef char_traits<_CharT> __traits_type; - typedef typename numpunct<_CharT>::__cache_type __cache_type; + typedef char_traits<_CharT> __traits_type; + using __gnu_cxx::__add_unsigned; + typedef typename __add_unsigned<_ValueT>::__type __unsigned_type; + typedef __numpunct_cache<_CharT> __cache_type; __use_cache<__cache_type> __uc; const locale& __loc = __io._M_getloc(); const __cache_type* __lc = __uc(__loc); const _CharT* __lit = __lc->_M_atoms_in; + char_type __c = char_type(); // NB: Iff __basefield == 0, __base can change based on contents. const ios_base::fmtflags __basefield = __io.flags() @@ -444,165 +529,165 @@ namespace std const bool __oct = __basefield == ios_base::oct; int __base = __oct ? 8 : (__basefield == ios_base::hex ? 16 : 10); - // True if numeric digits are found. - bool __found_num = false; + // True if __beg becomes equal to __end. + bool __testeof = __beg == __end; // First check for sign. bool __negative = false; - if (__beg != __end) + if (!__testeof) { - const char_type __c = *__beg; + __c = *__beg; if (numeric_limits<_ValueT>::is_signed) __negative = __c == __lit[__num_base::_S_iminus]; if ((__negative || __c == __lit[__num_base::_S_iplus]) && !(__lc->_M_use_grouping && __c == __lc->_M_thousands_sep) && !(__c == __lc->_M_decimal_point)) - ++__beg; + { + if (++__beg != __end) + __c = *__beg; + else + __testeof = true; + } } // Next, look for leading zeros and check required digits // for base formats. - while (__beg != __end) + bool __found_zero = false; + int __sep_pos = 0; + while (!__testeof) { - const char_type __c = *__beg; if (__lc->_M_use_grouping && __c == __lc->_M_thousands_sep || __c == __lc->_M_decimal_point) break; else if (__c == __lit[__num_base::_S_izero] - && (!__found_num || __base == 10)) + && (!__found_zero || __base == 10)) { - __found_num = true; - ++__beg; + __found_zero = true; + ++__sep_pos; + if (__basefield == 0) + __base = 8; + if (__base == 8) + __sep_pos = 0; } - else if (__found_num) + else if (__found_zero + && (__c == __lit[__num_base::_S_ix] + || __c == __lit[__num_base::_S_iX])) { - if (__c == __lit[__num_base::_S_ix] - || __c == __lit[__num_base::_S_iX]) + if (__basefield == 0) + __base = 16; + if (__base == 16) { - if (__basefield == 0) - __base = 16; - if (__base == 16) - { - __found_num = false; - ++__beg; - } + __found_zero = false; + __sep_pos = 0; } - else if (__basefield == 0) - __base = 8; - break; + else + break; } else break; - } + if (++__beg != __end) + { + __c = *__beg; + if (!__found_zero) + break; + } + else + __testeof = true; + } + // At this point, base is determined. If not hex, only allow // base digits as valid input. - const size_t __len = __base == 16 ? (__num_base::_S_iend - - __num_base::_S_izero) - : __base; + const size_t __len = (__base == 16 ? __num_base::_S_iend + - __num_base::_S_izero : __base); // Extract. string __found_grouping; if (__lc->_M_use_grouping) __found_grouping.reserve(32); - int __sep_pos = 0; - bool __overflow = false; - _ValueT __result = 0; + bool __testfail = false; + const __unsigned_type __max = __negative ? + -numeric_limits<_ValueT>::min() : numeric_limits<_ValueT>::max(); + const __unsigned_type __smax = __max / __base; + __unsigned_type __result = 0; + int __digit = 0; const char_type* __lit_zero = __lit + __num_base::_S_izero; - const char_type* __q; - if (__negative) - { - const _ValueT __min = numeric_limits<_ValueT>::min() / __base; - for (; __beg != __end; ++__beg) - { - // According to 22.2.2.1.2, p8-9, first look for thousands_sep - // and decimal_point. - const char_type __c = *__beg; - if (__lc->_M_use_grouping && __c == __lc->_M_thousands_sep) - { - // NB: Thousands separator at the beginning of a string - // is a no-no, as is two consecutive thousands separators. - if (__sep_pos) - { - __found_grouping += static_cast<char>(__sep_pos); - __sep_pos = 0; - } - else - { - __err |= ios_base::failbit; - break; - } - } - else if (__c == __lc->_M_decimal_point) - break; - else if (__q = __traits_type::find(__lit_zero, __len, __c)) - { - int __digit = __q - __lit_zero; - if (__digit > 15) - __digit -= 6; - if (__result < __min) - __overflow = true; - else - { - const _ValueT __new_result = __result * __base - - __digit; - __overflow |= __new_result > __result; - __result = __new_result; - ++__sep_pos; - __found_num = true; - } - } - else - // Not a valid input item. - break; - } - } - else - { - const _ValueT __max = numeric_limits<_ValueT>::max() / __base; - for (; __beg != __end; ++__beg) - { - const char_type __c = *__beg; - if (__lc->_M_use_grouping && __c == __lc->_M_thousands_sep) - { - if (__sep_pos) - { - __found_grouping += static_cast<char>(__sep_pos); - __sep_pos = 0; - } - else - { - __err |= ios_base::failbit; - break; - } - } - else if (__c == __lc->_M_decimal_point) - break; - else if (__q = __traits_type::find(__lit_zero, __len, __c)) - { - int __digit = __q - __lit_zero; - if (__digit > 15) - __digit -= 6; - if (__result > __max) - __overflow = true; - else - { - const _ValueT __new_result = __result * __base - + __digit; - __overflow |= __new_result < __result; - __result = __new_result; - ++__sep_pos; - __found_num = true; - } - } - else - break; - } - } + if (!__lc->_M_allocated) + // "C" locale + while (!__testeof) + { + __digit = _M_find(__lit_zero, __len, __c); + if (__digit == -1) + break; + + if (__result > __smax) + __testfail = true; + else + { + __result *= __base; + __testfail |= __result > __max - __digit; + __result += __digit; + ++__sep_pos; + } + + if (++__beg != __end) + __c = *__beg; + else + __testeof = true; + } + else + while (!__testeof) + { + // According to 22.2.2.1.2, p8-9, first look for thousands_sep + // and decimal_point. + if (__lc->_M_use_grouping && __c == __lc->_M_thousands_sep) + { + // NB: Thousands separator at the beginning of a string + // is a no-no, as is two consecutive thousands separators. + if (__sep_pos) + { + __found_grouping += static_cast<char>(__sep_pos); + __sep_pos = 0; + } + else + { + __testfail = true; + break; + } + } + else if (__c == __lc->_M_decimal_point) + break; + else + { + const char_type* __q = + __traits_type::find(__lit_zero, __len, __c); + if (!__q) + break; + + __digit = __q - __lit_zero; + if (__digit > 15) + __digit -= 6; + if (__result > __smax) + __testfail = true; + else + { + __result *= __base; + __testfail |= __result > __max - __digit; + __result += __digit; + ++__sep_pos; + } + } + + if (++__beg != __end) + __c = *__beg; + else + __testeof = true; + } + // Digit grouping is checked. If grouping and found_grouping don't // match, then get very very upset, and set failbit. - if (__lc->_M_use_grouping && __found_grouping.size()) + if (__found_grouping.size()) { // Add the ending grouping. __found_grouping += static_cast<char>(__sep_pos); @@ -613,13 +698,13 @@ namespace std __err |= ios_base::failbit; } - if (!(__err & ios_base::failbit) && !__overflow - && __found_num) - __v = __result; + if (!__testfail && (__sep_pos || __found_zero + || __found_grouping.size())) + __v = __negative ? -__result : __result; else __err |= ios_base::failbit; - if (__beg == __end) + if (__testeof) __err |= ios_base::eofbit; return __beg; } @@ -647,8 +732,7 @@ namespace std else { // Parse bool values as alphanumeric. - typedef char_traits<_CharT> __traits_type; - typedef typename numpunct<_CharT>::__cache_type __cache_type; + typedef __numpunct_cache<_CharT> __cache_type; __use_cache<__cache_type> __uc; const locale& __loc = __io._M_getloc(); const __cache_type* __lc = __uc(__loc); @@ -656,22 +740,28 @@ namespace std bool __testf = true; bool __testt = true; size_t __n; - for (__n = 0; __beg != __end; ++__n, ++__beg) + bool __testeof = __beg == __end; + for (__n = 0; !__testeof; ++__n) { + const char_type __c = *__beg; + if (__testf) if (__n < __lc->_M_falsename_size) - __testf = *__beg == __lc->_M_falsename[__n]; + __testf = __c == __lc->_M_falsename[__n]; else break; if (__testt) if (__n < __lc->_M_truename_size) - __testt = *__beg == __lc->_M_truename[__n]; + __testt = __c == __lc->_M_truename[__n]; else break; if (!__testf && !__testt) break; + + if (++__beg == __end) + __testeof = true; } if (__testf && __n == __lc->_M_falsename_size) __v = 0; @@ -680,7 +770,7 @@ namespace std else __err |= ios_base::failbit; - if (__beg == __end) + if (__testeof) __err |= ios_base::eofbit; } return __beg; @@ -756,6 +846,21 @@ namespace std return __beg; } +#if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__ + template<typename _CharT, typename _InIter> + _InIter + num_get<_CharT, _InIter>:: + __do_get(iter_type __beg, iter_type __end, ios_base& __io, + ios_base::iostate& __err, double& __v) const + { + string __xtrc; + __xtrc.reserve(32); + __beg = _M_extract_float(__beg, __end, __io, __err, __xtrc); + std::__convert_to_v(__xtrc.c_str(), __v, __err, _S_get_c_locale()); + return __beg; + } +#endif + template<typename _CharT, typename _InIter> _InIter num_get<_CharT, _InIter>:: @@ -788,8 +893,6 @@ namespace std if (!(__err & ios_base::failbit)) __v = reinterpret_cast<void*>(__ul); - else - __err |= ios_base::failbit; return __beg; } @@ -808,92 +911,33 @@ namespace std __len = static_cast<int>(__w); } - // Forwarding functions to peel signed from unsigned integer types. - template<typename _CharT> - inline int - __int_to_char(_CharT* __bufend, long __v, const _CharT* __lit, - ios_base::fmtflags __flags) - { - unsigned long __ul = static_cast<unsigned long>(__v); - bool __neg = false; - if (__v < 0) - { - __ul = -__ul; - __neg = true; - } - return __int_to_char(__bufend, __ul, __lit, __flags, __neg); - } - - template<typename _CharT> - inline int - __int_to_char(_CharT* __bufend, unsigned long __v, const _CharT* __lit, - ios_base::fmtflags __flags) - { - // About showpos, see Table 60 and C99 7.19.6.1, p6 (+). - return __int_to_char(__bufend, __v, __lit, - __flags & ~ios_base::showpos, false); - } - -#ifdef _GLIBCXX_USE_LONG_LONG - template<typename _CharT> - inline int - __int_to_char(_CharT* __bufend, long long __v, const _CharT* __lit, - ios_base::fmtflags __flags) - { - unsigned long long __ull = static_cast<unsigned long long>(__v); - bool __neg = false; - if (__v < 0) - { - __ull = -__ull; - __neg = true; - } - return __int_to_char(__bufend, __ull, __lit, __flags, __neg); - } - - template<typename _CharT> - inline int - __int_to_char(_CharT* __bufend, unsigned long long __v, - const _CharT* __lit, ios_base::fmtflags __flags) - { return __int_to_char(__bufend, __v, __lit, - __flags & ~ios_base::showpos, false); } -#endif +_GLIBCXX_END_LDBL_NAMESPACE template<typename _CharT, typename _ValueT> int __int_to_char(_CharT* __bufend, _ValueT __v, const _CharT* __lit, - ios_base::fmtflags __flags, bool __neg) + ios_base::fmtflags __flags, bool __dec) { - // Don't write base if already 0. - const bool __showbase = (__flags & ios_base::showbase) && __v; - const ios_base::fmtflags __basefield = __flags & ios_base::basefield; - _CharT* __buf = __bufend - 1; - - if (__builtin_expect(__basefield != ios_base::oct && - __basefield != ios_base::hex, true)) + _CharT* __buf = __bufend; + if (__builtin_expect(__dec, true)) { // Decimal. do { - *__buf-- = __lit[(__v % 10) + __num_base::_S_odigits]; + *--__buf = __lit[(__v % 10) + __num_base::_S_odigits]; __v /= 10; } while (__v != 0); - if (__neg) - *__buf-- = __lit[__num_base::_S_ominus]; - else if (__flags & ios_base::showpos) - *__buf-- = __lit[__num_base::_S_oplus]; } - else if (__basefield == ios_base::oct) + else if ((__flags & ios_base::basefield) == ios_base::oct) { // Octal. do { - *__buf-- = __lit[(__v & 0x7) + __num_base::_S_odigits]; + *--__buf = __lit[(__v & 0x7) + __num_base::_S_odigits]; __v >>= 3; } while (__v != 0); - if (__showbase) - *__buf-- = __lit[__num_base::_S_odigits]; } else { @@ -903,54 +947,27 @@ namespace std : __num_base::_S_odigits; do { - *__buf-- = __lit[(__v & 0xf) + __case_offset]; + *--__buf = __lit[(__v & 0xf) + __case_offset]; __v >>= 4; } while (__v != 0); - if (__showbase) - { - // 'x' or 'X' - *__buf-- = __lit[__num_base::_S_ox + __uppercase]; - // '0' - *__buf-- = __lit[__num_base::_S_odigits]; - } } - return __bufend - __buf - 1; + return __bufend - __buf; } +_GLIBCXX_BEGIN_LDBL_NAMESPACE + template<typename _CharT, typename _OutIter> void num_put<_CharT, _OutIter>:: _M_group_int(const char* __grouping, size_t __grouping_size, _CharT __sep, - ios_base& __io, _CharT* __new, _CharT* __cs, int& __len) const + ios_base&, _CharT* __new, _CharT* __cs, int& __len) const { - // By itself __add_grouping cannot deal correctly with __cs when - // ios::showbase is set and ios_base::oct || ios_base::hex. - // Therefore we take care "by hand" of the initial 0, 0x or 0X. - // However, remember that the latter do not occur if the number - // printed is '0' (__len == 1). - streamsize __off = 0; - const ios_base::fmtflags __basefield = __io.flags() - & ios_base::basefield; - if ((__io.flags() & ios_base::showbase) && __len > 1) - if (__basefield == ios_base::oct) - { - __off = 1; - __new[0] = __cs[0]; - } - else if (__basefield == ios_base::hex) - { - __off = 2; - __new[0] = __cs[0]; - __new[1] = __cs[1]; - } - _CharT* __p; - __p = std::__add_grouping(__new + __off, __sep, __grouping, - __grouping_size, __cs + __off, - __cs + __len); + _CharT* __p = std::__add_grouping(__new, __sep, __grouping, + __grouping_size, __cs, __cs + __len); __len = __p - __new; } - + template<typename _CharT, typename _OutIter> template<typename _ValueT> _OutIter @@ -958,33 +975,68 @@ namespace std _M_insert_int(_OutIter __s, ios_base& __io, _CharT __fill, _ValueT __v) const { - typedef typename numpunct<_CharT>::__cache_type __cache_type; + using __gnu_cxx::__add_unsigned; + typedef typename __add_unsigned<_ValueT>::__type __unsigned_type; + typedef __numpunct_cache<_CharT> __cache_type; __use_cache<__cache_type> __uc; const locale& __loc = __io._M_getloc(); const __cache_type* __lc = __uc(__loc); const _CharT* __lit = __lc->_M_atoms_out; + const ios_base::fmtflags __flags = __io.flags(); // Long enough to hold hex, dec, and octal representations. - const int __ilen = 4 * sizeof(_ValueT); + const int __ilen = 5 * sizeof(_ValueT); _CharT* __cs = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * __ilen)); // [22.2.2.2.2] Stage 1, numeric conversion to character. // Result is returned right-justified in the buffer. - int __len; - __len = __int_to_char(__cs + __ilen, __v, __lit, __io.flags()); + const ios_base::fmtflags __basefield = __flags & ios_base::basefield; + const bool __dec = (__basefield != ios_base::oct + && __basefield != ios_base::hex); + const __unsigned_type __u = (__v > 0 || !__dec) ? __v : -__v; + int __len = __int_to_char(__cs + __ilen, __u, __lit, __flags, __dec); __cs += __ilen - __len; // Add grouping, if necessary. if (__lc->_M_use_grouping) { - // Grouping can add (almost) as many separators as the - // number of digits, but no more. + // Grouping can add (almost) as many separators as the number + // of digits + space is reserved for numeric base or sign. _CharT* __cs2 = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) - * __len * 2)); + * (__len + 1) + * 2)); _M_group_int(__lc->_M_grouping, __lc->_M_grouping_size, - __lc->_M_thousands_sep, __io, __cs2, __cs, __len); - __cs = __cs2; + __lc->_M_thousands_sep, __io, __cs2 + 2, __cs, __len); + __cs = __cs2 + 2; + } + + // Complete Stage 1, prepend numeric base or sign. + if (__builtin_expect(__dec, true)) + { + // Decimal. + if (__v > 0) + { + if (__flags & ios_base::showpos + && numeric_limits<_ValueT>::is_signed) + *--__cs = __lit[__num_base::_S_oplus], ++__len; + } + else if (__v) + *--__cs = __lit[__num_base::_S_ominus], ++__len; + } + else if (__flags & ios_base::showbase && __v) + { + if (__basefield == ios_base::oct) + *--__cs = __lit[__num_base::_S_odigits], ++__len; + else + { + // 'x' or 'X' + const bool __uppercase = __flags & ios_base::uppercase; + *--__cs = __lit[__num_base::_S_ox + __uppercase]; + // '0' + *--__cs = __lit[__num_base::_S_odigits]; + __len += 2; + } } // Pad. @@ -1013,10 +1065,10 @@ namespace std // _GLIBCXX_RESOLVE_LIB_DEFECTS // 282. What types does numpunct grouping refer to? // Add grouping, if necessary. - _CharT* __p2; const int __declen = __p ? __p - __cs : __len; - __p2 = std::__add_grouping(__new, __sep, __grouping, __grouping_size, - __cs, __cs + __declen); + _CharT* __p2 = std::__add_grouping(__new, __sep, __grouping, + __grouping_size, + __cs, __cs + __declen); // Tack on decimal part. int __newlen = __p2 - __new; @@ -1028,7 +1080,7 @@ namespace std __len = __newlen; } - // The following code uses snprintf (or sprintf(), when + // The following code uses vsnprintf (or vsprintf(), when // _GLIBCXX_USE_C99 is not defined) to convert floating point values // for insertion into a stream. An optimization would be to replace // them with code that works directly on a wide buffer and then use @@ -1045,15 +1097,13 @@ namespace std _M_insert_float(_OutIter __s, ios_base& __io, _CharT __fill, char __mod, _ValueT __v) const { - typedef typename numpunct<_CharT>::__cache_type __cache_type; + typedef __numpunct_cache<_CharT> __cache_type; __use_cache<__cache_type> __uc; const locale& __loc = __io._M_getloc(); const __cache_type* __lc = __uc(__loc); // Use default precision if out of range. - streamsize __prec = __io.precision(); - if (__prec < static_cast<streamsize>(0)) - __prec = static_cast<streamsize>(6); + const streamsize __prec = __io.precision() < 0 ? 6 : __io.precision(); const int __max_digits = numeric_limits<_ValueT>::digits10; @@ -1061,24 +1111,23 @@ namespace std int __len; // Long enough for the max format spec. char __fbuf[16]; + __num_base::_S_format_float(__io, __fbuf, __mod); #ifdef _GLIBCXX_USE_C99 // First try a buffer perhaps big enough (most probably sufficient // for non-ios_base::fixed outputs) int __cs_size = __max_digits * 3; char* __cs = static_cast<char*>(__builtin_alloca(__cs_size)); - - __num_base::_S_format_float(__io, __fbuf, __mod); - __len = std::__convert_from_v(__cs, __cs_size, __fbuf, __v, - _S_get_c_locale(), __prec); + __len = std::__convert_from_v(_S_get_c_locale(), __cs, __cs_size, + __fbuf, __prec, __v); // If the buffer was not large enough, try again with the correct size. if (__len >= __cs_size) { __cs_size = __len + 1; __cs = static_cast<char*>(__builtin_alloca(__cs_size)); - __len = std::__convert_from_v(__cs, __cs_size, __fbuf, __v, - _S_get_c_locale(), __prec); + __len = std::__convert_from_v(_S_get_c_locale(), __cs, __cs_size, + __fbuf, __prec, __v); } #else // Consider the possibility of long ios_base::fixed outputs @@ -1094,55 +1143,71 @@ namespace std const int __cs_size = __fixed ? __max_exp + __prec + 4 : __max_digits * 2 + __prec; char* __cs = static_cast<char*>(__builtin_alloca(__cs_size)); - - __num_base::_S_format_float(__io, __fbuf, __mod); - __len = std::__convert_from_v(__cs, 0, __fbuf, __v, - _S_get_c_locale(), __prec); + __len = std::__convert_from_v(_S_get_c_locale(), __cs, 0, __fbuf, + __prec, __v); #endif - // [22.2.2.2.2] Stage 2, convert to char_type, using correct - // numpunct.decimal_point() values for '.' and adding grouping. - const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc); - - _CharT* __ws = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) - * __len)); - __ctype.widen(__cs, __cs + __len, __ws); - - // Replace decimal point. - const _CharT __cdec = __ctype.widen('.'); - const _CharT __dec = __lc->_M_decimal_point; - const _CharT* __p; - if (__p = char_traits<_CharT>::find(__ws, __len, __cdec)) - __ws[__p - __ws] = __dec; - - // Add grouping, if necessary. - if (__lc->_M_use_grouping) - { - // Grouping can add (almost) as many separators as the - // number of digits, but no more. - _CharT* __ws2 = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) - * __len * 2)); - _M_group_float(__lc->_M_grouping, __lc->_M_grouping_size, - __lc->_M_thousands_sep, __p, __ws2, __ws, __len); - __ws = __ws2; - } - - // Pad. - const streamsize __w = __io.width(); - if (__w > static_cast<streamsize>(__len)) - { - _CharT* __ws3 = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) - * __w)); - _M_pad(__fill, __w, __io, __ws3, __ws, __len); - __ws = __ws3; - } - __io.width(0); + // [22.2.2.2.2] Stage 2, convert to char_type, using correct + // numpunct.decimal_point() values for '.' and adding grouping. + const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc); + + _CharT* __ws = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) + * __len)); + __ctype.widen(__cs, __cs + __len, __ws); + + // Replace decimal point. + _CharT* __wp = 0; + const char* __p = char_traits<char>::find(__cs, __len, '.'); + if (__p) + { + __wp = __ws + (__p - __cs); + *__wp = __lc->_M_decimal_point; + } + + // Add grouping, if necessary. + // N.B. Make sure to not group things like 2e20, i.e., no decimal + // point, scientific notation. + if (__lc->_M_use_grouping + && (__wp || __len < 3 || (__cs[1] <= '9' && __cs[2] <= '9' + && __cs[1] >= '0' && __cs[2] >= '0'))) + { + // Grouping can add (almost) as many separators as the + // number of digits, but no more. + _CharT* __ws2 = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) + * __len * 2)); + + streamsize __off = 0; + if (__cs[0] == '-' || __cs[0] == '+') + { + __off = 1; + __ws2[0] = __ws[0]; + __len -= 1; + } + + _M_group_float(__lc->_M_grouping, __lc->_M_grouping_size, + __lc->_M_thousands_sep, __wp, __ws2 + __off, + __ws + __off, __len); + __len += __off; + + __ws = __ws2; + } - // [22.2.2.2.2] Stage 4. - // Write resulting, fully-formatted string to output iterator. - return std::__write(__s, __ws, __len); + // Pad. + const streamsize __w = __io.width(); + if (__w > static_cast<streamsize>(__len)) + { + _CharT* __ws3 = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) + * __w)); + _M_pad(__fill, __w, __io, __ws3, __ws, __len); + __ws = __ws3; + } + __io.width(0); + + // [22.2.2.2.2] Stage 4. + // Write resulting, fully-formatted string to output iterator. + return std::__write(__s, __ws, __len); } - + template<typename _CharT, typename _OutIter> _OutIter num_put<_CharT, _OutIter>:: @@ -1156,7 +1221,7 @@ namespace std } else { - typedef typename numpunct<_CharT>::__cache_type __cache_type; + typedef __numpunct_cache<_CharT> __cache_type; __use_cache<__cache_type> __uc; const locale& __loc = __io._M_getloc(); const __cache_type* __lc = __uc(__loc); @@ -1198,8 +1263,8 @@ namespace std template<typename _CharT, typename _OutIter> _OutIter num_put<_CharT, _OutIter>:: - do_put(iter_type __s, ios_base& __b, char_type __fill, long long __v) const - { return _M_insert_int(__s, __b, __fill, __v); } + do_put(iter_type __s, ios_base& __io, char_type __fill, long long __v) const + { return _M_insert_int(__s, __io, __fill, __v); } template<typename _CharT, typename _OutIter> _OutIter @@ -1215,6 +1280,14 @@ namespace std do_put(iter_type __s, ios_base& __io, char_type __fill, double __v) const { return _M_insert_float(__s, __io, __fill, char(), __v); } +#if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__ + template<typename _CharT, typename _OutIter> + _OutIter + num_put<_CharT, _OutIter>:: + __do_put(iter_type __s, ios_base& __io, char_type __fill, double __v) const + { return _M_insert_float(__s, __io, __fill, char(), __v); } +#endif + template<typename _CharT, typename _OutIter> _OutIter num_put<_CharT, _OutIter>:: @@ -1250,8 +1323,7 @@ namespace std typedef char_traits<_CharT> __traits_type; typedef typename string_type::size_type size_type; typedef money_base::part part; - typedef moneypunct<_CharT, _Intl> __moneypunct_type; - typedef typename __moneypunct_type::__cache_type __cache_type; + typedef __moneypunct_cache<_CharT, _Intl> __cache_type; const locale& __loc = __io._M_getloc(); const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc); @@ -1285,8 +1357,7 @@ namespace std __res.reserve(32); const char_type* __lit_zero = __lit + money_base::_S_zero; - const char_type* __q; - const money_base::pattern __p = __lc->_M_neg_format; + const money_base::pattern __p = __lc->_M_neg_format; for (int __i = 0; __i < 4 && __testvalid; ++__i) { const part __which = static_cast<part>(__p.field[__i]); @@ -1347,35 +1418,41 @@ namespace std // Extract digits, remove and stash away the // grouping of found thousands separators. for (; __beg != __end; ++__beg) - if (__q = __traits_type::find(__lit_zero, 10, *__beg)) - { - __res += money_base::_S_atoms[__q - __lit]; - ++__n; - } - else if (*__beg == __lc->_M_decimal_point && !__testdecfound) - { - __last_pos = __n; - __n = 0; - __testdecfound = true; - } - else if (__lc->_M_use_grouping - && *__beg == __lc->_M_thousands_sep - && !__testdecfound) - { - if (__n) - { - // Mark position for later analysis. - __grouping_tmp += static_cast<char>(__n); - __n = 0; - } - else - { - __testvalid = false; - break; - } - } - else - break; + { + const char_type __c = *__beg; + const char_type* __q = __traits_type::find(__lit_zero, + 10, __c); + if (__q != 0) + { + __res += money_base::_S_atoms[__q - __lit]; + ++__n; + } + else if (__c == __lc->_M_decimal_point + && !__testdecfound) + { + __last_pos = __n; + __n = 0; + __testdecfound = true; + } + else if (__lc->_M_use_grouping + && __c == __lc->_M_thousands_sep + && !__testdecfound) + { + if (__n) + { + // Mark position for later analysis. + __grouping_tmp += static_cast<char>(__n); + __n = 0; + } + else + { + __testvalid = false; + break; + } + } + else + break; + } if (__res.empty()) __testvalid = false; break; @@ -1431,7 +1508,7 @@ namespace std if (!std::__verify_grouping(__lc->_M_grouping, __lc->_M_grouping_size, __grouping_tmp)) - __testvalid = false; + __err |= ios_base::failbit; } // Iff not enough digits were supplied after the decimal-point. @@ -1440,19 +1517,33 @@ namespace std __testvalid = false; } - // Iff no more characters are available. - if (__beg == __end) - __err |= ios_base::eofbit; - // Iff valid sequence is not recognized. if (!__testvalid) __err |= ios_base::failbit; else __units.swap(__res); + // Iff no more characters are available. + if (__beg == __end) + __err |= ios_base::eofbit; return __beg; } +#if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__ + template<typename _CharT, typename _InIter> + _InIter + money_get<_CharT, _InIter>:: + __do_get(iter_type __beg, iter_type __end, bool __intl, ios_base& __io, + ios_base::iostate& __err, double& __units) const + { + string __str; + __beg = __intl ? _M_extract<true>(__beg, __end, __io, __err, __str) + : _M_extract<false>(__beg, __end, __io, __err, __str); + std::__convert_to_v(__str.c_str(), __units, __err, _S_get_c_locale()); + return __beg; + } +#endif + template<typename _CharT, typename _InIter> _InIter money_get<_CharT, _InIter>:: @@ -1460,10 +1551,8 @@ namespace std ios_base::iostate& __err, long double& __units) const { string __str; - if (__intl) - __beg = _M_extract<true>(__beg, __end, __io, __err, __str); - else - __beg = _M_extract<false>(__beg, __end, __io, __err, __str); + __beg = __intl ? _M_extract<true>(__beg, __end, __io, __err, __str) + : _M_extract<false>(__beg, __end, __io, __err, __str); std::__convert_to_v(__str.c_str(), __units, __err, _S_get_c_locale()); return __beg; } @@ -1472,7 +1561,7 @@ namespace std _InIter money_get<_CharT, _InIter>:: do_get(iter_type __beg, iter_type __end, bool __intl, ios_base& __io, - ios_base::iostate& __err, string_type& __units) const + ios_base::iostate& __err, string_type& __digits) const { typedef typename string::size_type size_type; @@ -1480,20 +1569,15 @@ namespace std const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc); string __str; - const iter_type __ret = __intl ? _M_extract<true>(__beg, __end, __io, - __err, __str) - : _M_extract<false>(__beg, __end, __io, - __err, __str); + __beg = __intl ? _M_extract<true>(__beg, __end, __io, __err, __str) + : _M_extract<false>(__beg, __end, __io, __err, __str); const size_type __len = __str.size(); if (__len) { - _CharT* __ws = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) - * __len)); - __ctype.widen(__str.data(), __str.data() + __len, __ws); - __units.assign(__ws, __len); + __digits.resize(__len); + __ctype.widen(__str.data(), __str.data() + __len, &__digits[0]); } - - return __ret; + return __beg; } template<typename _CharT, typename _OutIter> @@ -1505,8 +1589,7 @@ namespace std { typedef typename string_type::size_type size_type; typedef money_base::part part; - typedef moneypunct<_CharT, _Intl> __moneypunct_type; - typedef typename __moneypunct_type::__cache_type __cache_type; + typedef __moneypunct_cache<_CharT, _Intl> __cache_type; const locale& __loc = __io._M_getloc(); const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc); @@ -1522,7 +1605,7 @@ namespace std money_base::pattern __p; const char_type* __sign; size_type __sign_size; - if (*__beg != __lit[money_base::_S_minus]) + if (!(*__beg == __lit[money_base::_S_minus])) { __p = __lc->_M_pos_format; __sign = __lc->_M_positive_sign; @@ -1550,22 +1633,20 @@ namespace std // Add thousands separators to non-decimal digits, per // grouping rules. - int __paddec = __len - __lc->_M_frac_digits; + long __paddec = __len - __lc->_M_frac_digits; if (__paddec > 0) { if (__lc->_M_frac_digits < 0) __paddec = __len; if (__lc->_M_grouping_size) { - _CharT* __ws = - static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) - * 2 * __len)); - _CharT* __ws_end = - std::__add_grouping(__ws, __lc->_M_thousands_sep, + __value.assign(2 * __paddec, char_type()); + _CharT* __vend = + std::__add_grouping(&__value[0], __lc->_M_thousands_sep, __lc->_M_grouping, __lc->_M_grouping_size, __beg, __beg + __paddec); - __value.assign(__ws, __ws_end - __ws); + __value.erase(__vend - &__value[0]); } else __value.assign(__beg, __paddec); @@ -1658,7 +1739,16 @@ namespace std __io.width(0); return __s; } - + +#if defined _GLIBCXX_LONG_DOUBLE_COMPAT && defined __LONG_DOUBLE_128__ + template<typename _CharT, typename _OutIter> + _OutIter + money_put<_CharT, _OutIter>:: + __do_put(iter_type __s, bool __intl, ios_base& __io, char_type __fill, + double __units) const + { return this->do_put(__s, __intl, __io, __fill, (long double) __units); } +#endif + template<typename _CharT, typename _OutIter> _OutIter money_put<_CharT, _OutIter>:: @@ -1673,27 +1763,25 @@ namespace std char* __cs = static_cast<char*>(__builtin_alloca(__cs_size)); // _GLIBCXX_RESOLVE_LIB_DEFECTS // 328. Bad sprintf format modifier in money_put<>::do_put() - int __len = std::__convert_from_v(__cs, __cs_size, "%.*Lf", __units, - _S_get_c_locale(), 0); + int __len = std::__convert_from_v(_S_get_c_locale(), __cs, __cs_size, + "%.*Lf", 0, __units); // If the buffer was not large enough, try again with the correct size. if (__len >= __cs_size) { __cs_size = __len + 1; __cs = static_cast<char*>(__builtin_alloca(__cs_size)); - __len = std::__convert_from_v(__cs, __cs_size, "%.*Lf", __units, - _S_get_c_locale(), 0); + __len = std::__convert_from_v(_S_get_c_locale(), __cs, __cs_size, + "%.*Lf", 0, __units); } #else // max_exponent10 + 1 for the integer part, + 2 for sign and '\0'. const int __cs_size = numeric_limits<long double>::max_exponent10 + 3; char* __cs = static_cast<char*>(__builtin_alloca(__cs_size)); - int __len = std::__convert_from_v(__cs, 0, "%.*Lf", __units, - _S_get_c_locale(), 0); + int __len = std::__convert_from_v(_S_get_c_locale(), __cs, 0, "%.*Lf", + 0, __units); #endif - _CharT* __ws = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) - * __cs_size)); - __ctype.widen(__cs, __cs + __len, __ws); - const string_type __digits(__ws, __len); + string_type __digits(__len, char_type()); + __ctype.widen(__cs, __cs + __len, &__digits[0]); return __intl ? _M_insert<true>(__s, __io, __fill, __digits) : _M_insert<false>(__s, __io, __fill, __digits); } @@ -1706,6 +1794,7 @@ namespace std { return __intl ? _M_insert<true>(__s, __io, __fill, __digits) : _M_insert<false>(__s, __io, __fill, __digits); } +_GLIBCXX_END_LDBL_NAMESPACE // NB: Not especially useful. Without an ios_base object or some // kind of locale reference, we are left clawing at the air where @@ -1729,7 +1818,8 @@ namespace std const ctype<_CharT>& __ctype = use_facet<ctype<_CharT> >(__loc); const size_t __len = char_traits<_CharT>::length(__format); - for (size_t __i = 0; __beg != __end && __i < __len && !__err; ++__i) + ios_base::iostate __tmperr = ios_base::goodbit; + for (size_t __i = 0; __beg != __end && __i < __len && !__tmperr; ++__i) { if (__ctype.narrow(__format[__i], 0) == '%') { @@ -1747,14 +1837,14 @@ namespace std const char_type* __days1[7]; __tp._M_days_abbreviated(__days1); __beg = _M_extract_name(__beg, __end, __tm->tm_wday, __days1, - 7, __io, __err); + 7, __io, __tmperr); break; case 'A': // Weekday name [tm_wday]. const char_type* __days2[7]; __tp._M_days(__days2); __beg = _M_extract_name(__beg, __end, __tm->tm_wday, __days2, - 7, __io, __err); + 7, __io, __tmperr); break; case 'h': case 'b': @@ -1762,77 +1852,77 @@ namespace std const char_type* __months1[12]; __tp._M_months_abbreviated(__months1); __beg = _M_extract_name(__beg, __end, __tm->tm_mon, - __months1, 12, __io, __err); + __months1, 12, __io, __tmperr); break; case 'B': // Month name [tm_mon]. const char_type* __months2[12]; __tp._M_months(__months2); __beg = _M_extract_name(__beg, __end, __tm->tm_mon, - __months2, 12, __io, __err); + __months2, 12, __io, __tmperr); break; case 'c': // Default time and date representation. const char_type* __dt[2]; __tp._M_date_time_formats(__dt); - __beg = _M_extract_via_format(__beg, __end, __io, __err, + __beg = _M_extract_via_format(__beg, __end, __io, __tmperr, __tm, __dt[0]); break; case 'd': // Day [01, 31]. [tm_mday] __beg = _M_extract_num(__beg, __end, __tm->tm_mday, 1, 31, 2, - __io, __err); + __io, __tmperr); break; case 'e': // Day [1, 31], with single digits preceded by // space. [tm_mday] if (__ctype.is(ctype_base::space, *__beg)) __beg = _M_extract_num(++__beg, __end, __tm->tm_mday, 1, 9, - 1, __io, __err); + 1, __io, __tmperr); else __beg = _M_extract_num(__beg, __end, __tm->tm_mday, 10, 31, - 2, __io, __err); + 2, __io, __tmperr); break; case 'D': // Equivalent to %m/%d/%y.[tm_mon, tm_mday, tm_year] __cs = "%m/%d/%y"; __ctype.widen(__cs, __cs + 9, __wcs); - __beg = _M_extract_via_format(__beg, __end, __io, __err, + __beg = _M_extract_via_format(__beg, __end, __io, __tmperr, __tm, __wcs); break; case 'H': // Hour [00, 23]. [tm_hour] __beg = _M_extract_num(__beg, __end, __tm->tm_hour, 0, 23, 2, - __io, __err); + __io, __tmperr); break; case 'I': // Hour [01, 12]. [tm_hour] __beg = _M_extract_num(__beg, __end, __tm->tm_hour, 1, 12, 2, - __io, __err); + __io, __tmperr); break; case 'm': // Month [01, 12]. [tm_mon] __beg = _M_extract_num(__beg, __end, __mem, 1, 12, 2, - __io, __err); - if (!__err) + __io, __tmperr); + if (!__tmperr) __tm->tm_mon = __mem - 1; break; case 'M': // Minute [00, 59]. [tm_min] __beg = _M_extract_num(__beg, __end, __tm->tm_min, 0, 59, 2, - __io, __err); + __io, __tmperr); break; case 'n': if (__ctype.narrow(*__beg, 0) == '\n') ++__beg; else - __err |= ios_base::failbit; + __tmperr |= ios_base::failbit; break; case 'R': // Equivalent to (%H:%M). __cs = "%H:%M"; __ctype.widen(__cs, __cs + 6, __wcs); - __beg = _M_extract_via_format(__beg, __end, __io, __err, + __beg = _M_extract_via_format(__beg, __end, __io, __tmperr, __tm, __wcs); break; case 'S': @@ -1843,46 +1933,46 @@ namespace std #else __beg = _M_extract_num(__beg, __end, __tm->tm_sec, 0, 61, 2, #endif - __io, __err); + __io, __tmperr); break; case 't': if (__ctype.narrow(*__beg, 0) == '\t') ++__beg; else - __err |= ios_base::failbit; + __tmperr |= ios_base::failbit; break; case 'T': // Equivalent to (%H:%M:%S). __cs = "%H:%M:%S"; __ctype.widen(__cs, __cs + 9, __wcs); - __beg = _M_extract_via_format(__beg, __end, __io, __err, + __beg = _M_extract_via_format(__beg, __end, __io, __tmperr, __tm, __wcs); break; case 'x': // Locale's date. const char_type* __dates[2]; __tp._M_date_formats(__dates); - __beg = _M_extract_via_format(__beg, __end, __io, __err, + __beg = _M_extract_via_format(__beg, __end, __io, __tmperr, __tm, __dates[0]); break; case 'X': // Locale's time. const char_type* __times[2]; __tp._M_time_formats(__times); - __beg = _M_extract_via_format(__beg, __end, __io, __err, + __beg = _M_extract_via_format(__beg, __end, __io, __tmperr, __tm, __times[0]); break; case 'y': case 'C': // C99 // Two digit year. [tm_year] __beg = _M_extract_num(__beg, __end, __tm->tm_year, 0, 99, 2, - __io, __err); + __io, __tmperr); break; case 'Y': // Year [1900). [tm_year] __beg = _M_extract_num(__beg, __end, __mem, 0, 9999, 4, - __io, __err); - if (!__err) + __io, __tmperr); + if (!__tmperr) __tm->tm_year = __mem - 1900; break; case 'Z': @@ -1892,25 +1982,25 @@ namespace std int __tmp; __beg = _M_extract_name(__beg, __end, __tmp, __timepunct_cache<_CharT>::_S_timezones, - 14, __io, __err); + 14, __io, __tmperr); // GMT requires special effort. - if (__beg != __end && !__err && __tmp == 0 + if (__beg != __end && !__tmperr && __tmp == 0 && (*__beg == __ctype.widen('-') || *__beg == __ctype.widen('+'))) { __beg = _M_extract_num(__beg, __end, __tmp, 0, 23, 2, - __io, __err); + __io, __tmperr); __beg = _M_extract_num(__beg, __end, __tmp, 0, 59, 2, - __io, __err); + __io, __tmperr); } } else - __err |= ios_base::failbit; + __tmperr |= ios_base::failbit; break; default: // Not recognized. - __err |= ios_base::failbit; + __tmperr |= ios_base::failbit; } } else @@ -1919,9 +2009,13 @@ namespace std if (__format[__i] == *__beg) ++__beg; else - __err |= ios_base::failbit; + __tmperr |= ios_base::failbit; } } + + if (__tmperr) + __err |= ios_base::failbit; + return __beg; } @@ -1959,6 +2053,7 @@ namespace std __member = __value; else __err |= ios_base::failbit; + return __beg; } @@ -2007,7 +2102,7 @@ namespace std for (size_t __i3 = 0; __i3 < __nmatches;) { __name = __names[__matches[__i3]]; - if (__name[__pos] != *__beg) + if (!(__name[__pos] == *__beg)) __matches[__i3] = __matches[--__nmatches]; else ++__i3; @@ -2034,6 +2129,7 @@ namespace std __testvalid = false; if (!__testvalid) __err |= ios_base::failbit; + return __beg; } @@ -2064,7 +2160,7 @@ namespace std const __timepunct<_CharT>& __tp = use_facet<__timepunct<_CharT> >(__loc); const char_type* __dates[2]; __tp._M_date_formats(__dates); - __beg = _M_extract_via_format(__beg, __end, __io, __err, + __beg = _M_extract_via_format(__beg, __end, __io, __err, __tm, __dates[0]); if (__beg == __end) __err |= ios_base::eofbit; @@ -2084,7 +2180,9 @@ namespace std const char_type* __days[7]; __tp._M_days_abbreviated(__days); int __tmpwday; - __beg = _M_extract_name(__beg, __end, __tmpwday, __days, 7, __io, __err); + ios_base::iostate __tmperr = ios_base::goodbit; + __beg = _M_extract_name(__beg, __end, __tmpwday, __days, 7, + __io, __tmperr); // Check to see if non-abbreviated name exists, and extract. // NB: Assumes both _M_days and _M_days_abbreviated organized in @@ -2092,7 +2190,7 @@ namespace std // __days array with the same index points to a day, and that // day's abbreviated form. // NB: Also assumes that an abbreviated name is a subset of the name. - if (!__err && __beg != __end) + if (!__tmperr && __beg != __end) { size_t __pos = __traits_type::length(__days[__tmpwday]); __tp._M_days(__days); @@ -2105,12 +2203,14 @@ namespace std && __name[__pos] == *__beg) ++__beg, ++__pos; if (__len != __pos) - __err |= ios_base::failbit; + __tmperr |= ios_base::failbit; } } - if (!__err) + if (!__tmperr) __tm->tm_wday = __tmpwday; - + else + __err |= ios_base::failbit; + if (__beg == __end) __err |= ios_base::eofbit; return __beg; @@ -2129,8 +2229,9 @@ namespace std const char_type* __months[12]; __tp._M_months_abbreviated(__months); int __tmpmon; + ios_base::iostate __tmperr = ios_base::goodbit; __beg = _M_extract_name(__beg, __end, __tmpmon, __months, 12, - __io, __err); + __io, __tmperr); // Check to see if non-abbreviated name exists, and extract. // NB: Assumes both _M_months and _M_months_abbreviated organized in @@ -2138,7 +2239,7 @@ namespace std // __months array with the same index points to a month, and that // month's abbreviated form. // NB: Also assumes that an abbreviated name is a subset of the name. - if (!__err && __beg != __end) + if (!__tmperr && __beg != __end) { size_t __pos = __traits_type::length(__months[__tmpmon]); __tp._M_months(__months); @@ -2151,11 +2252,13 @@ namespace std && __name[__pos] == *__beg) ++__beg, ++__pos; if (__len != __pos) - __err |= ios_base::failbit; + __tmperr |= ios_base::failbit; } } - if (!__err) + if (!__tmperr) __tm->tm_mon = __tmpmon; + else + __err |= ios_base::failbit; if (__beg == __end) __err |= ios_base::eofbit; @@ -2185,6 +2288,7 @@ namespace std __tm->tm_year = __i == 2 ? __value : __value - 1900; else __err |= ios_base::failbit; + if (__beg == __end) __err |= ios_base::eofbit; return __beg; @@ -2266,7 +2370,6 @@ namespace std return std::__write(__s, __res, char_traits<char_type>::length(__res)); } - // Generic version does nothing. template<typename _CharT> int @@ -2323,43 +2426,55 @@ namespace std collate<_CharT>:: do_transform(const _CharT* __lo, const _CharT* __hi) const { + string_type __ret; + // strxfrm assumes zero-terminated strings so we make a copy - string_type __str(__lo, __hi); + const string_type __str(__lo, __hi); const _CharT* __p = __str.c_str(); const _CharT* __pend = __str.data() + __str.length(); size_t __len = (__hi - __lo) * 2; - string_type __ret; + _CharT* __c = new _CharT[__len]; - // strxfrm stops when it sees a nul character so we break - // the string into zero-terminated substrings and pass those - // to strxfrm. - for (;;) + try { - // First try a buffer perhaps big enough. - _CharT* __c = - static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) * __len)); - size_t __res = _M_transform(__c, __p, __len); - // If the buffer was not large enough, try again with the - // correct size. - if (__res >= __len) + // strxfrm stops when it sees a nul character so we break + // the string into zero-terminated substrings and pass those + // to strxfrm. + for (;;) { - __len = __res + 1; - __c = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) - * __len)); - __res = _M_transform(__c, __p, __res + 1); - } + // First try a buffer perhaps big enough. + size_t __res = _M_transform(__c, __p, __len); + // If the buffer was not large enough, try again with the + // correct size. + if (__res >= __len) + { + __len = __res + 1; + delete [] __c, __c = 0; + __c = new _CharT[__len]; + __res = _M_transform(__c, __p, __len); + } - __ret.append(__c, __res); - __p += char_traits<_CharT>::length(__p); - if (__p == __pend) - return __ret; + __ret.append(__c, __res); + __p += char_traits<_CharT>::length(__p); + if (__p == __pend) + break; - __p++; - __ret.push_back(_CharT()); + __p++; + __ret.push_back(_CharT()); + } + } + catch(...) + { + delete [] __c; + __throw_exception_again; } + + delete [] __c; + + return __ret; } template<typename _CharT> @@ -2443,7 +2558,7 @@ namespace std const string& __grouping_tmp) { const size_t __n = __grouping_tmp.size() - 1; - const size_t __min = std::min(__n, __grouping_size - 1); + const size_t __min = std::min(__n, size_t(__grouping_size - 1)); size_t __i = __n; bool __test = true; @@ -2454,9 +2569,11 @@ namespace std __test = __grouping_tmp[__i] == __grouping[__j]; for (; __i && __test; --__i) __test = __grouping_tmp[__i] == __grouping[__min]; - // ... but the last parsed grouping can be <= numpunct - // grouping. - __test &= __grouping_tmp[0] <= __grouping[__min]; + // ... but the first parsed grouping can be <= numpunct + // grouping (only do the check if the numpunct char is > 0 + // because <= 0 means any size is ok). + if (static_cast<signed char>(__grouping[__min]) > 0) + __test &= __grouping_tmp[0] <= __grouping[__min]; return __test; } @@ -2466,18 +2583,33 @@ namespace std const char* __gbeg, size_t __gsize, const _CharT* __first, const _CharT* __last) { - if (__last - __first > *__gbeg) + size_t __idx = 0; + size_t __ctr = 0; + + while (__last - __first > __gbeg[__idx] + && static_cast<signed char>(__gbeg[__idx]) > 0) { - const bool __bump = __gsize != 1; - __s = std::__add_grouping(__s, __sep, __gbeg + __bump, - __gsize - __bump, __first, - __last - *__gbeg); - __first = __last - *__gbeg; - *__s++ = __sep; + __last -= __gbeg[__idx]; + __idx < __gsize - 1 ? ++__idx : ++__ctr; } - do + + while (__first != __last) *__s++ = *__first++; - while (__first != __last); + + while (__ctr--) + { + *__s++ = __sep; + for (char __i = __gbeg[__idx]; __i > 0; --__i) + *__s++ = *__first++; + } + + while (__idx--) + { + *__s++ = __sep; + for (char __i = __gbeg[__idx]; __i > 0; --__i) + *__s++ = *__first++; + } + return __s; } @@ -2489,12 +2621,12 @@ namespace std extern template class moneypunct<char, true>; extern template class moneypunct_byname<char, false>; extern template class moneypunct_byname<char, true>; - extern template class money_get<char>; - extern template class money_put<char>; + extern template class _GLIBCXX_LDBL_NAMESPACE money_get<char>; + extern template class _GLIBCXX_LDBL_NAMESPACE money_put<char>; extern template class numpunct<char>; extern template class numpunct_byname<char>; - extern template class num_get<char>; - extern template class num_put<char>; + extern template class _GLIBCXX_LDBL_NAMESPACE num_get<char>; + extern template class _GLIBCXX_LDBL_NAMESPACE num_put<char>; extern template class __timepunct<char>; extern template class time_put<char>; extern template class time_put_byname<char>; @@ -2616,12 +2748,12 @@ namespace std extern template class moneypunct<wchar_t, true>; extern template class moneypunct_byname<wchar_t, false>; extern template class moneypunct_byname<wchar_t, true>; - extern template class money_get<wchar_t>; - extern template class money_put<wchar_t>; + extern template class _GLIBCXX_LDBL_NAMESPACE money_get<wchar_t>; + extern template class _GLIBCXX_LDBL_NAMESPACE money_put<wchar_t>; extern template class numpunct<wchar_t>; extern template class numpunct_byname<wchar_t>; - extern template class num_get<wchar_t>; - extern template class num_put<wchar_t>; + extern template class _GLIBCXX_LDBL_NAMESPACE num_get<wchar_t>; + extern template class _GLIBCXX_LDBL_NAMESPACE num_put<wchar_t>; extern template class __timepunct<wchar_t>; extern template class time_put<wchar_t>; extern template class time_put_byname<wchar_t>; @@ -2739,6 +2871,7 @@ namespace std has_facet<messages<wchar_t> >(const locale&); #endif #endif -} // namespace std + +_GLIBCXX_END_NAMESPACE #endif diff --git a/contrib/libstdc++/include/bits/localefwd.h b/contrib/libstdc++/include/bits/localefwd.h index 247158d..b858668 100644 --- a/contrib/libstdc++/include/bits/localefwd.h +++ b/contrib/libstdc++/include/bits/localefwd.h @@ -1,6 +1,6 @@ // Locale support -*- C++ -*- -// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003 +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2005, 2006 // Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free @@ -16,7 +16,7 @@ // 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// 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 @@ -28,15 +28,15 @@ // invalidate any other reasons why the executable file might be covered by // the GNU General Public License. -// -// ISO C++ 14882: 22.1 Locales -// - /** @file localefwd.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_FWD_H #define _LOCALE_FWD_H 1 @@ -47,8 +47,8 @@ #include <iosfwd> // For ostreambuf_iterator, istreambuf_iterator #include <bits/functexcept.h> -namespace std -{ +_GLIBCXX_BEGIN_NAMESPACE(std) + // 22.1.1 Locale class locale; @@ -129,10 +129,12 @@ namespace std class codecvt_byname; // 22.2.2 and 22.2.3 numeric +_GLIBCXX_BEGIN_LDBL_NAMESPACE template<typename _CharT, typename _InIter = istreambuf_iterator<_CharT> > class num_get; template<typename _CharT, typename _OutIter = ostreambuf_iterator<_CharT> > class num_put; +_GLIBCXX_END_LDBL_NAMESPACE template<typename _CharT> class numpunct; template<typename _CharT> class numpunct_byname; @@ -155,10 +157,12 @@ namespace std // 22.2.6 money class money_base; +_GLIBCXX_BEGIN_LDBL_NAMESPACE template<typename _CharT, typename _InIter = istreambuf_iterator<_CharT> > class money_get; template<typename _CharT, typename _OutIter = ostreambuf_iterator<_CharT> > class money_put; +_GLIBCXX_END_LDBL_NAMESPACE template<typename _CharT, bool _Intl = false> class moneypunct; template<typename _CharT, bool _Intl = false> @@ -187,6 +191,7 @@ namespace std __throw_bad_cast(); return *__f; } -} // namespace std + +_GLIBCXX_END_NAMESPACE #endif diff --git a/contrib/libstdc++/include/bits/mask_array.h b/contrib/libstdc++/include/bits/mask_array.h index 1a694f3..98c8bfb 100644 --- a/contrib/libstdc++/include/bits/mask_array.h +++ b/contrib/libstdc++/include/bits/mask_array.h @@ -1,6 +1,6 @@ // The template and inlines for the -*- C++ -*- mask_array class. -// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2004 +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2004, 2005 // Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free @@ -16,7 +16,7 @@ // 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// 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 @@ -28,19 +28,19 @@ // invalidate any other reasons why the executable file might be covered by // the GNU General Public License. -// Written by Gabriel Dos Reis <Gabriel.Dos-Reis@DPTMaths.ENS-Cachan.Fr> - /** @file mask_array.h * This is an internal header file, included by other library headers. * You should not attempt to use it directly. */ +// Written by Gabriel Dos Reis <Gabriel.Dos-Reis@DPTMaths.ENS-Cachan.Fr> + #ifndef _MASK_ARRAY_H #define _MASK_ARRAY_H 1 #pragma GCC system_header -namespace std { +_GLIBCXX_BEGIN_NAMESPACE(std) /** * @brief Reference to selected subset of an array. @@ -128,13 +128,12 @@ namespace std { const size_t _M_sz; const _Array<bool> _M_mask; - const _Array<_Tp> _M_array; + const _Array<_Tp> _M_array; // not implemented mask_array(); }; - template<typename _Tp> inline mask_array<_Tp>::mask_array(const mask_array<_Tp>& a) : _M_sz(a._M_sz), _M_mask(a._M_mask), _M_array(a._M_array) {} @@ -200,10 +199,6 @@ _DEFINE_VALARRAY_OPERATOR(>>, __shift_right) #undef _DEFINE_VALARRAY_OPERATOR -} // std:: +_GLIBCXX_END_NAMESPACE #endif /* _MASK_ARRAY_H */ - -// Local Variables: -// mode:c++ -// End: diff --git a/contrib/libstdc++/include/bits/ostream.tcc b/contrib/libstdc++/include/bits/ostream.tcc index 2d1b5b4..36853e8 100644 --- a/contrib/libstdc++/include/bits/ostream.tcc +++ b/contrib/libstdc++/include/bits/ostream.tcc @@ -1,6 +1,7 @@ // ostream classes -*- C++ -*- -// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004 +// 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 @@ -16,7 +17,7 @@ // 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// 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 @@ -28,6 +29,11 @@ // invalidate any other reasons why the executable file might be covered by // the GNU General Public License. +/** @file ostream.tcc + * This is an internal header file, included by other library headers. + * You should not attempt to use it directly. + */ + // // ISO C++ 14882: 27.6.2 Output streams // @@ -39,8 +45,8 @@ #include <locale> -namespace std -{ +_GLIBCXX_BEGIN_NAMESPACE(std) + template<typename _CharT, typename _Traits> basic_ostream<_CharT, _Traits>::sentry:: sentry(basic_ostream<_CharT, _Traits>& __os) @@ -57,249 +63,57 @@ namespace std } template<typename _CharT, typename _Traits> - basic_ostream<_CharT, _Traits>& - basic_ostream<_CharT, _Traits>:: - operator<<(__ostream_type& (*__pf)(__ostream_type&)) - { - // _GLIBCXX_RESOLVE_LIB_DEFECTS - // DR 60. What is a formatted input function? - // The inserters for manipulators are *not* formatted output functions. - return __pf(*this); - } + template<typename _ValueT> + basic_ostream<_CharT, _Traits>& + basic_ostream<_CharT, _Traits>:: + _M_insert(_ValueT __v) + { + sentry __cerb(*this); + if (__cerb) + { + ios_base::iostate __err = ios_base::iostate(ios_base::goodbit); + try + { + const __num_put_type& __np = __check_facet(this->_M_num_put); + if (__np.put(*this, *this, this->fill(), __v).failed()) + __err |= ios_base::badbit; + } + catch(...) + { this->_M_setstate(ios_base::badbit); } + if (__err) + this->setstate(__err); + } + return *this; + } template<typename _CharT, typename _Traits> basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>:: - operator<<(__ios_type& (*__pf)(__ios_type&)) + operator<<(short __n) { // _GLIBCXX_RESOLVE_LIB_DEFECTS - // DR 60. What is a formatted input function? - // The inserters for manipulators are *not* formatted output functions. - __pf(*this); - return *this; + // 117. basic_ostream uses nonexistent num_put member functions. + const ios_base::fmtflags __fmt = this->flags() & ios_base::basefield; + if (__fmt == ios_base::oct || __fmt == ios_base::hex) + return _M_insert(static_cast<long>(static_cast<unsigned short>(__n))); + else + return _M_insert(static_cast<long>(__n)); } template<typename _CharT, typename _Traits> basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>:: - operator<<(ios_base& (*__pf)(ios_base&)) + operator<<(int __n) { // _GLIBCXX_RESOLVE_LIB_DEFECTS - // DR 60. What is a formatted input function? - // The inserters for manipulators are *not* formatted output functions. - __pf(*this); - return *this; - } - - template<typename _CharT, typename _Traits> - basic_ostream<_CharT, _Traits>& - basic_ostream<_CharT, _Traits>:: - operator<<(bool __n) - { - sentry __cerb(*this); - if (__cerb) - { - ios_base::iostate __err = ios_base::iostate(ios_base::goodbit); - try - { - const __num_put_type& __np = __check_facet(this->_M_num_put); - if (__np.put(*this, *this, this->fill(), __n).failed()) - __err |= ios_base::badbit; - } - catch(...) - { this->_M_setstate(ios_base::badbit); } - if (__err) - this->setstate(__err); - } - return *this; - } - - template<typename _CharT, typename _Traits> - basic_ostream<_CharT, _Traits>& - basic_ostream<_CharT, _Traits>:: - operator<<(long __n) - { - sentry __cerb(*this); - if (__cerb) - { - ios_base::iostate __err = ios_base::iostate(ios_base::goodbit); - try - { - bool __b = false; - const char_type __c = this->fill(); - const ios_base::fmtflags __fmt = (this->flags() - & ios_base::basefield); - const __num_put_type& __np = __check_facet(this->_M_num_put); - if ((__fmt & ios_base::oct) || (__fmt & ios_base::hex)) - { - const unsigned long __l = static_cast<unsigned long>(__n); - __b = __np.put(*this, *this, __c, __l).failed(); - } - else - __b = __np.put(*this, *this, __c, __n).failed(); - if (__b) - __err |= ios_base::badbit; - } - catch(...) - { this->_M_setstate(ios_base::badbit); } - if (__err) - this->setstate(__err); - } - return *this; - } - - template<typename _CharT, typename _Traits> - basic_ostream<_CharT, _Traits>& - basic_ostream<_CharT, _Traits>:: - operator<<(unsigned long __n) - { - sentry __cerb(*this); - if (__cerb) - { - ios_base::iostate __err = ios_base::iostate(ios_base::goodbit); - try - { - const __num_put_type& __np = __check_facet(this->_M_num_put); - if (__np.put(*this, *this, this->fill(), __n).failed()) - __err |= ios_base::badbit; - } - catch(...) - { this->_M_setstate(ios_base::badbit); } - if (__err) - this->setstate(__err); - } - return *this; - } - -#ifdef _GLIBCXX_USE_LONG_LONG - template<typename _CharT, typename _Traits> - basic_ostream<_CharT, _Traits>& - basic_ostream<_CharT, _Traits>:: - operator<<(long long __n) - { - sentry __cerb(*this); - if (__cerb) - { - ios_base::iostate __err = ios_base::iostate(ios_base::goodbit); - try - { - bool __b = false; - const char_type __c = this->fill(); - const ios_base::fmtflags __fmt = (this->flags() - & ios_base::basefield); - const __num_put_type& __np = __check_facet(this->_M_num_put); - if ((__fmt & ios_base::oct) || (__fmt & ios_base::hex)) - { - const unsigned long long __l = (static_cast< - unsigned long long>(__n)); - __b = __np.put(*this, *this, __c, __l).failed(); - } - else - __b = __np.put(*this, *this, __c, __n).failed(); - if (__b) - __err |= ios_base::badbit; - } - catch(...) - { this->_M_setstate(ios_base::badbit); } - if (__err) - this->setstate(__err); - } - return *this; - } - - template<typename _CharT, typename _Traits> - basic_ostream<_CharT, _Traits>& - basic_ostream<_CharT, _Traits>:: - operator<<(unsigned long long __n) - { - sentry __cerb(*this); - if (__cerb) - { - ios_base::iostate __err = ios_base::iostate(ios_base::goodbit); - try - { - const __num_put_type& __np = __check_facet(this->_M_num_put); - if (__np.put(*this, *this, this->fill(), __n).failed()) - __err |= ios_base::badbit; - } - catch(...) - { this->_M_setstate(ios_base::badbit); } - if (__err) - this->setstate(__err); - } - return *this; - } -#endif - - template<typename _CharT, typename _Traits> - basic_ostream<_CharT, _Traits>& - basic_ostream<_CharT, _Traits>:: - operator<<(double __n) - { - sentry __cerb(*this); - if (__cerb) - { - ios_base::iostate __err = ios_base::iostate(ios_base::goodbit); - try - { - const __num_put_type& __np = __check_facet(this->_M_num_put); - if (__np.put(*this, *this, this->fill(), __n).failed()) - __err |= ios_base::badbit; - } - catch(...) - { this->_M_setstate(ios_base::badbit); } - if (__err) - this->setstate(__err); - } - return *this; - } - - template<typename _CharT, typename _Traits> - basic_ostream<_CharT, _Traits>& - basic_ostream<_CharT, _Traits>:: - operator<<(long double __n) - { - sentry __cerb(*this); - if (__cerb) - { - ios_base::iostate __err = ios_base::iostate(ios_base::goodbit); - try - { - const __num_put_type& __np = __check_facet(this->_M_num_put); - if (__np.put(*this, *this, this->fill(), __n).failed()) - __err |= ios_base::badbit; - } - catch(...) - { this->_M_setstate(ios_base::badbit); } - if (__err) - this->setstate(__err); - } - return *this; - } - - template<typename _CharT, typename _Traits> - basic_ostream<_CharT, _Traits>& - basic_ostream<_CharT, _Traits>:: - operator<<(const void* __n) - { - sentry __cerb(*this); - if (__cerb) - { - ios_base::iostate __err = ios_base::iostate(ios_base::goodbit); - try - { - const __num_put_type& __np = __check_facet(this->_M_num_put); - if (__np.put(*this, *this, this->fill(), __n).failed()) - __err |= ios_base::badbit; - } - catch(...) - { this->_M_setstate(ios_base::badbit); } - if (__err) - this->setstate(__err); - } - return *this; + // 117. basic_ostream uses nonexistent num_put member functions. + const ios_base::fmtflags __fmt = this->flags() & ios_base::basefield; + if (__fmt == ios_base::oct || __fmt == ios_base::hex) + return _M_insert(static_cast<long>(static_cast<unsigned int>(__n))); + else + return _M_insert(static_cast<long>(__n)); } - + template<typename _CharT, typename _Traits> basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>:: @@ -467,203 +281,41 @@ namespace std return *this; } - // 27.6.2.5.4 Character inserters. template<typename _CharT, typename _Traits> basic_ostream<_CharT, _Traits>& - operator<<(basic_ostream<_CharT, _Traits>& __out, _CharT __c) - { - typedef basic_ostream<_CharT, _Traits> __ostream_type; - typename __ostream_type::sentry __cerb(__out); - if (__cerb) - { - try - { - const streamsize __w = __out.width(); - streamsize __len = 1; - _CharT* __cs = &__c; - if (__w > __len) - { - __cs = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) - * __w)); - __pad<_CharT, _Traits>::_S_pad(__out, __out.fill(), __cs, - &__c, __w, __len, false); - __len = __w; - } - __out._M_write(__cs, __len); - __out.width(0); - } - catch(...) - { __out._M_setstate(ios_base::badbit); } - } - return __out; - } - - // Specializations. - template <class _Traits> - basic_ostream<char, _Traits>& - operator<<(basic_ostream<char, _Traits>& __out, char __c) - { - typedef basic_ostream<char, _Traits> __ostream_type; - typename __ostream_type::sentry __cerb(__out); - if (__cerb) - { - try - { - const streamsize __w = __out.width(); - streamsize __len = 1; - char* __cs = &__c; - if (__w > __len) - { - __cs = static_cast<char*>(__builtin_alloca(__w)); - __pad<char, _Traits>::_S_pad(__out, __out.fill(), __cs, - &__c, __w, __len, false); - __len = __w; - } - __out._M_write(__cs, __len); - __out.width(0); - } - catch(...) - { __out._M_setstate(ios_base::badbit); } - } - return __out; - } - - template<typename _CharT, typename _Traits> - basic_ostream<_CharT, _Traits>& - operator<<(basic_ostream<_CharT, _Traits>& __out, const _CharT* __s) + operator<<(basic_ostream<_CharT, _Traits>& __out, const char* __s) { - typedef basic_ostream<_CharT, _Traits> __ostream_type; - typename __ostream_type::sentry __cerb(__out); - if (__cerb && __s) + if (!__s) + __out.setstate(ios_base::badbit); + else { + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 167. Improper use of traits_type::length() + const size_t __clen = char_traits<char>::length(__s); + _CharT* __ws = 0; try - { - const streamsize __w = __out.width(); - streamsize __len = static_cast<streamsize>(_Traits::length(__s)); - if (__w > __len) - { - _CharT* __cs = (static_cast< - _CharT*>(__builtin_alloca(sizeof(_CharT) - * __w))); - __pad<_CharT, _Traits>::_S_pad(__out, __out.fill(), __cs, - __s, __w, __len, false); - __s = __cs; - __len = __w; - } - __out._M_write(__s, __len); - __out.width(0); + { + __ws = new _CharT[__clen]; + for (size_t __i = 0; __i < __clen; ++__i) + __ws[__i] = __out.widen(__s[__i]); } catch(...) - { __out._M_setstate(ios_base::badbit); } - } - else if (!__s) - __out.setstate(ios_base::badbit); - return __out; - } - - template<typename _CharT, typename _Traits> - basic_ostream<_CharT, _Traits>& - operator<<(basic_ostream<_CharT, _Traits>& __out, const char* __s) - { - typedef basic_ostream<_CharT, _Traits> __ostream_type; - // _GLIBCXX_RESOLVE_LIB_DEFECTS - // 167. Improper use of traits_type::length() - // Note that this is only in 'Review' status. - typedef char_traits<char> __traits_type; - typename __ostream_type::sentry __cerb(__out); - if (__cerb && __s) - { - size_t __clen = __traits_type::length(__s); - _CharT* __ws = static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT) - * __clen)); - for (size_t __i = 0; __i < __clen; ++__i) - __ws[__i] = __out.widen(__s[__i]); - _CharT* __str = __ws; - - try { - const streamsize __w = __out.width(); - streamsize __len = static_cast<streamsize>(__clen); - if (__w > __len) - { - _CharT* __cs = (static_cast< - _CharT*>(__builtin_alloca(sizeof(_CharT) - * __w))); - __pad<_CharT, _Traits>::_S_pad(__out, __out.fill(), __cs, - __ws, __w, __len, false); - __str = __cs; - __len = __w; - } - __out._M_write(__str, __len); - __out.width(0); + delete [] __ws; + __out._M_setstate(ios_base::badbit); + return __out; } - catch(...) - { __out._M_setstate(ios_base::badbit); } - } - else if (!__s) - __out.setstate(ios_base::badbit); - return __out; - } - // Partial specializations. - template<class _Traits> - basic_ostream<char, _Traits>& - operator<<(basic_ostream<char, _Traits>& __out, const char* __s) - { - typedef basic_ostream<char, _Traits> __ostream_type; - typename __ostream_type::sentry __cerb(__out); - if (__cerb && __s) - { try { - const streamsize __w = __out.width(); - streamsize __len = static_cast<streamsize>(_Traits::length(__s)); - if (__w > __len) - { - char* __cs = static_cast<char*>(__builtin_alloca(__w)); - __pad<char, _Traits>::_S_pad(__out, __out.fill(), __cs, - __s, __w, __len, false); - __s = __cs; - __len = __w; - } - __out._M_write(__s, __len); - __out.width(0); + __ostream_insert(__out, __ws, __clen); + delete [] __ws; } catch(...) - { __out._M_setstate(ios_base::badbit); } - } - else if (!__s) - __out.setstate(ios_base::badbit); - return __out; - } - - // 21.3.7.9 basic_string::operator<< - template<typename _CharT, typename _Traits, typename _Alloc> - basic_ostream<_CharT, _Traits>& - operator<<(basic_ostream<_CharT, _Traits>& __out, - const basic_string<_CharT, _Traits, _Alloc>& __str) - { - typedef basic_ostream<_CharT, _Traits> __ostream_type; - typename __ostream_type::sentry __cerb(__out); - if (__cerb) - { - const streamsize __w = __out.width(); - streamsize __len = static_cast<streamsize>(__str.size()); - const _CharT* __s = __str.data(); - - // _GLIBCXX_RESOLVE_LIB_DEFECTS - // 25. String operator<< uses width() value wrong - if (__w > __len) { - _CharT* __cs = (static_cast< - _CharT*>(__builtin_alloca(sizeof(_CharT) * __w))); - __pad<_CharT, _Traits>::_S_pad(__out, __out.fill(), __cs, __s, - __w, __len, false); - __s = __cs; - __len = __w; + delete [] __ws; + __throw_exception_again; } - __out._M_write(__s, __len); - __out.width(0); } return __out; } @@ -682,6 +334,18 @@ namespace std extern template ostream& operator<<(ostream&, const char*); extern template ostream& operator<<(ostream&, const unsigned char*); extern template ostream& operator<<(ostream&, const signed char*); + extern template ostream& __ostream_insert(ostream&, const char*, streamsize); + + extern template ostream& ostream::_M_insert(long); + extern template ostream& ostream::_M_insert(unsigned long); + extern template ostream& ostream::_M_insert(bool); +#ifdef _GLIBCXX_USE_LONG_LONG + extern template ostream& ostream::_M_insert(long long); + extern template ostream& ostream::_M_insert(unsigned long long); +#endif + extern template ostream& ostream::_M_insert(double); + extern template ostream& ostream::_M_insert(long double); + extern template ostream& ostream::_M_insert(const void*); #ifdef _GLIBCXX_USE_WCHAR_T extern template class basic_ostream<wchar_t>; @@ -692,8 +356,22 @@ namespace std extern template wostream& operator<<(wostream&, char); extern template wostream& operator<<(wostream&, const wchar_t*); extern template wostream& operator<<(wostream&, const char*); + extern template wostream& __ostream_insert(wostream&, const wchar_t*, + streamsize); + + extern template wostream& wostream::_M_insert(long); + extern template wostream& wostream::_M_insert(unsigned long); + extern template wostream& wostream::_M_insert(bool); +#ifdef _GLIBCXX_USE_LONG_LONG + extern template wostream& wostream::_M_insert(long long); + extern template wostream& wostream::_M_insert(unsigned long long); +#endif + extern template wostream& wostream::_M_insert(double); + extern template wostream& wostream::_M_insert(long double); + extern template wostream& wostream::_M_insert(const void*); #endif #endif -} // namespace std + +_GLIBCXX_END_NAMESPACE #endif diff --git a/contrib/libstdc++/include/bits/ostream_insert.h b/contrib/libstdc++/include/bits/ostream_insert.h new file mode 100644 index 0000000..f3ed801 --- /dev/null +++ b/contrib/libstdc++/include/bits/ostream_insert.h @@ -0,0 +1,114 @@ +// Helpers for ostream inserters -*- C++ -*- + +// Copyright (C) 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 ostream_insert.h + * This is an internal header file, included by other library headers. + * You should not attempt to use it directly. + */ + +#ifndef _OSTREAM_INSERT_H +#define _OSTREAM_INSERT_H 1 + +#pragma GCC system_header + +#include <iosfwd> + +_GLIBCXX_BEGIN_NAMESPACE(std) + + template<typename _CharT, typename _Traits> + inline void + __ostream_write(basic_ostream<_CharT, _Traits>& __out, + const _CharT* __s, streamsize __n) + { + typedef basic_ostream<_CharT, _Traits> __ostream_type; + typedef typename __ostream_type::ios_base __ios_base; + + const streamsize __put = __out.rdbuf()->sputn(__s, __n); + if (__put != __n) + __out.setstate(__ios_base::badbit); + } + + template<typename _CharT, typename _Traits> + inline void + __ostream_fill(basic_ostream<_CharT, _Traits>& __out, streamsize __n) + { + typedef basic_ostream<_CharT, _Traits> __ostream_type; + typedef typename __ostream_type::ios_base __ios_base; + + const _CharT __c = __out.fill(); + for (; __n > 0; --__n) + { + const typename _Traits::int_type __put = __out.rdbuf()->sputc(__c); + if (_Traits::eq_int_type(__put, _Traits::eof())) + { + __out.setstate(__ios_base::badbit); + break; + } + } + } + + template<typename _CharT, typename _Traits> + basic_ostream<_CharT, _Traits>& + __ostream_insert(basic_ostream<_CharT, _Traits>& __out, + const _CharT* __s, streamsize __n) + { + typedef basic_ostream<_CharT, _Traits> __ostream_type; + typedef typename __ostream_type::ios_base __ios_base; + + typename __ostream_type::sentry __cerb(__out); + if (__cerb) + { + try + { + const streamsize __w = __out.width(); + if (__w > __n) + { + const bool __left = ((__out.flags() + & __ios_base::adjustfield) + == __ios_base::left); + if (!__left) + __ostream_fill(__out, __w - __n); + if (__out.good()) + __ostream_write(__out, __s, __n); + if (__left && __out.good()) + __ostream_fill(__out, __w - __n); + } + else + __ostream_write(__out, __s, __n); + __out.width(0); + } + catch(...) + { __out._M_setstate(__ios_base::badbit); } + } + return __out; + } + +_GLIBCXX_END_NAMESPACE + +#endif /* _OSTREAM_INSERT_H */ diff --git a/contrib/libstdc++/include/bits/postypes.h b/contrib/libstdc++/include/bits/postypes.h index 0cfb61b..40570d9 100644 --- a/contrib/libstdc++/include/bits/postypes.h +++ b/contrib/libstdc++/include/bits/postypes.h @@ -1,6 +1,6 @@ // Position types -*- C++ -*- -// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2003, 2004 +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 // Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free @@ -16,7 +16,7 @@ // 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// 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 @@ -28,16 +28,16 @@ // invalidate any other reasons why the executable file might be covered by // the GNU General Public License. -// -// ISO C++ 14882: 27.4.1 - Types -// ISO C++ 14882: 27.4.3 - Template class fpos -// - /** @file postypes.h * This is an internal header file, included by other library headers. * You should not attempt to use it directly. */ +// +// ISO C++ 14882: 27.4.1 - Types +// ISO C++ 14882: 27.4.3 - Template class fpos +// + #ifndef _GLIBCXX_POSTYPES_H #define _GLIBCXX_POSTYPES_H 1 @@ -49,8 +49,8 @@ #include <stdint.h> // For int64_t #endif -namespace std -{ +_GLIBCXX_BEGIN_NAMESPACE(std) + // The types streamoff, streampos and wstreampos and the class // template fpos<> are described in clauses 21.1.2, 21.1.3, 27.1.2, // 27.2, 27.4.1, 27.4.3 and D.6. Despite all this verbage, the @@ -129,20 +129,6 @@ namespace std state() const { return _M_state; } - // The standard only requires that operator== must be an - // equivalence relation. In this implementation two fpos<StateT> - // objects belong to the same equivalence class if the contained - // offsets compare equal. - /// Test if equivalent to another position. - bool - operator==(const fpos& __other) const - { return _M_off == __other._M_off; } - - /// Test if not equivalent to another position. - bool - operator!=(const fpos& __other) const - { return _M_off != __other._M_off; } - // The standard requires that this operator must be defined, but // gives no semantics. In this implemenation it just adds it's // argument to the stored offset and returns *this. @@ -203,6 +189,21 @@ namespace std { return _M_off - __other._M_off; } }; + // The standard only requires that operator== must be an + // equivalence relation. In this implementation two fpos<StateT> + // objects belong to the same equivalence class if the contained + // offsets compare equal. + /// Test if equivalent to another position. + template<typename _StateT> + inline bool + operator==(const fpos<_StateT>& __lhs, const fpos<_StateT>& __rhs) + { return streamoff(__lhs) == streamoff(__rhs); } + + template<typename _StateT> + inline bool + operator!=(const fpos<_StateT>& __lhs, const fpos<_StateT>& __rhs) + { return streamoff(__lhs) != streamoff(__rhs); } + // Clauses 21.1.3.1 and 21.1.3.2 describe streampos and wstreampos // as implementation defined types, but clause 27.2 requires that // they must both be typedefs for fpos<mbstate_t> @@ -210,6 +211,7 @@ namespace std typedef fpos<mbstate_t> streampos; /// File position for wchar_t streams. typedef fpos<mbstate_t> wstreampos; -} // namespace std + +_GLIBCXX_END_NAMESPACE #endif diff --git a/contrib/libstdc++/include/bits/slice_array.h b/contrib/libstdc++/include/bits/slice_array.h index 31c89bc..8eaf90d 100644 --- a/contrib/libstdc++/include/bits/slice_array.h +++ b/contrib/libstdc++/include/bits/slice_array.h @@ -1,6 +1,6 @@ // The template and inlines for the -*- C++ -*- slice_array class. -// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2004 +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2004, 2005 // Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free @@ -16,7 +16,7 @@ // 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// 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 @@ -28,20 +28,20 @@ // invalidate any other reasons why the executable file might be covered by // the GNU General Public License. -// Written by Gabriel Dos Reis <Gabriel.Dos-Reis@DPTMaths.ENS-Cachan.Fr> - /** @file slice_array.h * This is an internal header file, included by other library headers. * You should not attempt to use it directly. */ +// Written by Gabriel Dos Reis <Gabriel.Dos-Reis@DPTMaths.ENS-Cachan.Fr> + #ifndef _SLICE_ARRAY_H #define _SLICE_ARRAY_H 1 #pragma GCC system_header -namespace std -{ +_GLIBCXX_BEGIN_NAMESPACE(std) + /** * @brief Class defining one-dimensional subset of an array. * @@ -90,7 +90,7 @@ namespace std inline slice::slice(size_t __o, size_t __d, size_t __s) - : _M_off(__o), _M_sz(__d), _M_st(__s) {} + : _M_off(__o), _M_sz(__d), _M_st(__s) {} inline size_t slice::start() const @@ -160,34 +160,34 @@ namespace std // ~slice_array (); template<class _Dom> - void operator=(const _Expr<_Dom,_Tp>&) const; + void operator=(const _Expr<_Dom, _Tp>&) const; template<class _Dom> - void operator*=(const _Expr<_Dom,_Tp>&) const; + void operator*=(const _Expr<_Dom, _Tp>&) const; template<class _Dom> - void operator/=(const _Expr<_Dom,_Tp>&) const; + void operator/=(const _Expr<_Dom, _Tp>&) const; template<class _Dom> - void operator%=(const _Expr<_Dom,_Tp>&) const; + void operator%=(const _Expr<_Dom, _Tp>&) const; template<class _Dom> - void operator+=(const _Expr<_Dom,_Tp>&) const; + void operator+=(const _Expr<_Dom, _Tp>&) const; template<class _Dom> - void operator-=(const _Expr<_Dom,_Tp>&) const; + void operator-=(const _Expr<_Dom, _Tp>&) const; template<class _Dom> - void operator^=(const _Expr<_Dom,_Tp>&) const; + void operator^=(const _Expr<_Dom, _Tp>&) const; template<class _Dom> - void operator&=(const _Expr<_Dom,_Tp>&) const; + void operator&=(const _Expr<_Dom, _Tp>&) const; template<class _Dom> - void operator|=(const _Expr<_Dom,_Tp>&) const; + void operator|=(const _Expr<_Dom, _Tp>&) const; template<class _Dom> - void operator<<=(const _Expr<_Dom,_Tp>&) const; + void operator<<=(const _Expr<_Dom, _Tp>&) const; template<class _Dom> - void operator>>=(const _Expr<_Dom,_Tp>&) const; + void operator>>=(const _Expr<_Dom, _Tp>&) const; private: friend class valarray<_Tp>; slice_array(_Array<_Tp>, const slice&); - const size_t _M_sz; - const size_t _M_stride; + const size_t _M_sz; + const size_t _M_stride; const _Array<_Tp> _M_array; // not implemented @@ -264,10 +264,6 @@ _DEFINE_VALARRAY_OPERATOR(>>, __shift_right) #undef _DEFINE_VALARRAY_OPERATOR -} // std:: +_GLIBCXX_END_NAMESPACE #endif /* _SLICE_ARRAY_H */ - -// Local Variables: -// mode:c++ -// End: diff --git a/contrib/libstdc++/include/bits/sstream.tcc b/contrib/libstdc++/include/bits/sstream.tcc index 03f49fb..4de1c81 100644 --- a/contrib/libstdc++/include/bits/sstream.tcc +++ b/contrib/libstdc++/include/bits/sstream.tcc @@ -1,6 +1,6 @@ // String based streams -*- C++ -*- -// Copyright (C) 1997, 1998, 1999, 2001, 2002, 2003 +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 // Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free @@ -16,7 +16,7 @@ // 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// 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 @@ -28,6 +28,11 @@ // invalidate any other reasons why the executable file might be covered by // the GNU General Public License. +/** @file sstream.tcc + * This is an internal header file, included by other library headers. + * You should not attempt to use it directly. + */ + // // ISO C++ 14882: 27.7 String-based streams // @@ -39,32 +44,37 @@ #include <sstream> -namespace std -{ +_GLIBCXX_BEGIN_NAMESPACE(std) + template <class _CharT, class _Traits, class _Alloc> typename basic_stringbuf<_CharT, _Traits, _Alloc>::int_type basic_stringbuf<_CharT, _Traits, _Alloc>:: pbackfail(int_type __c) { int_type __ret = traits_type::eof(); - const bool __testeof = traits_type::eq_int_type(__c, __ret); - if (this->eback() < this->gptr()) { - const bool __testeq = traits_type::eq(traits_type::to_char_type(__c), - this->gptr()[-1]); - this->gbump(-1); - // Try to put back __c into input sequence in one of three ways. // Order these tests done in is unspecified by the standard. - if (!__testeof && __testeq) - __ret = __c; - else if (__testeof) - __ret = traits_type::not_eof(__c); + const bool __testeof = traits_type::eq_int_type(__c, __ret); + if (!__testeof) + { + const bool __testeq = traits_type::eq(traits_type:: + to_char_type(__c), + this->gptr()[-1]); + const bool __testout = this->_M_mode & ios_base::out; + if (__testeq || __testout) + { + this->gbump(-1); + if (!__testeq) + *this->gptr() = traits_type::to_char_type(__c); + __ret = __c; + } + } else { - *this->gptr() = traits_type::to_char_type(__c); - __ret = __c; + this->gbump(-1); + __ret = traits_type::not_eof(__c); } } return __ret; @@ -91,25 +101,34 @@ namespace std // Try to append __c into output sequence in one of two ways. // Order these tests done in is unspecified by the standard. + const char_type __conv = traits_type::to_char_type(__c); if (!__testput) { - // NB: Start ostringstream buffers at 512 chars. This is an + // NB: Start ostringstream buffers at 512 chars. This is an // experimental value (pronounced "arbitrary" in some of the // hipper english-speaking countries), and can be changed to // suit particular needs. - // Then, in virtue of DR 169 (TC) we are allowed to grow more - // than one char. + // + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 169. Bad efficiency of overflow() mandated + // 432. stringbuf::overflow() makes only one write position + // available const __size_type __opt_len = std::max(__size_type(2 * __capacity), __size_type(512)); const __size_type __len = std::min(__opt_len, __max_size); __string_type __tmp; __tmp.reserve(__len); - __tmp.assign(_M_string.data(), this->epptr() - this->pbase()); + if (this->pbase()) + __tmp.assign(this->pbase(), this->epptr() - this->pbase()); + __tmp.push_back(__conv); _M_string.swap(__tmp); _M_sync(const_cast<char_type*>(_M_string.data()), this->gptr() - this->eback(), this->pptr() - this->pbase()); } - return this->sputc(traits_type::to_char_type(__c)); + else + *this->pptr() = __conv; + this->pbump(1); + return __c; } template <class _CharT, class _Traits, class _Alloc> @@ -149,28 +168,28 @@ namespace std { _M_update_egptr(); - off_type __newoffi = 0; - off_type __newoffo = 0; + off_type __newoffi = __off; + off_type __newoffo = __newoffi; if (__way == ios_base::cur) { - __newoffi = this->gptr() - __beg; - __newoffo = this->pptr() - __beg; + __newoffi += this->gptr() - __beg; + __newoffo += this->pptr() - __beg; } else if (__way == ios_base::end) - __newoffo = __newoffi = this->egptr() - __beg; + __newoffo = __newoffi += this->egptr() - __beg; if ((__testin || __testboth) - && __newoffi + __off >= 0 - && this->egptr() - __beg >= __newoffi + __off) + && __newoffi >= 0 + && this->egptr() - __beg >= __newoffi) { - this->gbump((__beg + __newoffi + __off) - this->gptr()); + this->gbump((__beg + __newoffi) - this->gptr()); __ret = pos_type(__newoffi); } if ((__testout || __testboth) - && __newoffo + __off >= 0 - && this->egptr() - __beg >= __newoffo + __off) + && __newoffo >= 0 + && this->egptr() - __beg >= __newoffo) { - this->pbump((__beg + __newoffo + __off) - this->pptr()); + this->pbump((__beg + __newoffo) - this->pptr()); __ret = pos_type(__newoffo); } } @@ -187,14 +206,14 @@ namespace std const bool __testout = (ios_base::out & this->_M_mode & __mode) != 0; const char_type* __beg = __testin ? this->eback() : this->pbase(); - if (__beg) + if ((__beg || !off_type(__sp)) && (__testin || __testout)) { _M_update_egptr(); - off_type __pos(__sp); - const bool __testpos = 0 <= __pos - && __pos <= this->egptr() - __beg; - if ((__testin || __testout) && __testpos) + const off_type __pos(__sp); + const bool __testpos = (0 <= __pos + && __pos <= this->egptr() - __beg); + if (__testpos) { if (__testin) this->gbump((__beg + __pos) - this->gptr()); @@ -206,6 +225,38 @@ namespace std return __ret; } + template <class _CharT, class _Traits, class _Alloc> + void + basic_stringbuf<_CharT, _Traits, _Alloc>:: + _M_sync(char_type* __base, __size_type __i, __size_type __o) + { + const bool __testin = _M_mode & ios_base::in; + const bool __testout = _M_mode & ios_base::out; + char_type* __endg = __base + _M_string.size(); + char_type* __endp = __base + _M_string.capacity(); + + if (__base != _M_string.data()) + { + // setbuf: __i == size of buffer area (_M_string.size() == 0). + __endg += __i; + __i = 0; + __endp = __endg; + } + + if (__testin) + this->setg(__base, __base + __i, __endg); + if (__testout) + { + this->setp(__base, __endp); + this->pbump(__o); + // egptr() always tracks the string end. When !__testin, + // for the correct functioning of the streambuf inlines + // the other get area pointers are identical. + if (!__testin) + this->setg(__endg, __endg, __endg); + } + } + // Inhibit implicit instantiations for required instantiations, // which are defined via explicit instantiations elsewhere. // NB: This syntax is a GNU extension. @@ -222,6 +273,7 @@ namespace std extern template class basic_stringstream<wchar_t>; #endif #endif -} // namespace std + +_GLIBCXX_END_NAMESPACE #endif diff --git a/contrib/libstdc++/include/bits/stl_algo.h b/contrib/libstdc++/include/bits/stl_algo.h index 74956d7..cf3cd71 100644 --- a/contrib/libstdc++/include/bits/stl_algo.h +++ b/contrib/libstdc++/include/bits/stl_algo.h @@ -1,6 +1,7 @@ // Algorithm implementation -*- C++ -*- -// Copyright (C) 2001, 2002, 2003, 2004 Free Software Foundation, Inc. +// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 +// 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 @@ -15,7 +16,7 @@ // 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// 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 @@ -67,8 +68,8 @@ // See concept_check.h for the __glibcxx_*_requires macros. -namespace std -{ +_GLIBCXX_BEGIN_NAMESPACE(std) + /** * @brief Find the median of three values. * @param a A value. @@ -166,8 +167,8 @@ namespace std */ template<typename _InputIterator, typename _Tp> inline _InputIterator - find(_InputIterator __first, _InputIterator __last, - const _Tp& __val, input_iterator_tag) + __find(_InputIterator __first, _InputIterator __last, + const _Tp& __val, input_iterator_tag) { while (__first != __last && !(*__first == __val)) ++__first; @@ -181,8 +182,8 @@ namespace std */ template<typename _InputIterator, typename _Predicate> inline _InputIterator - find_if(_InputIterator __first, _InputIterator __last, - _Predicate __pred, input_iterator_tag) + __find_if(_InputIterator __first, _InputIterator __last, + _Predicate __pred, input_iterator_tag) { while (__first != __last && !__pred(*__first)) ++__first; @@ -196,8 +197,8 @@ namespace std */ template<typename _RandomAccessIterator, typename _Tp> _RandomAccessIterator - find(_RandomAccessIterator __first, _RandomAccessIterator __last, - const _Tp& __val, random_access_iterator_tag) + __find(_RandomAccessIterator __first, _RandomAccessIterator __last, + const _Tp& __val, random_access_iterator_tag) { typename iterator_traits<_RandomAccessIterator>::difference_type __trip_count = (__last - __first) >> 2; @@ -248,8 +249,8 @@ namespace std */ template<typename _RandomAccessIterator, typename _Predicate> _RandomAccessIterator - find_if(_RandomAccessIterator __first, _RandomAccessIterator __last, - _Predicate __pred, random_access_iterator_tag) + __find_if(_RandomAccessIterator __first, _RandomAccessIterator __last, + _Predicate __pred, random_access_iterator_tag) { typename iterator_traits<_RandomAccessIterator>::difference_type __trip_count = (__last - __first) >> 2; @@ -294,6 +295,17 @@ namespace std } /** + * @if maint + * This is an overload of find() for streambuf iterators. + * @endif + */ + template<typename _CharT> + typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value, + istreambuf_iterator<_CharT> >::__type + find(istreambuf_iterator<_CharT>, istreambuf_iterator<_CharT>, + const _CharT&); + + /** * @brief Find the first occurrence of a value in a sequence. * @param first An input iterator. * @param last An input iterator. @@ -311,8 +323,8 @@ namespace std __glibcxx_function_requires(_EqualOpConcept< typename iterator_traits<_InputIterator>::value_type, _Tp>) __glibcxx_requires_valid_range(__first, __last); - return std::find(__first, __last, __val, - std::__iterator_category(__first)); + return std::__find(__first, __last, __val, + std::__iterator_category(__first)); } /** @@ -333,8 +345,8 @@ namespace std __glibcxx_function_requires(_UnaryPredicateConcept<_Predicate, typename iterator_traits<_InputIterator>::value_type>) __glibcxx_requires_valid_range(__first, __last); - return std::find_if(__first, __last, __pred, - std::__iterator_category(__first)); + return std::__find_if(__first, __last, __pred, + std::__iterator_category(__first)); } /** @@ -413,9 +425,8 @@ namespace std { // concept requirements __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>) - __glibcxx_function_requires(_EqualityComparableConcept< - typename iterator_traits<_InputIterator>::value_type >) - __glibcxx_function_requires(_EqualityComparableConcept<_Tp>) + __glibcxx_function_requires(_EqualOpConcept< + typename iterator_traits<_InputIterator>::value_type, _Tp>) __glibcxx_requires_valid_range(__first, __last); typename iterator_traits<_InputIterator>::difference_type __n = 0; for ( ; __first != __last; ++__first) @@ -608,6 +619,92 @@ namespace std } /** + * @if maint + * This is an uglified + * search_n(_ForwardIterator, _ForwardIterator, _Integer, const _Tp&) + * overloaded for forward iterators. + * @endif + */ + template<typename _ForwardIterator, typename _Integer, typename _Tp> + _ForwardIterator + __search_n(_ForwardIterator __first, _ForwardIterator __last, + _Integer __count, const _Tp& __val, + std::forward_iterator_tag) + { + __first = std::find(__first, __last, __val); + while (__first != __last) + { + typename iterator_traits<_ForwardIterator>::difference_type + __n = __count; + _ForwardIterator __i = __first; + ++__i; + while (__i != __last && __n != 1 && *__i == __val) + { + ++__i; + --__n; + } + if (__n == 1) + return __first; + if (__i == __last) + return __last; + __first = std::find(++__i, __last, __val); + } + return __last; + } + + /** + * @if maint + * This is an uglified + * search_n(_ForwardIterator, _ForwardIterator, _Integer, const _Tp&) + * overloaded for random access iterators. + * @endif + */ + template<typename _RandomAccessIter, typename _Integer, typename _Tp> + _RandomAccessIter + __search_n(_RandomAccessIter __first, _RandomAccessIter __last, + _Integer __count, const _Tp& __val, + std::random_access_iterator_tag) + { + + typedef typename std::iterator_traits<_RandomAccessIter>::difference_type + _DistanceType; + + _DistanceType __tailSize = __last - __first; + const _DistanceType __pattSize = __count; + + if (__tailSize < __pattSize) + return __last; + + const _DistanceType __skipOffset = __pattSize - 1; + _RandomAccessIter __lookAhead = __first + __skipOffset; + __tailSize -= __pattSize; + + while (1) // the main loop... + { + // __lookAhead here is always pointing to the last element of next + // possible match. + while (!(*__lookAhead == __val)) // the skip loop... + { + if (__tailSize < __pattSize) + return __last; // Failure + __lookAhead += __pattSize; + __tailSize -= __pattSize; + } + _DistanceType __remainder = __skipOffset; + for (_RandomAccessIter __backTrack = __lookAhead - 1; + *__backTrack == __val; --__backTrack) + { + if (--__remainder == 0) + return (__lookAhead - __skipOffset); // Success + } + if (__remainder > __tailSize) + return __last; // Failure + __lookAhead += __remainder; + __tailSize -= __remainder; + } + } + + /** * @brief Search a sequence for a number of consecutive values. * @param first A forward iterator. * @param last A forward iterator. @@ -627,33 +724,109 @@ namespace std { // concept requirements __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>) - __glibcxx_function_requires(_EqualityComparableConcept< - typename iterator_traits<_ForwardIterator>::value_type>) - __glibcxx_function_requires(_EqualityComparableConcept<_Tp>) + __glibcxx_function_requires(_EqualOpConcept< + typename iterator_traits<_ForwardIterator>::value_type, _Tp>) __glibcxx_requires_valid_range(__first, __last); if (__count <= 0) return __first; - else + if (__count == 1) + return std::find(__first, __last, __val); + return std::__search_n(__first, __last, __count, __val, + std::__iterator_category(__first)); + } + + /** + * @if maint + * This is an uglified + * search_n(_ForwardIterator, _ForwardIterator, _Integer, const _Tp&, + * _BinaryPredicate) + * overloaded for forward iterators. + * @endif + */ + template<typename _ForwardIterator, typename _Integer, typename _Tp, + typename _BinaryPredicate> + _ForwardIterator + __search_n(_ForwardIterator __first, _ForwardIterator __last, + _Integer __count, const _Tp& __val, + _BinaryPredicate __binary_pred, std::forward_iterator_tag) + { + while (__first != __last && !__binary_pred(*__first, __val)) + ++__first; + + while (__first != __last) { - __first = std::find(__first, __last, __val); - while (__first != __last) + typename iterator_traits<_ForwardIterator>::difference_type + __n = __count; + _ForwardIterator __i = __first; + ++__i; + while (__i != __last && __n != 1 && __binary_pred(*__i, __val)) { - typename iterator_traits<_ForwardIterator>::difference_type - __n = __count; - _ForwardIterator __i = __first; ++__i; - while (__i != __last && __n != 1 && *__i == __val) - { - ++__i; - --__n; - } - if (__n == 1) - return __first; - else - __first = std::find(__i, __last, __val); + --__n; } - return __last; + if (__n == 1) + return __first; + if (__i == __last) + return __last; + __first = ++__i; + while (__first != __last && !__binary_pred(*__first, __val)) + ++__first; + } + return __last; + } + + /** + * @if maint + * This is an uglified + * search_n(_ForwardIterator, _ForwardIterator, _Integer, const _Tp&, + * _BinaryPredicate) + * overloaded for random access iterators. + * @endif + */ + template<typename _RandomAccessIter, typename _Integer, typename _Tp, + typename _BinaryPredicate> + _RandomAccessIter + __search_n(_RandomAccessIter __first, _RandomAccessIter __last, + _Integer __count, const _Tp& __val, + _BinaryPredicate __binary_pred, std::random_access_iterator_tag) + { + + typedef typename std::iterator_traits<_RandomAccessIter>::difference_type + _DistanceType; + + _DistanceType __tailSize = __last - __first; + const _DistanceType __pattSize = __count; + + if (__tailSize < __pattSize) + return __last; + + const _DistanceType __skipOffset = __pattSize - 1; + _RandomAccessIter __lookAhead = __first + __skipOffset; + __tailSize -= __pattSize; + + while (1) // the main loop... + { + // __lookAhead here is always pointing to the last element of next + // possible match. + while (!__binary_pred(*__lookAhead, __val)) // the skip loop... + { + if (__tailSize < __pattSize) + return __last; // Failure + __lookAhead += __pattSize; + __tailSize -= __pattSize; + } + _DistanceType __remainder = __skipOffset; + for (_RandomAccessIter __backTrack = __lookAhead - 1; + __binary_pred(*__backTrack, __val); --__backTrack) + { + if (--__remainder == 0) + return (__lookAhead - __skipOffset); // Success + } + if (__remainder > __tailSize) + return __last; // Failure + __lookAhead += __remainder; + __tailSize -= __remainder; } } @@ -687,40 +860,14 @@ namespace std if (__count <= 0) return __first; - else + if (__count == 1) { - while (__first != __last) - { - if (__binary_pred(*__first, __val)) - break; - ++__first; - } - while (__first != __last) - { - typename iterator_traits<_ForwardIterator>::difference_type - __n = __count; - _ForwardIterator __i = __first; - ++__i; - while (__i != __last && __n != 1 && __binary_pred(*__i, __val)) - { - ++__i; - --__n; - } - if (__n == 1) - return __first; - else - { - while (__i != __last) - { - if (__binary_pred(*__i, __val)) - break; - ++__i; - } - __first = __i; - } - } - return __last; + while (__first != __last && !__binary_pred(*__first, __val)) + ++__first; + return __first; } + return std::__search_n(__first, __last, __count, __val, __binary_pred, + std::__iterator_category(__first)); } /** @@ -918,7 +1065,10 @@ namespace std __glibcxx_requires_valid_range(__first, __last); for ( ; __first != __last; ++__first, ++__result) - *__result = *__first == __old_value ? __new_value : *__first; + if (*__first == __old_value) + *__result = __new_value; + else + *__result = *__first; return __result; } @@ -952,7 +1102,10 @@ namespace std __glibcxx_requires_valid_range(__first, __last); for ( ; __first != __last; ++__first, ++__result) - *__result = __pred(*__first) ? __new_value : *__first; + if (__pred(*__first)) + *__result = __new_value; + else + *__result = *__first; return __result; } @@ -1153,14 +1306,39 @@ namespace std * @if maint * This is an uglified unique_copy(_InputIterator, _InputIterator, * _OutputIterator) - * overloaded for output iterators. + * overloaded for forward iterators and output iterator as result. + * @endif + */ + template<typename _ForwardIterator, typename _OutputIterator> + _OutputIterator + __unique_copy(_ForwardIterator __first, _ForwardIterator __last, + _OutputIterator __result, + forward_iterator_tag, output_iterator_tag) + { + // concept requirements -- taken care of in dispatching function + _ForwardIterator __next = __first; + *__result = *__first; + while (++__next != __last) + if (!(*__first == *__next)) + { + __first = __next; + *++__result = *__first; + } + return ++__result; + } + + /** + * @if maint + * This is an uglified unique_copy(_InputIterator, _InputIterator, + * _OutputIterator) + * overloaded for input iterators and output iterator as result. * @endif */ template<typename _InputIterator, typename _OutputIterator> _OutputIterator __unique_copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result, - output_iterator_tag) + input_iterator_tag, output_iterator_tag) { // concept requirements -- taken care of in dispatching function typename iterator_traits<_InputIterator>::value_type __value = *__first; @@ -1178,14 +1356,14 @@ namespace std * @if maint * This is an uglified unique_copy(_InputIterator, _InputIterator, * _OutputIterator) - * overloaded for forward iterators. + * overloaded for input iterators and forward iterator as result. * @endif */ template<typename _InputIterator, typename _ForwardIterator> _ForwardIterator __unique_copy(_InputIterator __first, _InputIterator __last, _ForwardIterator __result, - forward_iterator_tag) + input_iterator_tag, forward_iterator_tag) { // concept requirements -- taken care of in dispatching function *__result = *__first; @@ -1200,16 +1378,46 @@ namespace std * This is an uglified * unique_copy(_InputIterator, _InputIterator, _OutputIterator, * _BinaryPredicate) - * overloaded for output iterators. + * overloaded for forward iterators and output iterator as result. + * @endif + */ + template<typename _ForwardIterator, typename _OutputIterator, + typename _BinaryPredicate> + _OutputIterator + __unique_copy(_ForwardIterator __first, _ForwardIterator __last, + _OutputIterator __result, _BinaryPredicate __binary_pred, + forward_iterator_tag, output_iterator_tag) + { + // concept requirements -- iterators already checked + __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate, + typename iterator_traits<_ForwardIterator>::value_type, + typename iterator_traits<_ForwardIterator>::value_type>) + + _ForwardIterator __next = __first; + *__result = *__first; + while (++__next != __last) + if (!__binary_pred(*__first, *__next)) + { + __first = __next; + *++__result = *__first; + } + return ++__result; + } + + /** + * @if maint + * This is an uglified + * unique_copy(_InputIterator, _InputIterator, _OutputIterator, + * _BinaryPredicate) + * overloaded for input iterators and output iterator as result. * @endif */ template<typename _InputIterator, typename _OutputIterator, typename _BinaryPredicate> _OutputIterator __unique_copy(_InputIterator __first, _InputIterator __last, - _OutputIterator __result, - _BinaryPredicate __binary_pred, - output_iterator_tag) + _OutputIterator __result, _BinaryPredicate __binary_pred, + input_iterator_tag, output_iterator_tag) { // concept requirements -- iterators already checked __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate, @@ -1232,25 +1440,25 @@ namespace std * This is an uglified * unique_copy(_InputIterator, _InputIterator, _OutputIterator, * _BinaryPredicate) - * overloaded for forward iterators. + * overloaded for input iterators and forward iterator as result. * @endif */ template<typename _InputIterator, typename _ForwardIterator, typename _BinaryPredicate> _ForwardIterator __unique_copy(_InputIterator __first, _InputIterator __last, - _ForwardIterator __result, - _BinaryPredicate __binary_pred, - forward_iterator_tag) + _ForwardIterator __result, _BinaryPredicate __binary_pred, + input_iterator_tag, forward_iterator_tag) { // concept requirements -- iterators already checked __glibcxx_function_requires(_BinaryPredicateConcept<_BinaryPredicate, - typename iterator_traits<_ForwardIterator>::value_type, - typename iterator_traits<_InputIterator>::value_type>) + typename iterator_traits<_ForwardIterator>::value_type, + typename iterator_traits<_InputIterator>::value_type>) *__result = *__first; while (++__first != __last) - if (!__binary_pred(*__result, *__first)) *++__result = *__first; + if (!__binary_pred(*__result, *__first)) + *++__result = *__first; return ++__result; } @@ -1266,6 +1474,15 @@ namespace std * from groups of consecutive elements that compare equal. * unique_copy() is stable, so the relative order of elements that are * copied is unchanged. + * + * @if maint + * _GLIBCXX_RESOLVE_LIB_DEFECTS + * DR 241. Does unique_copy() require CopyConstructible and Assignable? + * + * _GLIBCXX_RESOLVE_LIB_DEFECTS + * DR 538. 241 again: Does unique_copy() require CopyConstructible and + * Assignable? + * @endif */ template<typename _InputIterator, typename _OutputIterator> inline _OutputIterator @@ -1280,11 +1497,11 @@ namespace std typename iterator_traits<_InputIterator>::value_type>) __glibcxx_requires_valid_range(__first, __last); - typedef typename iterator_traits<_OutputIterator>::iterator_category - _IterType; - - if (__first == __last) return __result; - return std::__unique_copy(__first, __last, __result, _IterType()); + if (__first == __last) + return __result; + return std::__unique_copy(__first, __last, __result, + std::__iterator_category(__first), + std::__iterator_category(__result)); } /** @@ -1301,6 +1518,11 @@ namespace std * true. * unique_copy() is stable, so the relative order of elements that are * copied is unchanged. + * + * @if maint + * _GLIBCXX_RESOLVE_LIB_DEFECTS + * DR 241. Does unique_copy() require CopyConstructible and Assignable? + * @endif */ template<typename _InputIterator, typename _OutputIterator, typename _BinaryPredicate> @@ -1315,12 +1537,11 @@ namespace std typename iterator_traits<_InputIterator>::value_type>) __glibcxx_requires_valid_range(__first, __last); - typedef typename iterator_traits<_OutputIterator>::iterator_category - _IterType; - - if (__first == __last) return __result; - return std::__unique_copy(__first, __last, __result, - __binary_pred, _IterType()); + if (__first == __last) + return __result; + return std::__unique_copy(__first, __last, __result, __binary_pred, + std::__iterator_category(__first), + std::__iterator_category(__result)); } /** @@ -1412,29 +1633,39 @@ namespace std template<typename _BidirectionalIterator> void __reverse(_BidirectionalIterator __first, _BidirectionalIterator __last, - bidirectional_iterator_tag) + bidirectional_iterator_tag) { while (true) if (__first == __last || __first == --__last) return; else - std::iter_swap(__first++, __last); + { + std::iter_swap(__first, __last); + ++__first; + } } /** * @if maint * This is an uglified reverse(_BidirectionalIterator, * _BidirectionalIterator) - * overloaded for bidirectional iterators. + * overloaded for random access iterators. * @endif */ template<typename _RandomAccessIterator> void __reverse(_RandomAccessIterator __first, _RandomAccessIterator __last, - random_access_iterator_tag) + random_access_iterator_tag) { + if (__first == __last) + return; + --__last; while (__first < __last) - std::iter_swap(__first++, --__last); + { + std::iter_swap(__first, __last); + ++__first; + --__last; + } } /** @@ -1454,7 +1685,7 @@ namespace std { // concept requirements __glibcxx_function_requires(_Mutable_BidirectionalIteratorConcept< - _BidirectionalIterator>) + _BidirectionalIterator>) __glibcxx_requires_valid_range(__first, __last); std::__reverse(__first, __last, std::__iterator_category(__first)); } @@ -1525,15 +1756,17 @@ namespace std __rotate(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last, - forward_iterator_tag) + forward_iterator_tag) { - if ((__first == __middle) || (__last == __middle)) + if (__first == __middle || __last == __middle) return; _ForwardIterator __first2 = __middle; do { - swap(*__first++, *__first2++); + swap(*__first, *__first2); + ++__first; + ++__first2; if (__first == __middle) __middle = __first2; } @@ -1543,7 +1776,9 @@ namespace std while (__first2 != __last) { - swap(*__first++, *__first2++); + swap(*__first, *__first2); + ++__first; + ++__first2; if (__first == __middle) __middle = __first2; else if (__first2 == __last) @@ -1565,16 +1800,19 @@ namespace std { // concept requirements __glibcxx_function_requires(_Mutable_BidirectionalIteratorConcept< - _BidirectionalIterator>) + _BidirectionalIterator>) - if ((__first == __middle) || (__last == __middle)) + if (__first == __middle || __last == __middle) return; std::__reverse(__first, __middle, bidirectional_iterator_tag()); std::__reverse(__middle, __last, bidirectional_iterator_tag()); while (__first != __middle && __middle != __last) - swap(*__first++, *--__last); + { + swap(*__first, *--__last); + ++__first; + } if (__first == __middle) std::__reverse(__middle, __last, bidirectional_iterator_tag()); @@ -1596,9 +1834,9 @@ namespace std { // concept requirements __glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept< - _RandomAccessIterator>) + _RandomAccessIterator>) - if ((__first == __middle) || (__last == __middle)) + if (__first == __middle || __last == __middle) return; typedef typename iterator_traits<_RandomAccessIterator>::difference_type @@ -1620,7 +1858,7 @@ namespace std for (_Distance __i = 0; __i < __d; __i++) { - const _ValueType __tmp = *__first; + _ValueType __tmp = *__first; _RandomAccessIterator __p = __first; if (__k < __l) @@ -1719,7 +1957,8 @@ namespace std __glibcxx_requires_valid_range(__first, __middle); __glibcxx_requires_valid_range(__middle, __last); - return std::copy(__first, __middle, copy(__middle, __last, __result)); + return std::copy(__first, __middle, + std::copy(__middle, __last, __result)); } /** @@ -2194,10 +2433,10 @@ namespace std __final_insertion_sort(_RandomAccessIterator __first, _RandomAccessIterator __last) { - if (__last - __first > _S_threshold) + if (__last - __first > int(_S_threshold)) { - std::__insertion_sort(__first, __first + _S_threshold); - std::__unguarded_insertion_sort(__first + _S_threshold, __last); + std::__insertion_sort(__first, __first + int(_S_threshold)); + std::__unguarded_insertion_sort(__first + int(_S_threshold), __last); } else std::__insertion_sort(__first, __last); @@ -2213,10 +2452,10 @@ namespace std __final_insertion_sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) { - if (__last - __first > _S_threshold) + if (__last - __first > int(_S_threshold)) { - std::__insertion_sort(__first, __first + _S_threshold, __comp); - std::__unguarded_insertion_sort(__first + _S_threshold, __last, + std::__insertion_sort(__first, __first + int(_S_threshold), __comp); + std::__unguarded_insertion_sort(__first + int(_S_threshold), __last, __comp); } else @@ -2225,7 +2464,47 @@ namespace std /** * @if maint - * This is a helper function for the sort routine. + * This is a helper function for the sort routines. + * @endif + */ + template<typename _RandomAccessIterator> + void + __heap_select(_RandomAccessIterator __first, + _RandomAccessIterator __middle, + _RandomAccessIterator __last) + { + typedef typename iterator_traits<_RandomAccessIterator>::value_type + _ValueType; + + std::make_heap(__first, __middle); + for (_RandomAccessIterator __i = __middle; __i < __last; ++__i) + if (*__i < *__first) + std::__pop_heap(__first, __middle, __i, _ValueType(*__i)); + } + + /** + * @if maint + * This is a helper function for the sort routines. + * @endif + */ + template<typename _RandomAccessIterator, typename _Compare> + void + __heap_select(_RandomAccessIterator __first, + _RandomAccessIterator __middle, + _RandomAccessIterator __last, _Compare __comp) + { + typedef typename iterator_traits<_RandomAccessIterator>::value_type + _ValueType; + + std::make_heap(__first, __middle, __comp); + for (_RandomAccessIterator __i = __middle; __i < __last; ++__i) + if (__comp(*__i, *__first)) + std::__pop_heap(__first, __middle, __i, _ValueType(*__i), __comp); + } + + /** + * @if maint + * This is a helper function for the sort routines. * @endif */ template<typename _Size> @@ -2254,7 +2533,7 @@ namespace std * the range @p [middle,last) then @p *j<*i and @p *k<*i are both false. */ template<typename _RandomAccessIterator> - void + inline void partial_sort(_RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last) @@ -2269,10 +2548,7 @@ namespace std __glibcxx_requires_valid_range(__first, __middle); __glibcxx_requires_valid_range(__middle, __last); - std::make_heap(__first, __middle); - for (_RandomAccessIterator __i = __middle; __i < __last; ++__i) - if (*__i < *__first) - std::__pop_heap(__first, __middle, __i, _ValueType(*__i)); + std::__heap_select(__first, __middle, __last); std::sort_heap(__first, __middle); } @@ -2295,7 +2571,7 @@ namespace std * are both false. */ template<typename _RandomAccessIterator, typename _Compare> - void + inline void partial_sort(_RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last, @@ -2312,10 +2588,7 @@ namespace std __glibcxx_requires_valid_range(__first, __middle); __glibcxx_requires_valid_range(__middle, __last); - std::make_heap(__first, __middle, __comp); - for (_RandomAccessIterator __i = __middle; __i < __last; ++__i) - if (__comp(*__i, *__first)) - std::__pop_heap(__first, __middle, __i, _ValueType(*__i), __comp); + std::__heap_select(__first, __middle, __last, __comp); std::sort_heap(__first, __middle, __comp); } @@ -2353,8 +2626,9 @@ namespace std __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>) __glibcxx_function_requires(_ConvertibleConcept<_InputValueType, _OutputValueType>) + __glibcxx_function_requires(_LessThanOpConcept<_InputValueType, + _OutputValueType>) __glibcxx_function_requires(_LessThanComparableConcept<_OutputValueType>) - __glibcxx_function_requires(_LessThanComparableConcept<_InputValueType>) __glibcxx_requires_valid_range(__first, __last); __glibcxx_requires_valid_range(__result_first, __result_last); @@ -2421,6 +2695,8 @@ namespace std __glibcxx_function_requires(_ConvertibleConcept<_InputValueType, _OutputValueType>) __glibcxx_function_requires(_BinaryPredicateConcept<_Compare, + _InputValueType, _OutputValueType>) + __glibcxx_function_requires(_BinaryPredicateConcept<_Compare, _OutputValueType, _OutputValueType>) __glibcxx_requires_valid_range(__first, __last); __glibcxx_requires_valid_range(__result_first, __result_last); @@ -2463,7 +2739,7 @@ namespace std typedef typename iterator_traits<_RandomAccessIterator>::value_type _ValueType; - while (__last - __first > _S_threshold) + while (__last - __first > int(_S_threshold)) { if (__depth_limit == 0) { @@ -2499,7 +2775,7 @@ namespace std typedef typename iterator_traits<_RandomAccessIterator>::value_type _ValueType; - while (__last - __first > _S_threshold) + while (__last - __first > int(_S_threshold)) { if (__depth_limit == 0) { @@ -2550,7 +2826,8 @@ namespace std if (__first != __last) { - std::__introsort_loop(__first, __last, __lg(__last - __first) * 2); + std::__introsort_loop(__first, __last, + std::__lg(__last - __first) * 2); std::__final_insertion_sort(__first, __last); } } @@ -2586,8 +2863,8 @@ namespace std if (__first != __last) { - std::__introsort_loop(__first, __last, __lg(__last - __first) * 2, - __comp); + std::__introsort_loop(__first, __last, + std::__lg(__last - __first) * 2, __comp); std::__final_insertion_sort(__first, __last, __comp); } } @@ -2613,13 +2890,8 @@ namespace std _DistanceType; // concept requirements - // Note that these are slightly stricter than those of the 4-argument - // version, defined next. The difference is in the strictness of the - // comparison operations... so for looser checking, define your own - // comparison function, as was intended. __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>) - __glibcxx_function_requires(_SameTypeConcept<_Tp, _ValueType>) - __glibcxx_function_requires(_LessThanComparableConcept<_Tp>) + __glibcxx_function_requires(_LessThanOpConcept<_ValueType, _Tp>) __glibcxx_requires_partitioned(__first, __last, __val); _DistanceType __len = std::distance(__first, __last); @@ -2715,10 +2987,8 @@ namespace std _DistanceType; // concept requirements - // See comments on lower_bound. __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>) - __glibcxx_function_requires(_SameTypeConcept<_Tp, _ValueType>) - __glibcxx_function_requires(_LessThanComparableConcept<_Tp>) + __glibcxx_function_requires(_LessThanOpConcept<_Tp, _ValueType>) __glibcxx_requires_partitioned(__first, __last, __val); _DistanceType __len = std::distance(__first, __last); @@ -2961,16 +3231,19 @@ namespace std _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result) { + typedef typename iterator_traits<_InputIterator1>::value_type + _ValueType1; + typedef typename iterator_traits<_InputIterator2>::value_type + _ValueType2; + // concept requirements __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>) __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>) __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator, - typename iterator_traits<_InputIterator1>::value_type>) - __glibcxx_function_requires(_SameTypeConcept< - typename iterator_traits<_InputIterator1>::value_type, - typename iterator_traits<_InputIterator2>::value_type>) - __glibcxx_function_requires(_LessThanComparableConcept< - typename iterator_traits<_InputIterator1>::value_type>) + _ValueType1>) + __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator, + _ValueType2>) + __glibcxx_function_requires(_LessThanOpConcept<_ValueType2, _ValueType1>) __glibcxx_requires_sorted(__first1, __last1); __glibcxx_requires_sorted(__first2, __last2); @@ -3019,17 +3292,20 @@ namespace std _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp) { + typedef typename iterator_traits<_InputIterator1>::value_type + _ValueType1; + typedef typename iterator_traits<_InputIterator2>::value_type + _ValueType2; + // concept requirements __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>) __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>) - __glibcxx_function_requires(_SameTypeConcept< - typename iterator_traits<_InputIterator1>::value_type, - typename iterator_traits<_InputIterator2>::value_type>) __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator, - typename iterator_traits<_InputIterator1>::value_type>) + _ValueType1>) + __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator, + _ValueType2>) __glibcxx_function_requires(_BinaryPredicateConcept<_Compare, - typename iterator_traits<_InputIterator1>::value_type, - typename iterator_traits<_InputIterator2>::value_type>) + _ValueType2, _ValueType1>) __glibcxx_requires_sorted_pred(__first1, __last1, __comp); __glibcxx_requires_sorted_pred(__first2, __last2, __comp); @@ -3610,13 +3886,13 @@ namespace std __glibcxx_function_requires(_LessThanComparableConcept<_ValueType>) __glibcxx_requires_valid_range(__first, __last); - _Temporary_buffer<_RandomAccessIterator, _ValueType> - buf(__first, __last); - if (buf.begin() == 0) + _Temporary_buffer<_RandomAccessIterator, _ValueType> __buf(__first, + __last); + if (__buf.begin() == 0) std::__inplace_stable_sort(__first, __last); else - std::__stable_sort_adaptive(__first, __last, buf.begin(), - _DistanceType(buf.size())); + std::__stable_sort_adaptive(__first, __last, __buf.begin(), + _DistanceType(__buf.size())); } /** @@ -3654,12 +3930,86 @@ namespace std _ValueType>) __glibcxx_requires_valid_range(__first, __last); - _Temporary_buffer<_RandomAccessIterator, _ValueType> buf(__first, __last); - if (buf.begin() == 0) + _Temporary_buffer<_RandomAccessIterator, _ValueType> __buf(__first, + __last); + if (__buf.begin() == 0) std::__inplace_stable_sort(__first, __last, __comp); else - std::__stable_sort_adaptive(__first, __last, buf.begin(), - _DistanceType(buf.size()), __comp); + std::__stable_sort_adaptive(__first, __last, __buf.begin(), + _DistanceType(__buf.size()), __comp); + } + + + template<typename _RandomAccessIterator, typename _Size> + void + __introselect(_RandomAccessIterator __first, _RandomAccessIterator __nth, + _RandomAccessIterator __last, _Size __depth_limit) + { + typedef typename iterator_traits<_RandomAccessIterator>::value_type + _ValueType; + + while (__last - __first > 3) + { + if (__depth_limit == 0) + { + std::__heap_select(__first, __nth + 1, __last); + // Place the nth largest element in its final position. + std::iter_swap(__first, __nth); + return; + } + --__depth_limit; + _RandomAccessIterator __cut = + std::__unguarded_partition(__first, __last, + _ValueType(std::__median(*__first, + *(__first + + (__last + - __first) + / 2), + *(__last + - 1)))); + if (__cut <= __nth) + __first = __cut; + else + __last = __cut; + } + std::__insertion_sort(__first, __last); + } + + template<typename _RandomAccessIterator, typename _Size, typename _Compare> + void + __introselect(_RandomAccessIterator __first, _RandomAccessIterator __nth, + _RandomAccessIterator __last, _Size __depth_limit, + _Compare __comp) + { + typedef typename iterator_traits<_RandomAccessIterator>::value_type + _ValueType; + + while (__last - __first > 3) + { + if (__depth_limit == 0) + { + std::__heap_select(__first, __nth + 1, __last, __comp); + // Place the nth largest element in its final position. + std::iter_swap(__first, __nth); + return; + } + --__depth_limit; + _RandomAccessIterator __cut = + std::__unguarded_partition(__first, __last, + _ValueType(std::__median(*__first, + *(__first + + (__last + - __first) + / 2), + *(__last - 1), + __comp)), + __comp); + if (__cut <= __nth) + __first = __cut; + else + __last = __cut; + } + std::__insertion_sort(__first, __last, __comp); } /** @@ -3678,9 +4028,8 @@ namespace std * holds that @p *j<*i is false. */ template<typename _RandomAccessIterator> - void - nth_element(_RandomAccessIterator __first, - _RandomAccessIterator __nth, + inline void + nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomAccessIterator __last) { typedef typename iterator_traits<_RandomAccessIterator>::value_type @@ -3693,23 +4042,11 @@ namespace std __glibcxx_requires_valid_range(__first, __nth); __glibcxx_requires_valid_range(__nth, __last); - while (__last - __first > 3) - { - _RandomAccessIterator __cut = - std::__unguarded_partition(__first, __last, - _ValueType(std::__median(*__first, - *(__first - + (__last - - __first) - / 2), - *(__last - - 1)))); - if (__cut <= __nth) - __first = __cut; - else - __last = __cut; - } - std::__insertion_sort(__first, __last); + if (__first == __last || __nth == __last) + return; + + std::__introselect(__first, __nth, __last, + std::__lg(__last - __first) * 2); } /** @@ -3729,11 +4066,9 @@ namespace std * holds that @p comp(*j,*i) is false. */ template<typename _RandomAccessIterator, typename _Compare> - void - nth_element(_RandomAccessIterator __first, - _RandomAccessIterator __nth, - _RandomAccessIterator __last, - _Compare __comp) + inline void + nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, + _RandomAccessIterator __last, _Compare __comp) { typedef typename iterator_traits<_RandomAccessIterator>::value_type _ValueType; @@ -3746,23 +4081,11 @@ namespace std __glibcxx_requires_valid_range(__first, __nth); __glibcxx_requires_valid_range(__nth, __last); - while (__last - __first > 3) - { - _RandomAccessIterator __cut = - std::__unguarded_partition(__first, __last, - _ValueType(std::__median(*__first, - *(__first - + (__last - - __first) - / 2), - *(__last - 1), - __comp)), __comp); - if (__cut <= __nth) - __first = __cut; - else - __last = __cut; - } - std::__insertion_sort(__first, __last, __comp); + if (__first == __last || __nth == __last) + return; + + std::__introselect(__first, __nth, __last, + std::__lg(__last - __first) * 2, __comp); } /** @@ -3792,10 +4115,9 @@ namespace std _DistanceType; // concept requirements - // See comments on lower_bound. __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>) - __glibcxx_function_requires(_SameTypeConcept<_Tp, _ValueType>) - __glibcxx_function_requires(_LessThanComparableConcept<_Tp>) + __glibcxx_function_requires(_LessThanOpConcept<_ValueType, _Tp>) + __glibcxx_function_requires(_LessThanOpConcept<_Tp, _ValueType>) __glibcxx_requires_partitioned(__first, __last, __val); _DistanceType __len = std::distance(__first, __last); @@ -3906,12 +4228,12 @@ namespace std binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __val) { + typedef typename iterator_traits<_ForwardIterator>::value_type + _ValueType; + // concept requirements - // See comments on lower_bound. __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>) - __glibcxx_function_requires(_SameTypeConcept<_Tp, - typename iterator_traits<_ForwardIterator>::value_type>) - __glibcxx_function_requires(_LessThanComparableConcept<_Tp>) + __glibcxx_function_requires(_LessThanOpConcept<_Tp, _ValueType>) __glibcxx_requires_partitioned(__first, __last, __val); _ForwardIterator __i = std::lower_bound(__first, __last, __val); @@ -3938,12 +4260,13 @@ namespace std binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __val, _Compare __comp) { + typedef typename iterator_traits<_ForwardIterator>::value_type + _ValueType; + // concept requirements __glibcxx_function_requires(_ForwardIteratorConcept<_ForwardIterator>) __glibcxx_function_requires(_BinaryPredicateConcept<_Compare, - typename iterator_traits<_ForwardIterator>::value_type, _Tp>) - __glibcxx_function_requires(_BinaryPredicateConcept<_Compare, _Tp, - typename iterator_traits<_ForwardIterator>::value_type>) + _Tp, _ValueType>) __glibcxx_requires_partitioned_pred(__first, __last, __val, __comp); _ForwardIterator __i = std::lower_bound(__first, __last, __val, __comp); @@ -3976,14 +4299,16 @@ namespace std includes(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2) { + typedef typename iterator_traits<_InputIterator1>::value_type + _ValueType1; + typedef typename iterator_traits<_InputIterator2>::value_type + _ValueType2; + // concept requirements __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>) __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>) - __glibcxx_function_requires(_SameTypeConcept< - typename iterator_traits<_InputIterator1>::value_type, - typename iterator_traits<_InputIterator2>::value_type>) - __glibcxx_function_requires(_LessThanComparableConcept< - typename iterator_traits<_InputIterator1>::value_type>) + __glibcxx_function_requires(_LessThanOpConcept<_ValueType1, _ValueType2>) + __glibcxx_function_requires(_LessThanOpConcept<_ValueType2, _ValueType1>) __glibcxx_requires_sorted(__first1, __last1); __glibcxx_requires_sorted(__first2, __last2); @@ -4023,15 +4348,18 @@ namespace std includes(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, _Compare __comp) { + typedef typename iterator_traits<_InputIterator1>::value_type + _ValueType1; + typedef typename iterator_traits<_InputIterator2>::value_type + _ValueType2; + // concept requirements __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>) __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>) - __glibcxx_function_requires(_SameTypeConcept< - typename iterator_traits<_InputIterator1>::value_type, - typename iterator_traits<_InputIterator2>::value_type>) __glibcxx_function_requires(_BinaryPredicateConcept<_Compare, - typename iterator_traits<_InputIterator1>::value_type, - typename iterator_traits<_InputIterator2>::value_type>) + _ValueType1, _ValueType2>) + __glibcxx_function_requires(_BinaryPredicateConcept<_Compare, + _ValueType2, _ValueType1>) __glibcxx_requires_sorted_pred(__first1, __last1, __comp); __glibcxx_requires_sorted_pred(__first2, __last2, __comp); @@ -4070,16 +4398,20 @@ namespace std _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result) { + typedef typename iterator_traits<_InputIterator1>::value_type + _ValueType1; + typedef typename iterator_traits<_InputIterator2>::value_type + _ValueType2; + // concept requirements __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>) __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>) __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator, - typename iterator_traits<_InputIterator1>::value_type>) - __glibcxx_function_requires(_SameTypeConcept< - typename iterator_traits<_InputIterator1>::value_type, - typename iterator_traits<_InputIterator2>::value_type>) - __glibcxx_function_requires(_LessThanComparableConcept< - typename iterator_traits<_InputIterator1>::value_type>) + _ValueType1>) + __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator, + _ValueType2>) + __glibcxx_function_requires(_LessThanOpConcept<_ValueType1, _ValueType2>) + __glibcxx_function_requires(_LessThanOpConcept<_ValueType2, _ValueType1>) __glibcxx_requires_sorted(__first1, __last1); __glibcxx_requires_sorted(__first2, __last2); @@ -4132,17 +4464,22 @@ namespace std _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp) { + typedef typename iterator_traits<_InputIterator1>::value_type + _ValueType1; + typedef typename iterator_traits<_InputIterator2>::value_type + _ValueType2; + // concept requirements __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>) __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>) - __glibcxx_function_requires(_SameTypeConcept< - typename iterator_traits<_InputIterator1>::value_type, - typename iterator_traits<_InputIterator2>::value_type>) __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator, - typename iterator_traits<_InputIterator1>::value_type>) + _ValueType1>) + __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator, + _ValueType2>) __glibcxx_function_requires(_BinaryPredicateConcept<_Compare, - typename iterator_traits<_InputIterator1>::value_type, - typename iterator_traits<_InputIterator2>::value_type>) + _ValueType1, _ValueType2>) + __glibcxx_function_requires(_BinaryPredicateConcept<_Compare, + _ValueType2, _ValueType1>) __glibcxx_requires_sorted_pred(__first1, __last1, __comp); __glibcxx_requires_sorted_pred(__first2, __last2, __comp); @@ -4193,16 +4530,18 @@ namespace std _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result) { + typedef typename iterator_traits<_InputIterator1>::value_type + _ValueType1; + typedef typename iterator_traits<_InputIterator2>::value_type + _ValueType2; + // concept requirements __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>) __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>) __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator, - typename iterator_traits<_InputIterator1>::value_type>) - __glibcxx_function_requires(_SameTypeConcept< - typename iterator_traits<_InputIterator1>::value_type, - typename iterator_traits<_InputIterator2>::value_type>) - __glibcxx_function_requires(_LessThanComparableConcept< - typename iterator_traits<_InputIterator1>::value_type>) + _ValueType1>) + __glibcxx_function_requires(_LessThanOpConcept<_ValueType1, _ValueType2>) + __glibcxx_function_requires(_LessThanOpConcept<_ValueType2, _ValueType1>) __glibcxx_requires_sorted(__first1, __last1); __glibcxx_requires_sorted(__first2, __last2); @@ -4247,17 +4586,20 @@ namespace std _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp) { + typedef typename iterator_traits<_InputIterator1>::value_type + _ValueType1; + typedef typename iterator_traits<_InputIterator2>::value_type + _ValueType2; + // concept requirements __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>) __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>) - __glibcxx_function_requires(_SameTypeConcept< - typename iterator_traits<_InputIterator1>::value_type, - typename iterator_traits<_InputIterator2>::value_type>) __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator, - typename iterator_traits<_InputIterator1>::value_type>) + _ValueType1>) + __glibcxx_function_requires(_BinaryPredicateConcept<_Compare, + _ValueType1, _ValueType2>) __glibcxx_function_requires(_BinaryPredicateConcept<_Compare, - typename iterator_traits<_InputIterator1>::value_type, - typename iterator_traits<_InputIterator2>::value_type>) + _ValueType2, _ValueType1>) __glibcxx_requires_sorted_pred(__first1, __last1, __comp); __glibcxx_requires_sorted_pred(__first2, __last2, __comp); @@ -4301,16 +4643,18 @@ namespace std _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result) { + typedef typename iterator_traits<_InputIterator1>::value_type + _ValueType1; + typedef typename iterator_traits<_InputIterator2>::value_type + _ValueType2; + // concept requirements __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>) __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>) __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator, - typename iterator_traits<_InputIterator1>::value_type>) - __glibcxx_function_requires(_SameTypeConcept< - typename iterator_traits<_InputIterator1>::value_type, - typename iterator_traits<_InputIterator2>::value_type>) - __glibcxx_function_requires(_LessThanComparableConcept< - typename iterator_traits<_InputIterator1>::value_type>) + _ValueType1>) + __glibcxx_function_requires(_LessThanOpConcept<_ValueType1, _ValueType2>) + __glibcxx_function_requires(_LessThanOpConcept<_ValueType2, _ValueType1>) __glibcxx_requires_sorted(__first1, __last1); __glibcxx_requires_sorted(__first2, __last2); @@ -4359,17 +4703,20 @@ namespace std _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp) { + typedef typename iterator_traits<_InputIterator1>::value_type + _ValueType1; + typedef typename iterator_traits<_InputIterator2>::value_type + _ValueType2; + // concept requirements __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>) __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>) - __glibcxx_function_requires(_SameTypeConcept< - typename iterator_traits<_InputIterator1>::value_type, - typename iterator_traits<_InputIterator2>::value_type>) __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator, - typename iterator_traits<_InputIterator1>::value_type>) + _ValueType1>) + __glibcxx_function_requires(_BinaryPredicateConcept<_Compare, + _ValueType1, _ValueType2>) __glibcxx_function_requires(_BinaryPredicateConcept<_Compare, - typename iterator_traits<_InputIterator1>::value_type, - typename iterator_traits<_InputIterator2>::value_type>) + _ValueType2, _ValueType1>) __glibcxx_requires_sorted_pred(__first1, __last1, __comp); __glibcxx_requires_sorted_pred(__first2, __last2, __comp); @@ -4413,16 +4760,20 @@ namespace std _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result) { + typedef typename iterator_traits<_InputIterator1>::value_type + _ValueType1; + typedef typename iterator_traits<_InputIterator2>::value_type + _ValueType2; + // concept requirements __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>) __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>) __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator, - typename iterator_traits<_InputIterator1>::value_type>) - __glibcxx_function_requires(_SameTypeConcept< - typename iterator_traits<_InputIterator1>::value_type, - typename iterator_traits<_InputIterator2>::value_type>) - __glibcxx_function_requires(_LessThanComparableConcept< - typename iterator_traits<_InputIterator1>::value_type>) + _ValueType1>) + __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator, + _ValueType2>) + __glibcxx_function_requires(_LessThanOpConcept<_ValueType1, _ValueType2>) + __glibcxx_function_requires(_LessThanOpConcept<_ValueType2, _ValueType1>) __glibcxx_requires_sorted(__first1, __last1); __glibcxx_requires_sorted(__first2, __last2); @@ -4475,17 +4826,22 @@ namespace std _OutputIterator __result, _Compare __comp) { + typedef typename iterator_traits<_InputIterator1>::value_type + _ValueType1; + typedef typename iterator_traits<_InputIterator2>::value_type + _ValueType2; + // concept requirements __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>) __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>) - __glibcxx_function_requires(_SameTypeConcept< - typename iterator_traits<_InputIterator1>::value_type, - typename iterator_traits<_InputIterator2>::value_type>) __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator, - typename iterator_traits<_InputIterator1>::value_type>) + _ValueType1>) + __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator, + _ValueType2>) + __glibcxx_function_requires(_BinaryPredicateConcept<_Compare, + _ValueType1, _ValueType2>) __glibcxx_function_requires(_BinaryPredicateConcept<_Compare, - typename iterator_traits<_InputIterator1>::value_type, - typename iterator_traits<_InputIterator2>::value_type>) + _ValueType2, _ValueType1>) __glibcxx_requires_sorted_pred(__first1, __last1, __comp); __glibcxx_requires_sorted_pred(__first2, __last2, __comp); @@ -5143,6 +5499,6 @@ namespace std __comp); } -} // namespace std +_GLIBCXX_END_NAMESPACE #endif /* _ALGO_H */ diff --git a/contrib/libstdc++/include/bits/stl_algobase.h b/contrib/libstdc++/include/bits/stl_algobase.h index d482529..6f19feb 100644 --- a/contrib/libstdc++/include/bits/stl_algobase.h +++ b/contrib/libstdc++/include/bits/stl_algobase.h @@ -1,6 +1,7 @@ // Bits and pieces used in algorithms -*- C++ -*- -// Copyright (C) 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. +// Copyright (C) 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 @@ -15,7 +16,7 @@ // 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// 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 @@ -66,18 +67,68 @@ #include <climits> #include <cstdlib> #include <cstddef> -#include <new> #include <iosfwd> #include <bits/stl_pair.h> -#include <bits/type_traits.h> +#include <bits/cpp_type_traits.h> +#include <ext/type_traits.h> #include <bits/stl_iterator_base_types.h> #include <bits/stl_iterator_base_funcs.h> #include <bits/stl_iterator.h> #include <bits/concept_check.h> #include <debug/debug.h> -namespace std -{ +_GLIBCXX_BEGIN_NAMESPACE(std) + + /** + * @brief Swaps two values. + * @param a A thing of arbitrary type. + * @param b Another thing of arbitrary type. + * @return Nothing. + * + * This is the simple classic generic implementation. It will work on + * any type which has a copy constructor and an assignment operator. + */ + template<typename _Tp> + inline void + swap(_Tp& __a, _Tp& __b) + { + // concept requirements + __glibcxx_function_requires(_SGIAssignableConcept<_Tp>) + + _Tp __tmp = __a; + __a = __b; + __b = __tmp; + } + + // See http://gcc.gnu.org/ml/libstdc++/2004-08/msg00167.html: in a + // nutshell, we are partially implementing the resolution of DR 187, + // when it's safe, i.e., the value_types are equal. + template<bool _BoolType> + struct __iter_swap + { + template<typename _ForwardIterator1, typename _ForwardIterator2> + static void + iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b) + { + typedef typename iterator_traits<_ForwardIterator1>::value_type + _ValueType1; + _ValueType1 __tmp = *__a; + *__a = *__b; + *__b = __tmp; + } + }; + + template<> + struct __iter_swap<true> + { + template<typename _ForwardIterator1, typename _ForwardIterator2> + static void + iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b) + { + swap(*__a, *__b); + } + }; + /** * @brief Swaps the contents of two iterators. * @param a An iterator. @@ -106,36 +157,17 @@ namespace std __glibcxx_function_requires(_ConvertibleConcept<_ValueType2, _ValueType1>) - const _ValueType1 __tmp = *__a; - *__a = *__b; - *__b = __tmp; + typedef typename iterator_traits<_ForwardIterator1>::reference + _ReferenceType1; + typedef typename iterator_traits<_ForwardIterator2>::reference + _ReferenceType2; + std::__iter_swap<__are_same<_ValueType1, _ValueType2>::__value && + __are_same<_ValueType1 &, _ReferenceType1>::__value && + __are_same<_ValueType2 &, _ReferenceType2>::__value>:: + iter_swap(__a, __b); } /** - * @brief Swaps two values. - * @param a A thing of arbitrary type. - * @param b Another thing of arbitrary type. - * @return Nothing. - * - * This is the simple classic generic implementation. It will work on - * any type which has a copy constructor and an assignment operator. - */ - template<typename _Tp> - inline void - swap(_Tp& __a, _Tp& __b) - { - // concept requirements - __glibcxx_function_requires(_SGIAssignableConcept<_Tp>) - - const _Tp __tmp = __a; - __a = __b; - __b = __tmp; - } - - #undef min - #undef max - - /** * @brief This does what you think it does. * @param a A thing of arbitrary type. * @param b Another thing of arbitrary type. @@ -219,113 +251,122 @@ namespace std return __a; } - // All of these auxiliary functions serve two purposes. (1) Replace + // All of these auxiliary structs serve two purposes. (1) Replace // calls to copy with memmove whenever possible. (Memmove, not memcpy, // because the input and output ranges are permitted to overlap.) // (2) If we're using random access iterators, then write the loop as // a for loop with an explicit count. - template<typename _InputIterator, typename _OutputIterator> - inline _OutputIterator - __copy(_InputIterator __first, _InputIterator __last, - _OutputIterator __result, input_iterator_tag) + template<bool, typename> + struct __copy { - for (; __first != __last; ++__result, ++__first) - *__result = *__first; - return __result; - } + template<typename _II, typename _OI> + static _OI + copy(_II __first, _II __last, _OI __result) + { + for (; __first != __last; ++__result, ++__first) + *__result = *__first; + return __result; + } + }; - template<typename _RandomAccessIterator, typename _OutputIterator> - inline _OutputIterator - __copy(_RandomAccessIterator __first, _RandomAccessIterator __last, - _OutputIterator __result, random_access_iterator_tag) - { - typedef typename iterator_traits<_RandomAccessIterator>::difference_type - _Distance; - for (_Distance __n = __last - __first; __n > 0; --__n) - { - *__result = *__first; - ++__first; - ++__result; + template<bool _BoolType> + struct __copy<_BoolType, random_access_iterator_tag> + { + template<typename _II, typename _OI> + static _OI + copy(_II __first, _II __last, _OI __result) + { + typedef typename iterator_traits<_II>::difference_type _Distance; + for(_Distance __n = __last - __first; __n > 0; --__n) + { + *__result = *__first; + ++__first; + ++__result; + } + return __result; } - return __result; - } + }; - template<typename _Tp> - inline _Tp* - __copy_trivial(const _Tp* __first, const _Tp* __last, _Tp* __result) + template<> + struct __copy<true, random_access_iterator_tag> { - std::memmove(__result, __first, sizeof(_Tp) * (__last - __first)); - return __result + (__last - __first); - } - - template<typename _InputIterator, typename _OutputIterator> - inline _OutputIterator - __copy_aux2(_InputIterator __first, _InputIterator __last, - _OutputIterator __result, __false_type) - { return std::__copy(__first, __last, __result, - std::__iterator_category(__first)); } - - template<typename _InputIterator, typename _OutputIterator> - inline _OutputIterator - __copy_aux2(_InputIterator __first, _InputIterator __last, - _OutputIterator __result, __true_type) - { return std::__copy(__first, __last, __result, - std::__iterator_category(__first)); } - - template<typename _Tp> - inline _Tp* - __copy_aux2(_Tp* __first, _Tp* __last, _Tp* __result, __true_type) - { return std::__copy_trivial(__first, __last, __result); } + template<typename _Tp> + static _Tp* + copy(const _Tp* __first, const _Tp* __last, _Tp* __result) + { + std::memmove(__result, __first, sizeof(_Tp) * (__last - __first)); + return __result + (__last - __first); + } + }; - template<typename _Tp> - inline _Tp* - __copy_aux2(const _Tp* __first, const _Tp* __last, _Tp* __result, - __true_type) - { return std::__copy_trivial(__first, __last, __result); } + template<typename _II, typename _OI> + inline _OI + __copy_aux(_II __first, _II __last, _OI __result) + { + typedef typename iterator_traits<_II>::value_type _ValueTypeI; + typedef typename iterator_traits<_OI>::value_type _ValueTypeO; + typedef typename iterator_traits<_II>::iterator_category _Category; + const bool __simple = (__is_scalar<_ValueTypeI>::__value + && __is_pointer<_II>::__value + && __is_pointer<_OI>::__value + && __are_same<_ValueTypeI, _ValueTypeO>::__value); - template<typename _InputIterator, typename _OutputIterator> - inline _OutputIterator - __copy_ni2(_InputIterator __first, _InputIterator __last, - _OutputIterator __result, __true_type) - { - typedef typename iterator_traits<_InputIterator>::value_type - _ValueType; - typedef typename __type_traits< - _ValueType>::has_trivial_assignment_operator _Trivial; - return _OutputIterator(std::__copy_aux2(__first, __last, __result.base(), - _Trivial())); + return std::__copy<__simple, _Category>::copy(__first, __last, __result); } - template<typename _InputIterator, typename _OutputIterator> - inline _OutputIterator - __copy_ni2(_InputIterator __first, _InputIterator __last, - _OutputIterator __result, __false_type) + // Helpers for streambuf iterators (either istream or ostream). + template<typename _CharT> + typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value, + ostreambuf_iterator<_CharT> >::__type + __copy_aux(_CharT*, _CharT*, ostreambuf_iterator<_CharT>); + + template<typename _CharT> + typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value, + ostreambuf_iterator<_CharT> >::__type + __copy_aux(const _CharT*, const _CharT*, ostreambuf_iterator<_CharT>); + + template<typename _CharT> + typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value, _CharT*>::__type + __copy_aux(istreambuf_iterator<_CharT>, istreambuf_iterator<_CharT>, + _CharT*); + + template<bool, bool> + struct __copy_normal + { + template<typename _II, typename _OI> + static _OI + __copy_n(_II __first, _II __last, _OI __result) + { return std::__copy_aux(__first, __last, __result); } + }; + + template<> + struct __copy_normal<true, false> { - typedef typename iterator_traits<_InputIterator>::value_type _ValueType; - typedef typename __type_traits< - _ValueType>::has_trivial_assignment_operator _Trivial; - return std::__copy_aux2(__first, __last, __result, _Trivial()); - } + template<typename _II, typename _OI> + static _OI + __copy_n(_II __first, _II __last, _OI __result) + { return std::__copy_aux(__first.base(), __last.base(), __result); } + }; - template<typename _InputIterator, typename _OutputIterator> - inline _OutputIterator - __copy_ni1(_InputIterator __first, _InputIterator __last, - _OutputIterator __result, __true_type) + template<> + struct __copy_normal<false, true> { - typedef typename _Is_normal_iterator<_OutputIterator>::_Normal __Normal; - return std::__copy_ni2(__first.base(), __last.base(), - __result, __Normal()); - } + template<typename _II, typename _OI> + static _OI + __copy_n(_II __first, _II __last, _OI __result) + { return _OI(std::__copy_aux(__first, __last, __result.base())); } + }; - template<typename _InputIterator, typename _OutputIterator> - inline _OutputIterator - __copy_ni1(_InputIterator __first, _InputIterator __last, - _OutputIterator __result, __false_type) + template<> + struct __copy_normal<true, true> { - typedef typename _Is_normal_iterator<_OutputIterator>::_Normal __Normal; - return std::__copy_ni2(__first, __last, __result, __Normal()); - } + template<typename _II, typename _OI> + static _OI + __copy_n(_II __first, _II __last, _OI __result) + { return _OI(std::__copy_aux(__first.base(), __last.base(), + __result.base())); } + }; /** * @brief Copies the range [first,last) into result. @@ -354,116 +395,114 @@ namespace std typename iterator_traits<_InputIterator>::value_type>) __glibcxx_requires_valid_range(__first, __last); - typedef typename _Is_normal_iterator<_InputIterator>::_Normal __Normal; - return std::__copy_ni1(__first, __last, __result, __Normal()); - } - - template<typename _BidirectionalIterator1, typename _BidirectionalIterator2> - inline _BidirectionalIterator2 - __copy_backward(_BidirectionalIterator1 __first, - _BidirectionalIterator1 __last, - _BidirectionalIterator2 __result, - bidirectional_iterator_tag) - { - while (__first != __last) - *--__result = *--__last; - return __result; - } - - template<typename _RandomAccessIterator, typename _BidirectionalIterator> - inline _BidirectionalIterator - __copy_backward(_RandomAccessIterator __first, _RandomAccessIterator __last, - _BidirectionalIterator __result, random_access_iterator_tag) - { - typename iterator_traits<_RandomAccessIterator>::difference_type __n; - for (__n = __last - __first; __n > 0; --__n) - *--__result = *--__last; - return __result; + const bool __in = __is_normal_iterator<_InputIterator>::__value; + const bool __out = __is_normal_iterator<_OutputIterator>::__value; + return std::__copy_normal<__in, __out>::__copy_n(__first, __last, + __result); } - - // This dispatch class is a workaround for compilers that do not - // have partial ordering of function templates. All we're doing is - // creating a specialization so that we can turn a call to copy_backward - // into a memmove whenever possible. - template<typename _BidirectionalIterator1, typename _BidirectionalIterator2, - typename _BoolType> - struct __copy_backward_dispatch - { - static _BidirectionalIterator2 - copy(_BidirectionalIterator1 __first, _BidirectionalIterator1 __last, - _BidirectionalIterator2 __result) - { return std::__copy_backward(__first, __last, __result, - std::__iterator_category(__first)); } + // Overload for streambuf iterators. + template<typename _CharT> + typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value, + ostreambuf_iterator<_CharT> >::__type + copy(istreambuf_iterator<_CharT>, istreambuf_iterator<_CharT>, + ostreambuf_iterator<_CharT>); + + template<bool, typename> + struct __copy_backward + { + template<typename _BI1, typename _BI2> + static _BI2 + __copy_b(_BI1 __first, _BI1 __last, _BI2 __result) + { + while (__first != __last) + *--__result = *--__last; + return __result; + } }; - template<typename _Tp> - struct __copy_backward_dispatch<_Tp*, _Tp*, __true_type> - { - static _Tp* - copy(const _Tp* __first, const _Tp* __last, _Tp* __result) - { - const ptrdiff_t _Num = __last - __first; - std::memmove(__result - _Num, __first, sizeof(_Tp) * _Num); - return __result - _Num; - } + template<bool _BoolType> + struct __copy_backward<_BoolType, random_access_iterator_tag> + { + template<typename _BI1, typename _BI2> + static _BI2 + __copy_b(_BI1 __first, _BI1 __last, _BI2 __result) + { + typename iterator_traits<_BI1>::difference_type __n; + for (__n = __last - __first; __n > 0; --__n) + *--__result = *--__last; + return __result; + } }; - template<typename _Tp> - struct __copy_backward_dispatch<const _Tp*, _Tp*, __true_type> - { - static _Tp* - copy(const _Tp* __first, const _Tp* __last, _Tp* __result) - { - return std::__copy_backward_dispatch<_Tp*, _Tp*, __true_type> - ::copy(__first, __last, __result); - } + template<> + struct __copy_backward<true, random_access_iterator_tag> + { + template<typename _Tp> + static _Tp* + __copy_b(const _Tp* __first, const _Tp* __last, _Tp* __result) + { + const ptrdiff_t _Num = __last - __first; + std::memmove(__result - _Num, __first, sizeof(_Tp) * _Num); + return __result - _Num; + } }; template<typename _BI1, typename _BI2> inline _BI2 __copy_backward_aux(_BI1 __first, _BI1 __last, _BI2 __result) { - typedef typename __type_traits<typename iterator_traits<_BI2>::value_type> - ::has_trivial_assignment_operator _Trivial; - return - std::__copy_backward_dispatch<_BI1, _BI2, _Trivial>::copy(__first, - __last, - __result); + typedef typename iterator_traits<_BI1>::value_type _ValueType1; + typedef typename iterator_traits<_BI2>::value_type _ValueType2; + typedef typename iterator_traits<_BI1>::iterator_category _Category; + const bool __simple = (__is_scalar<_ValueType1>::__value + && __is_pointer<_BI1>::__value + && __is_pointer<_BI2>::__value + && __are_same<_ValueType1, _ValueType2>::__value); + + return std::__copy_backward<__simple, _Category>::__copy_b(__first, + __last, + __result); } - template <typename _BI1, typename _BI2> - inline _BI2 - __copy_backward_output_normal_iterator(_BI1 __first, _BI1 __last, - _BI2 __result, __true_type) - { return _BI2(std::__copy_backward_aux(__first, __last, __result.base())); } + template<bool, bool> + struct __copy_backward_normal + { + template<typename _BI1, typename _BI2> + static _BI2 + __copy_b_n(_BI1 __first, _BI1 __last, _BI2 __result) + { return std::__copy_backward_aux(__first, __last, __result); } + }; - template <typename _BI1, typename _BI2> - inline _BI2 - __copy_backward_output_normal_iterator(_BI1 __first, _BI1 __last, - _BI2 __result, __false_type) - { return std::__copy_backward_aux(__first, __last, __result); } + template<> + struct __copy_backward_normal<true, false> + { + template<typename _BI1, typename _BI2> + static _BI2 + __copy_b_n(_BI1 __first, _BI1 __last, _BI2 __result) + { return std::__copy_backward_aux(__first.base(), __last.base(), + __result); } + }; - template <typename _BI1, typename _BI2> - inline _BI2 - __copy_backward_input_normal_iterator(_BI1 __first, _BI1 __last, - _BI2 __result, __true_type) + template<> + struct __copy_backward_normal<false, true> { - typedef typename _Is_normal_iterator<_BI2>::_Normal __Normal; - return std::__copy_backward_output_normal_iterator(__first.base(), - __last.base(), - __result, __Normal()); - } + template<typename _BI1, typename _BI2> + static _BI2 + __copy_b_n(_BI1 __first, _BI1 __last, _BI2 __result) + { return _BI2(std::__copy_backward_aux(__first, __last, + __result.base())); } + }; - template <typename _BI1, typename _BI2> - inline _BI2 - __copy_backward_input_normal_iterator(_BI1 __first, _BI1 __last, - _BI2 __result, __false_type) + template<> + struct __copy_backward_normal<true, true> { - typedef typename _Is_normal_iterator<_BI2>::_Normal __Normal; - return std::__copy_backward_output_normal_iterator(__first, __last, - __result, __Normal()); - } + template<typename _BI1, typename _BI2> + static _BI2 + __copy_b_n(_BI1 __first, _BI1 __last, _BI2 __result) + { return _BI2(std::__copy_backward_aux(__first.base(), __last.base(), + __result.base())); } + }; /** * @brief Copies the range [first,last) into result. @@ -494,11 +533,39 @@ namespace std typename iterator_traits<_BI2>::value_type>) __glibcxx_requires_valid_range(__first, __last); - typedef typename _Is_normal_iterator<_BI1>::_Normal __Normal; - return std::__copy_backward_input_normal_iterator(__first, __last, - __result, __Normal()); + const bool __bi1 = __is_normal_iterator<_BI1>::__value; + const bool __bi2 = __is_normal_iterator<_BI2>::__value; + return std::__copy_backward_normal<__bi1, __bi2>::__copy_b_n(__first, + __last, + __result); } + template<bool> + struct __fill + { + template<typename _ForwardIterator, typename _Tp> + static void + fill(_ForwardIterator __first, _ForwardIterator __last, + const _Tp& __value) + { + for (; __first != __last; ++__first) + *__first = __value; + } + }; + + template<> + struct __fill<true> + { + template<typename _ForwardIterator, typename _Tp> + static void + fill(_ForwardIterator __first, _ForwardIterator __last, + const _Tp& __value) + { + const _Tp __tmp = __value; + for (; __first != __last; ++__first) + *__first = __tmp; + } + }; /** * @brief Fills the range [first,last) with copies of value. @@ -520,31 +587,8 @@ namespace std _ForwardIterator>) __glibcxx_requires_valid_range(__first, __last); - for ( ; __first != __last; ++__first) - *__first = __value; - } - - /** - * @brief Fills the range [first,first+n) with copies of value. - * @param first An output iterator. - * @param n The count of copies to perform. - * @param value A reference-to-const of arbitrary type. - * @return The iterator at first+n. - * - * This function fills a range with copies of the same value. For one-byte - * types filling contiguous areas of memory, this becomes an inline call to - * @c memset. - */ - template<typename _OutputIterator, typename _Size, typename _Tp> - _OutputIterator - fill_n(_OutputIterator __first, _Size __n, const _Tp& __value) - { - // concept requirements - __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,_Tp>) - - for ( ; __n > 0; --__n, ++__first) - *__first = __value; - return __first; + const bool __scalar = __is_scalar<_Tp>::__value; + std::__fill<__scalar>::fill(__first, __last, __value); } // Specialization: for one-byte types we can use memset. @@ -572,6 +616,55 @@ namespace std std::memset(__first, static_cast<unsigned char>(__tmp), __last - __first); } + template<bool> + struct __fill_n + { + template<typename _OutputIterator, typename _Size, typename _Tp> + static _OutputIterator + fill_n(_OutputIterator __first, _Size __n, const _Tp& __value) + { + for (; __n > 0; --__n, ++__first) + *__first = __value; + return __first; + } + }; + + template<> + struct __fill_n<true> + { + template<typename _OutputIterator, typename _Size, typename _Tp> + static _OutputIterator + fill_n(_OutputIterator __first, _Size __n, const _Tp& __value) + { + const _Tp __tmp = __value; + for (; __n > 0; --__n, ++__first) + *__first = __tmp; + return __first; + } + }; + + /** + * @brief Fills the range [first,first+n) with copies of value. + * @param first An output iterator. + * @param n The count of copies to perform. + * @param value A reference-to-const of arbitrary type. + * @return The iterator at first+n. + * + * This function fills a range with copies of the same value. For one-byte + * types filling contiguous areas of memory, this becomes an inline call to + * @c memset. + */ + template<typename _OutputIterator, typename _Size, typename _Tp> + _OutputIterator + fill_n(_OutputIterator __first, _Size __n, const _Tp& __value) + { + // concept requirements + __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator, _Tp>) + + const bool __scalar = __is_scalar<_Tp>::__value; + return std::__fill_n<__scalar>::fill_n(__first, __n, __value); + } + template<typename _Size> inline unsigned char* fill_n(unsigned char* __first, _Size __n, const unsigned char& __c) @@ -582,7 +675,7 @@ namespace std template<typename _Size> inline signed char* - fill_n(char* __first, _Size __n, const signed char& __c) + fill_n(signed char* __first, _Size __n, const signed char& __c) { std::fill(__first, __first + __n, __c); return __first + __n; @@ -596,7 +689,6 @@ namespace std return __first + __n; } - /** * @brief Finds the places in ranges which don't match. * @param first1 An input iterator. @@ -686,8 +778,8 @@ namespace std typename iterator_traits<_InputIterator1>::value_type, typename iterator_traits<_InputIterator2>::value_type>) __glibcxx_requires_valid_range(__first1, __last1); - - for ( ; __first1 != __last1; ++__first1, ++__first2) + + for (; __first1 != __last1; ++__first1, ++__first2) if (!(*__first1 == *__first2)) return false; return true; @@ -718,7 +810,7 @@ namespace std __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>) __glibcxx_requires_valid_range(__first1, __last1); - for ( ; __first1 != __last1; ++__first1, ++__first2) + for (; __first1 != __last1; ++__first1, ++__first2) if (!__binary_pred(*__first1, *__first2)) return false; return true; @@ -755,7 +847,8 @@ namespace std __glibcxx_requires_valid_range(__first1, __last1); __glibcxx_requires_valid_range(__first2, __last2); - for (;__first1 != __last1 && __first2 != __last2; ++__first1, ++__first2) + for (; __first1 != __last1 && __first2 != __last2; + ++__first1, ++__first2) { if (*__first1 < *__first2) return true; @@ -790,8 +883,8 @@ namespace std __glibcxx_requires_valid_range(__first1, __last1); __glibcxx_requires_valid_range(__first2, __last2); - for ( ; __first1 != __last1 && __first2 != __last2 - ; ++__first1, ++__first2) + for (; __first1 != __last1 && __first2 != __last2; + ++__first1, ++__first2) { if (__comp(*__first1, *__first2)) return true; @@ -837,6 +930,6 @@ namespace std #endif /* CHAR_MAX == SCHAR_MAX */ } -} // namespace std +_GLIBCXX_END_NAMESPACE #endif diff --git a/contrib/libstdc++/include/bits/stl_bvector.h b/contrib/libstdc++/include/bits/stl_bvector.h index afae738..9dc2656 100644 --- a/contrib/libstdc++/include/bits/stl_bvector.h +++ b/contrib/libstdc++/include/bits/stl_bvector.h @@ -1,6 +1,7 @@ // vector<bool> specialization -*- C++ -*- -// Copyright (C) 2001, 2002, 2003, 2004 Free Software Foundation, Inc. +// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 +// 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 @@ -15,7 +16,7 @@ // 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// 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 @@ -61,8 +62,8 @@ #ifndef _BVECTOR_H #define _BVECTOR_H 1 -namespace _GLIBCXX_STD -{ +_GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD) + typedef unsigned long _Bit_type; enum { _S_word_bit = int(CHAR_BIT * sizeof(_Bit_type)) }; @@ -76,7 +77,8 @@ namespace _GLIBCXX_STD _Bit_reference() : _M_p(0), _M_mask(0) { } - operator bool() const { return !!(*_M_p & _M_mask); } + operator bool() const + { return !!(*_M_p & _M_mask); } _Bit_reference& operator=(bool __x) @@ -101,10 +103,12 @@ namespace _GLIBCXX_STD { return !bool(*this) && bool(__x); } void - flip() { *_M_p ^= _M_mask; } + flip() + { *_M_p ^= _M_mask; } }; - struct _Bit_iterator_base : public iterator<random_access_iterator_tag, bool> + struct _Bit_iterator_base + : public std::iterator<std::random_access_iterator_tag, bool> { _Bit_type * _M_p; unsigned int _M_offset; @@ -115,7 +119,7 @@ namespace _GLIBCXX_STD void _M_bump_up() { - if (_M_offset++ == _S_word_bit - 1) + if (_M_offset++ == int(_S_word_bit) - 1) { _M_offset = 0; ++_M_p; @@ -127,7 +131,7 @@ namespace _GLIBCXX_STD { if (_M_offset-- == 0) { - _M_offset = _S_word_bit - 1; + _M_offset = int(_S_word_bit) - 1; --_M_p; } } @@ -136,15 +140,14 @@ namespace _GLIBCXX_STD _M_incr(ptrdiff_t __i) { difference_type __n = __i + _M_offset; - _M_p += __n / _S_word_bit; - __n = __n % _S_word_bit; + _M_p += __n / int(_S_word_bit); + __n = __n % int(_S_word_bit); if (__n < 0) { - _M_offset = static_cast<unsigned int>(__n + _S_word_bit); + __n += int(_S_word_bit); --_M_p; } - else - _M_offset = static_cast<unsigned int>(__n); + _M_offset = static_cast<unsigned int>(__n); } bool @@ -178,7 +181,8 @@ namespace _GLIBCXX_STD inline ptrdiff_t operator-(const _Bit_iterator_base& __x, const _Bit_iterator_base& __y) { - return _S_word_bit * (__x._M_p - __y._M_p) + __x._M_offset - __y._M_offset; + return (int(_S_word_bit) * (__x._M_p - __y._M_p) + + __x._M_offset - __y._M_offset); } struct _Bit_iterator : public _Bit_iterator_base @@ -188,11 +192,13 @@ namespace _GLIBCXX_STD typedef _Bit_iterator iterator; _Bit_iterator() : _Bit_iterator_base(0, 0) { } + _Bit_iterator(_Bit_type * __x, unsigned int __y) : _Bit_iterator_base(__x, __y) { } reference - operator*() const { return reference(_M_p, 1UL << _M_offset); } + operator*() const + { return reference(_M_p, 1UL << _M_offset); } iterator& operator++() @@ -253,13 +259,13 @@ namespace _GLIBCXX_STD } reference - operator[](difference_type __i) + operator[](difference_type __i) const { return *(*this + __i); } }; inline _Bit_iterator - operator+(ptrdiff_t __n, const _Bit_iterator& __x) { return __x + __n; } - + operator+(ptrdiff_t __n, const _Bit_iterator& __x) + { return __x + __n; } struct _Bit_const_iterator : public _Bit_iterator_base { @@ -269,8 +275,10 @@ namespace _GLIBCXX_STD typedef _Bit_const_iterator const_iterator; _Bit_const_iterator() : _Bit_iterator_base(0, 0) { } + _Bit_const_iterator(_Bit_type * __x, unsigned int __y) : _Bit_iterator_base(__x, __y) { } + _Bit_const_iterator(const _Bit_iterator& __x) : _Bit_iterator_base(__x._M_p, __x._M_offset) { } @@ -323,7 +331,8 @@ namespace _GLIBCXX_STD } const_iterator - operator+(difference_type __i) const { + operator+(difference_type __i) const + { const_iterator __tmp = *this; return __tmp += __i; } @@ -336,7 +345,7 @@ namespace _GLIBCXX_STD } const_reference - operator[](difference_type __i) + operator[](difference_type __i) const { return *(*this + __i); } }; @@ -344,13 +353,34 @@ namespace _GLIBCXX_STD operator+(ptrdiff_t __n, const _Bit_const_iterator& __x) { return __x + __n; } + inline void + __fill_bvector(_Bit_iterator __first, _Bit_iterator __last, bool __x) + { + for (; __first != __last; ++__first) + *__first = __x; + } + + inline void + fill(_Bit_iterator __first, _Bit_iterator __last, const bool& __x) + { + if (__first._M_p != __last._M_p) + { + std::fill(__first._M_p + 1, __last._M_p, __x ? ~0 : 0); + __fill_bvector(__first, _Bit_iterator(__first._M_p + 1, 0), __x); + __fill_bvector(_Bit_iterator(__last._M_p, 0), __last, __x); + } + else + __fill_bvector(__first, __last, __x); + } + template<class _Alloc> - class _Bvector_base + struct _Bvector_base { typedef typename _Alloc::template rebind<_Bit_type>::other _Bit_alloc_type; - struct _Bvector_impl : public _Bit_alloc_type + struct _Bvector_impl + : public _Bit_alloc_type { _Bit_iterator _M_start; _Bit_iterator _M_finish; @@ -363,36 +393,47 @@ namespace _GLIBCXX_STD public: typedef _Alloc allocator_type; + _Bit_alloc_type& + _M_get_Bit_allocator() + { return *static_cast<_Bit_alloc_type*>(&this->_M_impl); } + + const _Bit_alloc_type& + _M_get_Bit_allocator() const + { return *static_cast<const _Bit_alloc_type*>(&this->_M_impl); } + allocator_type get_allocator() const - { return *static_cast<const _Bit_alloc_type*>(&this->_M_impl); } + { return allocator_type(_M_get_Bit_allocator()); } _Bvector_base(const allocator_type& __a) : _M_impl(__a) { } - ~_Bvector_base() { this->_M_deallocate(); } + ~_Bvector_base() + { this->_M_deallocate(); } protected: _Bvector_impl _M_impl; _Bit_type* _M_allocate(size_t __n) - { return _M_impl.allocate((__n + _S_word_bit - 1) / _S_word_bit); } + { return _M_impl.allocate((__n + int(_S_word_bit) - 1) + / int(_S_word_bit)); } void _M_deallocate() { if (_M_impl._M_start._M_p) _M_impl.deallocate(_M_impl._M_start._M_p, - _M_impl._M_end_of_storage - _M_impl._M_start._M_p); + _M_impl._M_end_of_storage - _M_impl._M_start._M_p); } }; -} // namespace std + +_GLIBCXX_END_NESTED_NAMESPACE // Declare a partial specialization of vector<T, Alloc>. #include <bits/stl_vector.h> -namespace _GLIBCXX_STD -{ +_GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD) + /** * @brief A specialization of vector for booleans which offers fixed time * access to individual elements in any order. @@ -412,345 +453,223 @@ namespace _GLIBCXX_STD * also provided as with C-style arrays. */ template<typename _Alloc> - class vector<bool, _Alloc> : public _Bvector_base<_Alloc> + class vector<bool, _Alloc> : protected _Bvector_base<_Alloc> { - public: - typedef bool value_type; - typedef size_t size_type; - typedef ptrdiff_t difference_type; - typedef _Bit_reference reference; - typedef bool const_reference; - typedef _Bit_reference* pointer; - typedef const bool* const_pointer; + typedef _Bvector_base<_Alloc> _Base; - typedef _Bit_iterator iterator; - typedef _Bit_const_iterator const_iterator; - - typedef std::reverse_iterator<const_iterator> const_reverse_iterator; - typedef std::reverse_iterator<iterator> reverse_iterator; - - typedef typename _Bvector_base<_Alloc>::allocator_type allocator_type; + public: + typedef bool value_type; + typedef size_t size_type; + typedef ptrdiff_t difference_type; + typedef _Bit_reference reference; + typedef bool const_reference; + typedef _Bit_reference* pointer; + typedef const bool* const_pointer; + typedef _Bit_iterator iterator; + typedef _Bit_const_iterator const_iterator; + typedef std::reverse_iterator<const_iterator> const_reverse_iterator; + typedef std::reverse_iterator<iterator> reverse_iterator; + typedef _Alloc allocator_type; allocator_type get_allocator() const - { return _Bvector_base<_Alloc>::get_allocator(); } + { return _Base::get_allocator(); } protected: - using _Bvector_base<_Alloc>::_M_allocate; - using _Bvector_base<_Alloc>::_M_deallocate; + using _Base::_M_allocate; + using _Base::_M_deallocate; + using _Base::_M_get_Bit_allocator; - protected: - void _M_initialize(size_type __n) + public: + explicit + vector(const allocator_type& __a = allocator_type()) + : _Base(__a) { } + + explicit + vector(size_type __n, const bool& __value = bool(), + const allocator_type& __a = allocator_type()) + : _Base(__a) { - _Bit_type* __q = this->_M_allocate(__n); - this->_M_impl._M_end_of_storage = __q - + (__n + _S_word_bit - 1) / _S_word_bit; - this->_M_impl._M_start = iterator(__q, 0); - this->_M_impl._M_finish = this->_M_impl._M_start + difference_type(__n); + _M_initialize(__n); + std::fill(this->_M_impl._M_start._M_p, this->_M_impl._M_end_of_storage, + __value ? ~0 : 0); } - void _M_insert_aux(iterator __position, bool __x) + vector(const vector& __x) + : _Base(__x._M_get_Bit_allocator()) { - if (this->_M_impl._M_finish._M_p != this->_M_impl._M_end_of_storage) - { - std::copy_backward(__position, this->_M_impl._M_finish, - this->_M_impl._M_finish + 1); - *__position = __x; - ++this->_M_impl._M_finish; - } - else - { - const size_type __len = size() ? 2 * size() - : static_cast<size_type>(_S_word_bit); - _Bit_type * __q = this->_M_allocate(__len); - iterator __i = std::copy(begin(), __position, iterator(__q, 0)); - *__i++ = __x; - this->_M_impl._M_finish = std::copy(__position, end(), __i); - this->_M_deallocate(); - this->_M_impl._M_end_of_storage = __q + (__len + _S_word_bit - 1) - / _S_word_bit; - this->_M_impl._M_start = iterator(__q, 0); - } + _M_initialize(__x.size()); + _M_copy_aligned(__x.begin(), __x.end(), this->_M_impl._M_start); } template<class _InputIterator> - void _M_initialize_range(_InputIterator __first, _InputIterator __last, - input_iterator_tag) - { - this->_M_impl._M_start = iterator(); - this->_M_impl._M_finish = iterator(); - this->_M_impl._M_end_of_storage = 0; - for ( ; __first != __last; ++__first) - push_back(*__first); - } + vector(_InputIterator __first, _InputIterator __last, + const allocator_type& __a = allocator_type()) + : _Base(__a) + { + typedef typename std::__is_integer<_InputIterator>::__type _Integral; + _M_initialize_dispatch(__first, __last, _Integral()); + } - template<class _ForwardIterator> - void _M_initialize_range(_ForwardIterator __first, _ForwardIterator __last, - forward_iterator_tag) - { - const size_type __n = std::distance(__first, __last); - _M_initialize(__n); - std::copy(__first, __last, this->_M_impl._M_start); - } + ~vector() { } - template<class _InputIterator> - void _M_insert_range(iterator __pos, _InputIterator __first, - _InputIterator __last, input_iterator_tag) + vector& + operator=(const vector& __x) { - for ( ; __first != __last; ++__first) + if (&__x == this) + return *this; + if (__x.size() > capacity()) { - __pos = insert(__pos, *__first); - ++__pos; + this->_M_deallocate(); + _M_initialize(__x.size()); } + this->_M_impl._M_finish = _M_copy_aligned(__x.begin(), __x.end(), + begin()); + return *this; } - template<class _ForwardIterator> - void _M_insert_range(iterator __position, _ForwardIterator __first, - _ForwardIterator __last, forward_iterator_tag) - { - if (__first != __last) - { - size_type __n = std::distance(__first, __last); - if (capacity() - size() >= __n) - { - std::copy_backward(__position, end(), - this->_M_impl._M_finish + difference_type(__n)); - std::copy(__first, __last, __position); - this->_M_impl._M_finish += difference_type(__n); - } - else - { - const size_type __len = size() + std::max(size(), __n); - _Bit_type * __q = this->_M_allocate(__len); - iterator __i = std::copy(begin(), __position, iterator(__q, 0)); - __i = std::copy(__first, __last, __i); - this->_M_impl._M_finish = std::copy(__position, end(), __i); - this->_M_deallocate(); - this->_M_impl._M_end_of_storage = __q + (__len + _S_word_bit - 1) - / _S_word_bit; - this->_M_impl._M_start = iterator(__q, 0); - } - } - } + // assign(), a generalized assignment member function. Two + // versions: one that takes a count, and one that takes a range. + // The range version is a member template, so we dispatch on whether + // or not the type is an integer. + void + assign(size_type __n, const bool& __x) + { _M_fill_assign(__n, __x); } - public: - iterator begin() + template<class _InputIterator> + void + assign(_InputIterator __first, _InputIterator __last) + { + typedef typename std::__is_integer<_InputIterator>::__type _Integral; + _M_assign_dispatch(__first, __last, _Integral()); + } + + iterator + begin() { return this->_M_impl._M_start; } - const_iterator begin() const + const_iterator + begin() const { return this->_M_impl._M_start; } - iterator end() + iterator + end() { return this->_M_impl._M_finish; } - const_iterator end() const + const_iterator + end() const { return this->_M_impl._M_finish; } - reverse_iterator rbegin() + reverse_iterator + rbegin() { return reverse_iterator(end()); } - const_reverse_iterator rbegin() const + const_reverse_iterator + rbegin() const { return const_reverse_iterator(end()); } - reverse_iterator rend() + reverse_iterator + rend() { return reverse_iterator(begin()); } - const_reverse_iterator rend() const + const_reverse_iterator + rend() const { return const_reverse_iterator(begin()); } - size_type size() const + size_type + size() const { return size_type(end() - begin()); } - size_type max_size() const - { return size_type(-1); } - - size_type capacity() const - { return size_type(const_iterator(this->_M_impl._M_end_of_storage, 0) - - begin()); } - bool empty() const - { return begin() == end(); } - - reference operator[](size_type __n) - { return *(begin() + difference_type(__n)); } - - const_reference operator[](size_type __n) const - { return *(begin() + difference_type(__n)); } - - void _M_range_check(size_type __n) const - { - if (__n >= this->size()) - __throw_out_of_range(__N("vector<bool>::_M_range_check")); - } - - reference at(size_type __n) - { _M_range_check(__n); return (*this)[__n]; } - - const_reference at(size_type __n) const - { _M_range_check(__n); return (*this)[__n]; } - - explicit vector(const allocator_type& __a = allocator_type()) - : _Bvector_base<_Alloc>(__a) { } - - vector(size_type __n, bool __value, - const allocator_type& __a = allocator_type()) - : _Bvector_base<_Alloc>(__a) - { - _M_initialize(__n); - std::fill(this->_M_impl._M_start._M_p, this->_M_impl._M_end_of_storage, - __value ? ~0 : 0); - } - - explicit vector(size_type __n) - : _Bvector_base<_Alloc>(allocator_type()) + size_type + max_size() const { - _M_initialize(__n); - std::fill(this->_M_impl._M_start._M_p, - this->_M_impl._M_end_of_storage, 0); - } - - vector(const vector& __x) : _Bvector_base<_Alloc>(__x.get_allocator()) - { - _M_initialize(__x.size()); - std::copy(__x.begin(), __x.end(), this->_M_impl._M_start); + const size_type __asize = _M_get_Bit_allocator().max_size(); + return (__asize <= size_type(-1) / int(_S_word_bit) ? + __asize * int(_S_word_bit) : size_type(-1)); } - // Check whether it's an integral type. If so, it's not an iterator. - template<class _Integer> - void _M_initialize_dispatch(_Integer __n, _Integer __x, __true_type) - { - _M_initialize(__n); - std::fill(this->_M_impl._M_start._M_p, - this->_M_impl._M_end_of_storage, __x ? ~0 : 0); - } - - template<class _InputIterator> - void - _M_initialize_dispatch(_InputIterator __first, _InputIterator __last, - __false_type) - { _M_initialize_range(__first, __last, - std::__iterator_category(__first)); } - - template<class _InputIterator> - vector(_InputIterator __first, _InputIterator __last, - const allocator_type& __a = allocator_type()) - : _Bvector_base<_Alloc>(__a) - { - typedef typename _Is_integer<_InputIterator>::_Integral _Integral; - _M_initialize_dispatch(__first, __last, _Integral()); - } + size_type + capacity() const + { return size_type(const_iterator(this->_M_impl._M_end_of_storage, 0) + - begin()); } - ~vector() { } + bool + empty() const + { return begin() == end(); } - vector& operator=(const vector& __x) + reference + operator[](size_type __n) { - if (&__x == this) - return *this; - if (__x.size() > capacity()) - { - this->_M_deallocate(); - _M_initialize(__x.size()); - } - std::copy(__x.begin(), __x.end(), begin()); - this->_M_impl._M_finish = begin() + difference_type(__x.size()); - return *this; + return *iterator(this->_M_impl._M_start._M_p + + __n / int(_S_word_bit), __n % int(_S_word_bit)); } - // assign(), a generalized assignment member function. Two - // versions: one that takes a count, and one that takes a range. - // The range version is a member template, so we dispatch on whether - // or not the type is an integer. - - void _M_fill_assign(size_t __n, bool __x) + const_reference + operator[](size_type __n) const { - if (__n > size()) - { - std::fill(this->_M_impl._M_start._M_p, - this->_M_impl._M_end_of_storage, __x ? ~0 : 0); - insert(end(), __n - size(), __x); - } - else - { - erase(begin() + __n, end()); - std::fill(this->_M_impl._M_start._M_p, - this->_M_impl._M_end_of_storage, __x ? ~0 : 0); - } + return *const_iterator(this->_M_impl._M_start._M_p + + __n / int(_S_word_bit), __n % int(_S_word_bit)); } - void assign(size_t __n, bool __x) - { _M_fill_assign(__n, __x); } - - template<class _InputIterator> - void assign(_InputIterator __first, _InputIterator __last) + protected: + void + _M_range_check(size_type __n) const { - typedef typename _Is_integer<_InputIterator>::_Integral _Integral; - _M_assign_dispatch(__first, __last, _Integral()); + if (__n >= this->size()) + __throw_out_of_range(__N("vector<bool>::_M_range_check")); } - template<class _Integer> - void _M_assign_dispatch(_Integer __n, _Integer __val, __true_type) - { _M_fill_assign((size_t) __n, (bool) __val); } - - template<class _InputIterator> - void _M_assign_dispatch(_InputIterator __first, _InputIterator __last, - __false_type) - { _M_assign_aux(__first, __last, std::__iterator_category(__first)); } - - template<class _InputIterator> - void _M_assign_aux(_InputIterator __first, _InputIterator __last, - input_iterator_tag) - { - iterator __cur = begin(); - for ( ; __first != __last && __cur != end(); ++__cur, ++__first) - *__cur = *__first; - if (__first == __last) - erase(__cur, end()); - else - insert(end(), __first, __last); - } + public: + reference + at(size_type __n) + { _M_range_check(__n); return (*this)[__n]; } - template<class _ForwardIterator> - void _M_assign_aux(_ForwardIterator __first, _ForwardIterator __last, - forward_iterator_tag) - { - const size_type __len = std::distance(__first, __last); - if (__len < size()) - erase(std::copy(__first, __last, begin()), end()); - else - { - _ForwardIterator __mid = __first; - std::advance(__mid, size()); - std::copy(__first, __mid, begin()); - insert(end(), __mid, __last); - } - } + const_reference + at(size_type __n) const + { _M_range_check(__n); return (*this)[__n]; } - void reserve(size_type __n) + void + reserve(size_type __n) { if (__n > this->max_size()) __throw_length_error(__N("vector::reserve")); if (this->capacity() < __n) { _Bit_type* __q = this->_M_allocate(__n); - this->_M_impl._M_finish = std::copy(begin(), end(), - iterator(__q, 0)); + this->_M_impl._M_finish = _M_copy_aligned(begin(), end(), + iterator(__q, 0)); this->_M_deallocate(); this->_M_impl._M_start = iterator(__q, 0); - this->_M_impl._M_end_of_storage = __q + (__n + _S_word_bit - 1) / _S_word_bit; + this->_M_impl._M_end_of_storage = (__q + (__n + int(_S_word_bit) - 1) + / int(_S_word_bit)); } } - reference front() + reference + front() { return *begin(); } - const_reference front() const + const_reference + front() const { return *begin(); } - reference back() + reference + back() { return *(end() - 1); } - const_reference back() const + const_reference + back() const { return *(end() - 1); } - void push_back(bool __x) + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // DR 464. Suggestion for new member functions in standard containers. + // N.B. DR 464 says nothing about vector<bool> but we need something + // here due to the way we are implementing DR 464 in the debug-mode + // vector class. + void + data() { } + + void + push_back(bool __x) { if (this->_M_impl._M_finish._M_p != this->_M_impl._M_end_of_storage) *this->_M_impl._M_finish++ = __x; @@ -758,23 +677,31 @@ template<typename _Alloc> _M_insert_aux(end(), __x); } - void swap(vector<bool, _Alloc>& __x) + void + swap(vector<bool, _Alloc>& __x) { std::swap(this->_M_impl._M_start, __x._M_impl._M_start); std::swap(this->_M_impl._M_finish, __x._M_impl._M_finish); std::swap(this->_M_impl._M_end_of_storage, __x._M_impl._M_end_of_storage); + + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 431. Swapping containers with unequal allocators. + std::__alloc_swap<typename _Base::_Bit_alloc_type>:: + _S_do_it(_M_get_Bit_allocator(), __x._M_get_Bit_allocator()); } // [23.2.5]/1, third-to-last entry in synopsis listing - static void swap(reference __x, reference __y) + static void + swap(reference __x, reference __y) { bool __tmp = __x; __x = __y; __y = __tmp; } - iterator insert(iterator __position, bool __x = bool()) + iterator + insert(iterator __position, const bool& __x = bool()) { const difference_type __n = __position - begin(); if (this->_M_impl._M_finish._M_p != this->_M_impl._M_end_of_storage @@ -785,29 +712,195 @@ template<typename _Alloc> return begin() + __n; } - // Check whether it's an integral type. If so, it's not an iterator. + template<class _InputIterator> + void + insert(iterator __position, + _InputIterator __first, _InputIterator __last) + { + typedef typename std::__is_integer<_InputIterator>::__type _Integral; + _M_insert_dispatch(__position, __first, __last, _Integral()); + } + void + insert(iterator __position, size_type __n, const bool& __x) + { _M_fill_insert(__position, __n, __x); } + + void + pop_back() + { --this->_M_impl._M_finish; } + + iterator + erase(iterator __position) + { + if (__position + 1 != end()) + std::copy(__position + 1, end(), __position); + --this->_M_impl._M_finish; + return __position; + } + + iterator + erase(iterator __first, iterator __last) + { + _M_erase_at_end(std::copy(__last, end(), __first)); + return __first; + } + + void + resize(size_type __new_size, bool __x = bool()) + { + if (__new_size < size()) + _M_erase_at_end(begin() + difference_type(__new_size)); + else + insert(end(), __new_size - size(), __x); + } + + void + flip() + { + for (_Bit_type * __p = this->_M_impl._M_start._M_p; + __p != this->_M_impl._M_end_of_storage; ++__p) + *__p = ~*__p; + } + + void + clear() + { _M_erase_at_end(begin()); } + + + protected: + // Precondition: __first._M_offset == 0 && __result._M_offset == 0. + iterator + _M_copy_aligned(const_iterator __first, const_iterator __last, + iterator __result) + { + _Bit_type* __q = std::copy(__first._M_p, __last._M_p, __result._M_p); + return std::copy(const_iterator(__last._M_p, 0), __last, + iterator(__q, 0)); + } + + void + _M_initialize(size_type __n) + { + _Bit_type* __q = this->_M_allocate(__n); + this->_M_impl._M_end_of_storage = (__q + + ((__n + int(_S_word_bit) - 1) + / int(_S_word_bit))); + this->_M_impl._M_start = iterator(__q, 0); + this->_M_impl._M_finish = this->_M_impl._M_start + difference_type(__n); + } + + // Check whether it's an integral type. If so, it's not an iterator. template<class _Integer> - void _M_insert_dispatch(iterator __pos, _Integer __n, _Integer __x, - __true_type) - { _M_fill_insert(__pos, __n, __x); } + void + _M_initialize_dispatch(_Integer __n, _Integer __x, __true_type) + { + _M_initialize(__n); + std::fill(this->_M_impl._M_start._M_p, + this->_M_impl._M_end_of_storage, __x ? ~0 : 0); + } template<class _InputIterator> - void _M_insert_dispatch(iterator __pos, - _InputIterator __first, _InputIterator __last, - __false_type) - { _M_insert_range(__pos, __first, __last, - std::__iterator_category(__first)); } + void + _M_initialize_dispatch(_InputIterator __first, _InputIterator __last, + __false_type) + { _M_initialize_range(__first, __last, + std::__iterator_category(__first)); } template<class _InputIterator> - void insert(iterator __position, - _InputIterator __first, _InputIterator __last) + void + _M_initialize_range(_InputIterator __first, _InputIterator __last, + std::input_iterator_tag) + { + for (; __first != __last; ++__first) + push_back(*__first); + } + + template<class _ForwardIterator> + void + _M_initialize_range(_ForwardIterator __first, _ForwardIterator __last, + std::forward_iterator_tag) + { + const size_type __n = std::distance(__first, __last); + _M_initialize(__n); + std::copy(__first, __last, this->_M_impl._M_start); + } + + template<class _Integer> + void + _M_assign_dispatch(_Integer __n, _Integer __val, __true_type) + { _M_fill_assign((size_t) __n, (bool) __val); } + + template<class _InputIterator> + void + _M_assign_dispatch(_InputIterator __first, _InputIterator __last, + __false_type) + { _M_assign_aux(__first, __last, std::__iterator_category(__first)); } + + void + _M_fill_assign(size_t __n, bool __x) { - typedef typename _Is_integer<_InputIterator>::_Integral _Integral; - _M_insert_dispatch(__position, __first, __last, _Integral()); + if (__n > size()) + { + std::fill(this->_M_impl._M_start._M_p, + this->_M_impl._M_end_of_storage, __x ? ~0 : 0); + insert(end(), __n - size(), __x); + } + else + { + _M_erase_at_end(begin() + __n); + std::fill(this->_M_impl._M_start._M_p, + this->_M_impl._M_end_of_storage, __x ? ~0 : 0); + } } - void _M_fill_insert(iterator __position, size_type __n, bool __x) + template<class _InputIterator> + void + _M_assign_aux(_InputIterator __first, _InputIterator __last, + std::input_iterator_tag) + { + iterator __cur = begin(); + for (; __first != __last && __cur != end(); ++__cur, ++__first) + *__cur = *__first; + if (__first == __last) + _M_erase_at_end(__cur); + else + insert(end(), __first, __last); + } + + template<class _ForwardIterator> + void + _M_assign_aux(_ForwardIterator __first, _ForwardIterator __last, + std::forward_iterator_tag) + { + const size_type __len = std::distance(__first, __last); + if (__len < size()) + _M_erase_at_end(std::copy(__first, __last, begin())); + else + { + _ForwardIterator __mid = __first; + std::advance(__mid, size()); + std::copy(__first, __mid, begin()); + insert(end(), __mid, __last); + } + } + + // Check whether it's an integral type. If so, it's not an iterator. + template<class _Integer> + void + _M_insert_dispatch(iterator __pos, _Integer __n, _Integer __x, + __true_type) + { _M_fill_insert(__pos, __n, __x); } + + template<class _InputIterator> + void + _M_insert_dispatch(iterator __pos, + _InputIterator __first, _InputIterator __last, + __false_type) + { _M_insert_range(__pos, __first, __last, + std::__iterator_category(__first)); } + + void + _M_fill_insert(iterator __position, size_type __n, bool __x) { if (__n == 0) return; @@ -822,55 +915,97 @@ template<typename _Alloc> { const size_type __len = size() + std::max(size(), __n); _Bit_type * __q = this->_M_allocate(__len); - iterator __i = std::copy(begin(), __position, iterator(__q, 0)); - std::fill_n(__i, __n, __x); + iterator __i = _M_copy_aligned(begin(), __position, + iterator(__q, 0)); + std::fill(__i, __i + difference_type(__n), __x); this->_M_impl._M_finish = std::copy(__position, end(), __i + difference_type(__n)); this->_M_deallocate(); - this->_M_impl._M_end_of_storage = __q + (__len + _S_word_bit - 1) - / _S_word_bit; + this->_M_impl._M_end_of_storage = (__q + ((__len + + int(_S_word_bit) - 1) + / int(_S_word_bit))); this->_M_impl._M_start = iterator(__q, 0); } } - void insert(iterator __position, size_type __n, bool __x) - { _M_fill_insert(__position, __n, __x); } - - void pop_back() - { --this->_M_impl._M_finish; } - - iterator erase(iterator __position) - { - if (__position + 1 != end()) - std::copy(__position + 1, end(), __position); - --this->_M_impl._M_finish; - return __position; - } + template<class _InputIterator> + void + _M_insert_range(iterator __pos, _InputIterator __first, + _InputIterator __last, std::input_iterator_tag) + { + for (; __first != __last; ++__first) + { + __pos = insert(__pos, *__first); + ++__pos; + } + } - iterator erase(iterator __first, iterator __last) - { - this->_M_impl._M_finish = std::copy(__last, end(), __first); - return __first; - } + template<class _ForwardIterator> + void + _M_insert_range(iterator __position, _ForwardIterator __first, + _ForwardIterator __last, std::forward_iterator_tag) + { + if (__first != __last) + { + size_type __n = std::distance(__first, __last); + if (capacity() - size() >= __n) + { + std::copy_backward(__position, end(), + this->_M_impl._M_finish + + difference_type(__n)); + std::copy(__first, __last, __position); + this->_M_impl._M_finish += difference_type(__n); + } + else + { + const size_type __len = size() + std::max(size(), __n); + _Bit_type * __q = this->_M_allocate(__len); + iterator __i = _M_copy_aligned(begin(), __position, + iterator(__q, 0)); + __i = std::copy(__first, __last, __i); + this->_M_impl._M_finish = std::copy(__position, end(), __i); + this->_M_deallocate(); + this->_M_impl._M_end_of_storage = (__q + + ((__len + + int(_S_word_bit) - 1) + / int(_S_word_bit))); + this->_M_impl._M_start = iterator(__q, 0); + } + } + } - void resize(size_type __new_size, bool __x = bool()) + void + _M_insert_aux(iterator __position, bool __x) { - if (__new_size < size()) - erase(begin() + difference_type(__new_size), end()); + if (this->_M_impl._M_finish._M_p != this->_M_impl._M_end_of_storage) + { + std::copy_backward(__position, this->_M_impl._M_finish, + this->_M_impl._M_finish + 1); + *__position = __x; + ++this->_M_impl._M_finish; + } else - insert(end(), __new_size - size(), __x); - } - - void flip() - { - for (_Bit_type * __p = this->_M_impl._M_start._M_p; - __p != this->_M_impl._M_end_of_storage; ++__p) - *__p = ~*__p; + { + const size_type __len = size() ? 2 * size() + : static_cast<size_type>(_S_word_bit); + _Bit_type * __q = this->_M_allocate(__len); + iterator __i = _M_copy_aligned(begin(), __position, + iterator(__q, 0)); + *__i++ = __x; + this->_M_impl._M_finish = std::copy(__position, end(), __i); + this->_M_deallocate(); + this->_M_impl._M_end_of_storage = (__q + ((__len + + int(_S_word_bit) - 1) + / int(_S_word_bit))); + this->_M_impl._M_start = iterator(__q, 0); + } } - void clear() - { erase(begin(), end()); } + void + _M_erase_at_end(iterator __pos) + { this->_M_impl._M_finish = __pos; } }; -} // namespace std + +_GLIBCXX_END_NESTED_NAMESPACE #endif diff --git a/contrib/libstdc++/include/bits/stl_construct.h b/contrib/libstdc++/include/bits/stl_construct.h index afb3387..0a03fb7 100644 --- a/contrib/libstdc++/include/bits/stl_construct.h +++ b/contrib/libstdc++/include/bits/stl_construct.h @@ -1,6 +1,6 @@ // nonstandard construct and destroy functions -*- C++ -*- -// Copyright (C) 2001, 2002, 2003, 2004 Free Software Foundation, Inc. +// Copyright (C) 2001, 2002, 2003, 2004, 2005 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 @@ -15,7 +15,7 @@ // 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// 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 @@ -61,11 +61,11 @@ #ifndef _STL_CONSTRUCT_H #define _STL_CONSTRUCT_H 1 -#include <bits/type_traits.h> +#include <bits/cpp_type_traits.h> #include <new> -namespace std -{ +_GLIBCXX_BEGIN_NAMESPACE(std) + /** * @if maint * Constructs an object in existing memory by invoking an allocated @@ -117,7 +117,10 @@ namespace std inline void __destroy_aux(_ForwardIterator __first, _ForwardIterator __last, __false_type) - { for ( ; __first != __last; ++__first) std::_Destroy(&*__first); } + { + for (; __first != __last; ++__first) + std::_Destroy(&*__first); + } /** * @if maint @@ -146,12 +149,40 @@ namespace std { typedef typename iterator_traits<_ForwardIterator>::value_type _Value_type; - typedef typename __type_traits<_Value_type>::has_trivial_destructor - _Has_trivial_destructor; + typedef typename std::__is_scalar<_Value_type>::__type + _Has_trivial_destructor; std::__destroy_aux(__first, __last, _Has_trivial_destructor()); } -} // namespace std + + /** + * @if maint + * Destroy a range of objects using the supplied allocator. For + * nondefault allocators we do not optimize away invocation of + * destroy() even if _Tp has a trivial destructor. + * @endif + */ + + template <typename _Tp> class allocator; + + template<typename _ForwardIterator, typename _Allocator> + void + _Destroy(_ForwardIterator __first, _ForwardIterator __last, + _Allocator __alloc) + { + for (; __first != __last; ++__first) + __alloc.destroy(&*__first); + } + + template<typename _ForwardIterator, typename _Tp> + inline void + _Destroy(_ForwardIterator __first, _ForwardIterator __last, + allocator<_Tp>) + { + _Destroy(__first, __last); + } + +_GLIBCXX_END_NAMESPACE #endif /* _STL_CONSTRUCT_H */ diff --git a/contrib/libstdc++/include/bits/stl_deque.h b/contrib/libstdc++/include/bits/stl_deque.h index 54dadf2..9da0bb7 100644 --- a/contrib/libstdc++/include/bits/stl_deque.h +++ b/contrib/libstdc++/include/bits/stl_deque.h @@ -1,6 +1,7 @@ // Deque implementation -*- C++ -*- -// Copyright (C) 2001, 2002, 2003, 2004 Free Software Foundation, Inc. +// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 +// 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 @@ -15,7 +16,7 @@ // 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// 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 @@ -65,8 +66,8 @@ #include <bits/stl_iterator_base_types.h> #include <bits/stl_iterator_base_funcs.h> -namespace _GLIBCXX_STD -{ +_GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD) + /** * @if maint * @brief This function controls the size of memory nodes. @@ -87,10 +88,11 @@ namespace _GLIBCXX_STD /** * @brief A deque::iterator. * - * Quite a bit of intelligence here. Much of the functionality of deque is - * actually passed off to this class. A deque holds two of these internally, - * marking its valid range. Access to elements is done as offsets of either - * of those two, relying on operator overloading in this class. + * Quite a bit of intelligence here. Much of the functionality of + * deque is actually passed off to this class. A deque holds two + * of these internally, marking its valid range. Access to + * elements is done as offsets of either of those two, relying on + * operator overloading in this class. * * @if maint * All the functions are op overloads except for _M_set_node. @@ -105,14 +107,14 @@ namespace _GLIBCXX_STD static size_t _S_buffer_size() { return __deque_buf_size(sizeof(_Tp)); } - typedef random_access_iterator_tag iterator_category; - typedef _Tp value_type; - typedef _Ptr pointer; - typedef _Ref reference; - typedef size_t size_type; - typedef ptrdiff_t difference_type; - typedef _Tp** _Map_pointer; - typedef _Deque_iterator _Self; + typedef std::random_access_iterator_tag iterator_category; + typedef _Tp value_type; + typedef _Ptr pointer; + typedef _Ref reference; + typedef size_t size_type; + typedef ptrdiff_t difference_type; + typedef _Tp** _Map_pointer; + typedef _Deque_iterator _Self; _Tp* _M_cur; _Tp* _M_first; @@ -219,9 +221,9 @@ namespace _GLIBCXX_STD { return *(*this + __n); } /** @if maint - * Prepares to traverse new_node. Sets everything except _M_cur, which - * should therefore be set by the caller immediately afterwards, based on - * _M_first and _M_last. + * Prepares to traverse new_node. Sets everything except + * _M_cur, which should therefore be set by the caller + * immediately afterwards, based on _M_first and _M_last. * @endif */ void @@ -320,6 +322,17 @@ namespace _GLIBCXX_STD // According to the resolution of DR179 not only the various comparison // operators but also operator- must accept mixed iterator/const_iterator // parameters. + template<typename _Tp, typename _Ref, typename _Ptr> + inline typename _Deque_iterator<_Tp, _Ref, _Ptr>::difference_type + operator-(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x, + const _Deque_iterator<_Tp, _Ref, _Ptr>& __y) + { + return typename _Deque_iterator<_Tp, _Ref, _Ptr>::difference_type + (_Deque_iterator<_Tp, _Ref, _Ptr>::_S_buffer_size()) + * (__x._M_node - __y._M_node - 1) + (__x._M_cur - __x._M_first) + + (__y._M_last - __y._M_cur); + } + template<typename _Tp, typename _RefL, typename _PtrL, typename _RefR, typename _PtrR> inline typename _Deque_iterator<_Tp, _RefL, _PtrL>::difference_type @@ -337,6 +350,11 @@ namespace _GLIBCXX_STD operator+(ptrdiff_t __n, const _Deque_iterator<_Tp, _Ref, _Ptr>& __x) { return __x + __n; } + template<typename _Tp> + void + fill(const _Deque_iterator<_Tp, _Tp&, _Tp*>& __first, + const _Deque_iterator<_Tp, _Tp&, _Tp*>& __last, const _Tp& __value); + /** * @if maint * Deque base class. This class provides the unified face for %deque's @@ -357,17 +375,17 @@ namespace _GLIBCXX_STD allocator_type get_allocator() const - { return *static_cast<const _Alloc*>(&this->_M_impl); } + { return allocator_type(_M_get_Tp_allocator()); } - typedef _Deque_iterator<_Tp,_Tp&,_Tp*> iterator; - typedef _Deque_iterator<_Tp,const _Tp&,const _Tp*> const_iterator; + typedef _Deque_iterator<_Tp, _Tp&, _Tp*> iterator; + typedef _Deque_iterator<_Tp, const _Tp&, const _Tp*> const_iterator; _Deque_base(const allocator_type& __a, size_t __num_elements) - : _M_impl(__a) + : _M_impl(__a) { _M_initialize_map(__num_elements); } _Deque_base(const allocator_type& __a) - : _M_impl(__a) + : _M_impl(__a) { } ~_Deque_base(); @@ -376,29 +394,47 @@ namespace _GLIBCXX_STD //This struct encapsulates the implementation of the std::deque //standard container and at the same time makes use of the EBO //for empty allocators. + typedef typename _Alloc::template rebind<_Tp*>::other _Map_alloc_type; + + typedef typename _Alloc::template rebind<_Tp>::other _Tp_alloc_type; + struct _Deque_impl - : public _Alloc { + : public _Tp_alloc_type + { _Tp** _M_map; size_t _M_map_size; iterator _M_start; iterator _M_finish; - _Deque_impl(const _Alloc& __a) - : _Alloc(__a), _M_map(0), _M_map_size(0), _M_start(), _M_finish() + _Deque_impl(const _Tp_alloc_type& __a) + : _Tp_alloc_type(__a), _M_map(0), _M_map_size(0), + _M_start(), _M_finish() { } }; - 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()); } + _Tp_alloc_type& + _M_get_Tp_allocator() + { return *static_cast<_Tp_alloc_type*>(&this->_M_impl); } + + const _Tp_alloc_type& + _M_get_Tp_allocator() const + { return *static_cast<const _Tp_alloc_type*>(&this->_M_impl); } + + _Map_alloc_type + _M_get_map_allocator() const + { return _Map_alloc_type(_M_get_Tp_allocator()); } _Tp* _M_allocate_node() - { return _M_impl._Alloc::allocate(__deque_buf_size(sizeof(_Tp))); } + { + return _M_impl._Tp_alloc_type::allocate(__deque_buf_size(sizeof(_Tp))); + } void _M_deallocate_node(_Tp* __p) - { _M_impl._Alloc::deallocate(__p, __deque_buf_size(sizeof(_Tp))); } + { + _M_impl._Tp_alloc_type::deallocate(__p, __deque_buf_size(sizeof(_Tp))); + } _Tp** _M_allocate_map(size_t __n) @@ -418,14 +454,16 @@ namespace _GLIBCXX_STD }; template<typename _Tp, typename _Alloc> - _Deque_base<_Tp,_Alloc>::~_Deque_base() - { - if (this->_M_impl._M_map) + _Deque_base<_Tp, _Alloc>:: + ~_Deque_base() { - _M_destroy_nodes(this->_M_impl._M_start._M_node, this->_M_impl._M_finish._M_node + 1); - _M_deallocate_map(this->_M_impl._M_map, this->_M_impl._M_map_size); + if (this->_M_impl._M_map) + { + _M_destroy_nodes(this->_M_impl._M_start._M_node, + this->_M_impl._M_finish._M_node + 1); + _M_deallocate_map(this->_M_impl._M_map, this->_M_impl._M_map_size); + } } - } /** * @if maint @@ -439,12 +477,14 @@ namespace _GLIBCXX_STD */ template<typename _Tp, typename _Alloc> 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 = __num_elements / __deque_buf_size(sizeof(_Tp)) + 1; + const size_t __num_nodes = (__num_elements/ __deque_buf_size(sizeof(_Tp)) + + 1); this->_M_impl._M_map_size = std::max((size_t) _S_initial_map_size, - __num_nodes + 2); + size_t(__num_nodes + 2)); this->_M_impl._M_map = _M_allocate_map(this->_M_impl._M_map_size); // For "small" maps (needing less than _M_map_size nodes), allocation @@ -452,7 +492,8 @@ namespace _GLIBCXX_STD // the beginning of _M_map, but for small maps it may be as far in as // _M_map+3. - _Tp** __nstart = this->_M_impl._M_map + (this->_M_impl._M_map_size - __num_nodes) / 2; + _Tp** __nstart = (this->_M_impl._M_map + + (this->_M_impl._M_map_size - __num_nodes) / 2); _Tp** __nfinish = __nstart + __num_nodes; try @@ -468,13 +509,15 @@ namespace _GLIBCXX_STD this->_M_impl._M_start._M_set_node(__nstart); this->_M_impl._M_finish._M_set_node(__nfinish - 1); this->_M_impl._M_start._M_cur = _M_impl._M_start._M_first; - this->_M_impl._M_finish._M_cur = this->_M_impl._M_finish._M_first + __num_elements - % __deque_buf_size(sizeof(_Tp)); + this->_M_impl._M_finish._M_cur = (this->_M_impl._M_finish._M_first + + __num_elements + % __deque_buf_size(sizeof(_Tp))); } template<typename _Tp, typename _Alloc> void - _Deque_base<_Tp,_Alloc>::_M_create_nodes(_Tp** __nstart, _Tp** __nfinish) + _Deque_base<_Tp, _Alloc>:: + _M_create_nodes(_Tp** __nstart, _Tp** __nfinish) { _Tp** __cur; try @@ -491,7 +534,8 @@ namespace _GLIBCXX_STD template<typename _Tp, typename _Alloc> 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) _M_deallocate_node(*__n); @@ -521,28 +565,27 @@ namespace _GLIBCXX_STD * - size_t _M_map_size * - iterator _M_start, _M_finish * - * map_size is at least 8. %map is an array of map_size pointers-to-"nodes". - * (The name %map has nothing to do with the std::map class, and "nodes" - * should not be confused with std::list's usage of "node".) - * - * A "node" has no specific type name as such, but it is referred to as - * "node" in this file. It is a simple array-of-Tp. If Tp is very large, - * there will be one Tp element per node (i.e., an "array" of one). - * For non-huge Tp's, node size is inversely related to Tp size: the - * larger the Tp, the fewer Tp's will fit in a node. The goal here is to - * keep the total size of a node relatively small and constant over different - * Tp's, to improve allocator efficiency. + * map_size is at least 8. %map is an array of map_size + * pointers-to-"nodes". (The name %map has nothing to do with the + * std::map class, and "nodes" should not be confused with + * std::list's usage of "node".) * - * **** As I write this, the nodes are /not/ allocated using the high-speed - * memory pool. There are 20 hours left in the year; perhaps I can fix - * this before 2002. + * A "node" has no specific type name as such, but it is referred + * to as "node" in this file. It is a simple array-of-Tp. If Tp + * is very large, there will be one Tp element per node (i.e., an + * "array" of one). For non-huge Tp's, node size is inversely + * related to Tp size: the larger the Tp, the fewer Tp's will fit + * in a node. The goal here is to keep the total size of a node + * relatively small and constant over different Tp's, to improve + * allocator efficiency. * - * Not every pointer in the %map array will point to a node. If the initial - * number of elements in the deque is small, the /middle/ %map pointers will - * be valid, and the ones at the edges will be unused. This same situation - * will arise as the %map grows: available %map pointers, if any, will be on - * the ends. As new nodes are created, only a subset of the %map's pointers - * need to be copied "outward". + * Not every pointer in the %map array will point to a node. If + * the initial number of elements in the deque is small, the + * /middle/ %map pointers will be valid, and the ones at the edges + * will be unused. This same situation will arise as the %map + * grows: available %map pointers, if any, will be on the ends. As + * new nodes are created, only a subset of the %map's pointers need + * to be copied "outward". * * Class invariants: * - For any nonsingular iterator i: @@ -554,16 +597,17 @@ namespace _GLIBCXX_STD * - i.cur is a pointer in the range [i.first, i.last). NOTE: * the implication of this is that i.cur is always a dereferenceable * pointer, even if i is a past-the-end iterator. - * - Start and Finish are always nonsingular iterators. NOTE: this means that - * an empty deque must have one node, a deque with <N elements (where N is - * the node buffer size) must have one node, a deque with N through (2N-1) - * elements must have two nodes, etc. - * - For every node other than start.node and finish.node, every element in - * the node is an initialized object. If start.node == finish.node, then - * [start.cur, finish.cur) are initialized objects, and the elements outside - * that range are uninitialized storage. Otherwise, [start.cur, start.last) - * and [finish.first, finish.cur) are initialized objects, and [start.first, - * start.cur) and [finish.cur, finish.last) are uninitialized storage. + * - Start and Finish are always nonsingular iterators. NOTE: this + * means that an empty deque must have one node, a deque with <N + * elements (where N is the node buffer size) must have one node, a + * deque with N through (2N-1) elements must have two nodes, etc. + * - For every node other than start.node and finish.node, every + * element in the node is an initialized object. If start.node == + * finish.node, then [start.cur, finish.cur) are initialized + * objects, and the elements outside that range are uninitialized + * storage. Otherwise, [start.cur, start.last) and [finish.first, + * finish.cur) are initialized objects, and [start.first, start.cur) + * and [finish.cur, finish.last) are uninitialized storage. * - [%map, %map + map_size) is a valid, non-empty range. * - [start.node, finish.node] is a valid range contained within * [%map, %map + map_size). @@ -581,27 +625,30 @@ namespace _GLIBCXX_STD * and we can use other standard algorithms as well. * @endif */ - template<typename _Tp, typename _Alloc = allocator<_Tp> > + template<typename _Tp, typename _Alloc = std::allocator<_Tp> > class deque : protected _Deque_base<_Tp, _Alloc> { // concept requirements + typedef typename _Alloc::value_type _Alloc_value_type; __glibcxx_class_requires(_Tp, _SGIAssignableConcept) + __glibcxx_class_requires2(_Tp, _Alloc_value_type, _SameTypeConcept) typedef _Deque_base<_Tp, _Alloc> _Base; + typedef typename _Base::_Tp_alloc_type _Tp_alloc_type; public: - typedef _Tp value_type; - typedef typename _Alloc::pointer pointer; - typedef typename _Alloc::const_pointer const_pointer; - typedef typename _Alloc::reference reference; - typedef typename _Alloc::const_reference const_reference; - typedef typename _Base::iterator iterator; - typedef typename _Base::const_iterator const_iterator; - typedef std::reverse_iterator<const_iterator> const_reverse_iterator; - typedef std::reverse_iterator<iterator> reverse_iterator; + typedef _Tp value_type; + typedef typename _Tp_alloc_type::pointer pointer; + typedef typename _Tp_alloc_type::const_pointer const_pointer; + typedef typename _Tp_alloc_type::reference reference; + typedef typename _Tp_alloc_type::const_reference const_reference; + typedef typename _Base::iterator iterator; + typedef typename _Base::const_iterator const_iterator; + typedef std::reverse_iterator<const_iterator> const_reverse_iterator; + typedef std::reverse_iterator<iterator> reverse_iterator; typedef size_t size_type; typedef ptrdiff_t difference_type; - typedef typename _Base::allocator_type allocator_type; + typedef _Alloc allocator_type; protected: typedef pointer* _Map_pointer; @@ -617,6 +664,7 @@ namespace _GLIBCXX_STD using _Base::_M_deallocate_node; using _Base::_M_allocate_map; using _Base::_M_deallocate_map; + using _Base::_M_get_Tp_allocator; /** @if maint * A total of four data members accumulated down the heirarchy. @@ -642,24 +690,13 @@ namespace _GLIBCXX_STD * * This constructor fills the %deque with @a n copies of @a value. */ - deque(size_type __n, const value_type& __value, + explicit + deque(size_type __n, const value_type& __value = value_type(), const allocator_type& __a = allocator_type()) : _Base(__a, __n) { _M_fill_initialize(__value); } /** - * @brief Create a %deque with default elements. - * @param n The number of elements to initially create. - * - * This constructor fills the %deque with @a n copies of a - * default-constructed element. - */ - explicit - deque(size_type __n) - : _Base(allocator_type(), __n) - { _M_fill_initialize(value_type()); } - - /** * @brief %Deque copy constructor. * @param x A %deque of identical element and allocator types. * @@ -667,8 +704,10 @@ namespace _GLIBCXX_STD * by @a x. */ deque(const deque& __x) - : _Base(__x.get_allocator(), __x.size()) - { std::uninitialized_copy(__x.begin(), __x.end(), this->_M_impl._M_start); } + : _Base(__x._M_get_Tp_allocator(), __x.size()) + { std::__uninitialized_copy_a(__x.begin(), __x.end(), + this->_M_impl._M_start, + _M_get_Tp_allocator()); } /** * @brief Builds a %deque from a range. @@ -690,7 +729,7 @@ namespace _GLIBCXX_STD : _Base(__a) { // Check whether it's an integral type. If so, it's not an iterator. - typedef typename _Is_integer<_InputIterator>::_Integral _Integral; + typedef typename std::__is_integer<_InputIterator>::__type _Integral; _M_initialize_dispatch(__first, __last, _Integral()); } @@ -700,7 +739,7 @@ namespace _GLIBCXX_STD * way. Managing the pointer is the user's responsibilty. */ ~deque() - { std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish); } + { _M_destroy_data(begin(), end(), _M_get_Tp_allocator()); } /** * @brief %Deque assignment operator. @@ -717,10 +756,10 @@ namespace _GLIBCXX_STD * @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. + * 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) @@ -742,7 +781,7 @@ namespace _GLIBCXX_STD void assign(_InputIterator __first, _InputIterator __last) { - typedef typename _Is_integer<_InputIterator>::_Integral _Integral; + typedef typename std::__is_integer<_InputIterator>::__type _Integral; _M_assign_dispatch(__first, __last, _Integral()); } @@ -769,50 +808,54 @@ namespace _GLIBCXX_STD { return this->_M_impl._M_start; } /** - * Returns a read/write iterator that points one past the last element in - * the %deque. Iteration is done in ordinary element order. + * 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_impl._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. + * 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_impl._M_finish; } /** - * Returns a read/write reverse iterator that points to the last element - * in the %deque. Iteration is done in reverse element order. + * 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_impl._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. + * 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_impl._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. + * 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_impl._M_start); } + rend() + { return reverse_iterator(this->_M_impl._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. + * 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 @@ -827,43 +870,32 @@ namespace _GLIBCXX_STD /** Returns the size() of the largest possible %deque. */ size_type max_size() const - { return size_type(-1); } + { return _M_get_Tp_allocator().max_size(); } /** * @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. + * 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) + resize(size_type __new_size, value_type __x = value_type()) { const size_type __len = size(); if (__new_size < __len) - erase(this->_M_impl._M_start + __new_size, this->_M_impl._M_finish); + _M_erase_at_end(this->_M_impl._M_start + difference_type(__new_size)); else insert(this->_M_impl._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().) + * Returns true if the %deque is empty. (Thus begin() would + * equal end().) */ bool empty() const @@ -871,26 +903,30 @@ namespace _GLIBCXX_STD // 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. + * @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().) + * 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_impl._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. + * @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().) + * 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 @@ -908,21 +944,26 @@ namespace _GLIBCXX_STD public: /** * @brief Provides access to the data contained in the %deque. - * @param n The index of the element for which data should be accessed. + * @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. + * 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]; } + { + _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. + * @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. * @@ -938,12 +979,12 @@ namespace _GLIBCXX_STD } /** - * Returns a read/write reference to the data at the first element of the - * %deque. + * Returns a read/write reference to the data at the first + * element of the %deque. */ reference front() - { return *this->_M_impl._M_start; } + { return *begin(); } /** * Returns a read-only (constant) reference to the data at the first @@ -951,7 +992,7 @@ namespace _GLIBCXX_STD */ const_reference front() const - { return *this->_M_impl._M_start; } + { return *begin(); } /** * Returns a read/write reference to the data at the last element of the @@ -960,7 +1001,7 @@ namespace _GLIBCXX_STD reference back() { - iterator __tmp = this->_M_impl._M_finish; + iterator __tmp = end(); --__tmp; return *__tmp; } @@ -972,7 +1013,7 @@ namespace _GLIBCXX_STD const_reference back() const { - const_iterator __tmp = this->_M_impl._M_finish; + const_iterator __tmp = end(); --__tmp; return *__tmp; } @@ -982,16 +1023,17 @@ namespace _GLIBCXX_STD * @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. + * 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_impl._M_start._M_cur != this->_M_impl._M_start._M_first) { - std::_Construct(this->_M_impl._M_start._M_cur - 1, __x); + this->_M_impl.construct(this->_M_impl._M_start._M_cur - 1, __x); --this->_M_impl._M_start._M_cur; } else @@ -1002,16 +1044,18 @@ namespace _GLIBCXX_STD * @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. + * 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_impl._M_finish._M_cur != this->_M_impl._M_finish._M_last - 1) + if (this->_M_impl._M_finish._M_cur + != this->_M_impl._M_finish._M_last - 1) { - std::_Construct(this->_M_impl._M_finish._M_cur, __x); + this->_M_impl.construct(this->_M_impl._M_finish._M_cur, __x); ++this->_M_impl._M_finish._M_cur; } else @@ -1029,9 +1073,10 @@ namespace _GLIBCXX_STD void pop_front() { - if (this->_M_impl._M_start._M_cur != this->_M_impl._M_start._M_last - 1) + if (this->_M_impl._M_start._M_cur + != this->_M_impl._M_start._M_last - 1) { - std::_Destroy(this->_M_impl._M_start._M_cur); + this->_M_impl.destroy(this->_M_impl._M_start._M_cur); ++this->_M_impl._M_start._M_cur; } else @@ -1049,10 +1094,11 @@ namespace _GLIBCXX_STD void pop_back() { - if (this->_M_impl._M_finish._M_cur != this->_M_impl._M_finish._M_first) + if (this->_M_impl._M_finish._M_cur + != this->_M_impl._M_finish._M_first) { --this->_M_impl._M_finish._M_cur; - std::_Destroy(this->_M_impl._M_finish._M_cur); + this->_M_impl.destroy(this->_M_impl._M_finish._M_cur); } else _M_pop_back_aux(); @@ -1068,7 +1114,7 @@ namespace _GLIBCXX_STD * specified location. */ iterator - insert(iterator position, const value_type& __x); + insert(iterator __position, const value_type& __x); /** * @brief Inserts a number of copies of given data into the %deque. @@ -1089,9 +1135,9 @@ namespace _GLIBCXX_STD * @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." + * 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 @@ -1099,7 +1145,7 @@ namespace _GLIBCXX_STD _InputIterator __last) { // Check whether it's an integral type. If so, it's not an iterator. - typedef typename _Is_integer<_InputIterator>::_Integral _Integral; + typedef typename std::__is_integer<_InputIterator>::__type _Integral; _M_insert_dispatch(__position, __first, __last, _Integral()); } @@ -1154,6 +1200,11 @@ namespace _GLIBCXX_STD std::swap(this->_M_impl._M_finish, __x._M_impl._M_finish); std::swap(this->_M_impl._M_map, __x._M_impl._M_map); std::swap(this->_M_impl._M_map_size, __x._M_impl._M_map_size); + + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 431. Swapping containers with unequal allocators. + std::__alloc_swap<_Tp_alloc_type>::_S_do_it(_M_get_Tp_allocator(), + __x._M_get_Tp_allocator()); } /** @@ -1162,7 +1213,9 @@ namespace _GLIBCXX_STD * pointed-to memory is not touched in any way. Managing the pointer is * the user's responsibilty. */ - void clear(); + void + clear() + { _M_erase_at_end(begin()); } protected: // Internal constructor functions follow. @@ -1182,8 +1235,8 @@ namespace _GLIBCXX_STD _M_initialize_dispatch(_InputIterator __first, _InputIterator __last, __false_type) { - typedef typename iterator_traits<_InputIterator>::iterator_category - _IterCategory; + typedef typename std::iterator_traits<_InputIterator>:: + iterator_category _IterCategory; _M_range_initialize(__first, __last, _IterCategory()); } @@ -1204,13 +1257,13 @@ namespace _GLIBCXX_STD template<typename _InputIterator> void _M_range_initialize(_InputIterator __first, _InputIterator __last, - input_iterator_tag); + std::input_iterator_tag); // called by the second initialize_dispatch above template<typename _ForwardIterator> void _M_range_initialize(_ForwardIterator __first, _ForwardIterator __last, - forward_iterator_tag); + std::forward_iterator_tag); //@} /** @@ -1218,8 +1271,8 @@ namespace _GLIBCXX_STD * @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. + * @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). @@ -1246,8 +1299,8 @@ namespace _GLIBCXX_STD _M_assign_dispatch(_InputIterator __first, _InputIterator __last, __false_type) { - typedef typename iterator_traits<_InputIterator>::iterator_category - _IterCategory; + typedef typename std::iterator_traits<_InputIterator>:: + iterator_category _IterCategory; _M_assign_aux(__first, __last, _IterCategory()); } @@ -1255,13 +1308,13 @@ namespace _GLIBCXX_STD template<typename _InputIterator> void _M_assign_aux(_InputIterator __first, _InputIterator __last, - input_iterator_tag); + std::input_iterator_tag); // called by the second assign_dispatch above template<typename _ForwardIterator> void _M_assign_aux(_ForwardIterator __first, _ForwardIterator __last, - forward_iterator_tag) + std::forward_iterator_tag) { const size_type __len = std::distance(__first, __last); if (__len > size()) @@ -1272,11 +1325,11 @@ namespace _GLIBCXX_STD insert(end(), __mid, __last); } else - erase(std::copy(__first, __last, begin()), end()); + _M_erase_at_end(std::copy(__first, __last, begin())); } - // Called by assign(n,t), and the range assign when it turns out to be the - // same thing. + // 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) { @@ -1287,7 +1340,7 @@ namespace _GLIBCXX_STD } else { - erase(begin() + __n, end()); + _M_erase_at_end(begin() + difference_type(__n)); std::fill(begin(), end(), __val); } } @@ -1299,8 +1352,11 @@ namespace _GLIBCXX_STD * @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(); //@} @@ -1324,8 +1380,8 @@ namespace _GLIBCXX_STD _InputIterator __first, _InputIterator __last, __false_type) { - typedef typename iterator_traits<_InputIterator>::iterator_category - _IterCategory; + typedef typename std::iterator_traits<_InputIterator>:: + iterator_category _IterCategory; _M_range_insert_aux(__pos, __first, __last, _IterCategory()); } @@ -1333,13 +1389,13 @@ namespace _GLIBCXX_STD template<typename _InputIterator> void _M_range_insert_aux(iterator __pos, _InputIterator __first, - _InputIterator __last, input_iterator_tag); + _InputIterator __last, std::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); + _ForwardIterator __last, std::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, @@ -1362,6 +1418,55 @@ namespace _GLIBCXX_STD _ForwardIterator __first, _ForwardIterator __last, size_type __n); + + // Internal erase functions follow. + + void + _M_destroy_data_aux(iterator __first, iterator __last); + + void + _M_destroy_data_dispatch(iterator, iterator, __true_type) { } + + void + _M_destroy_data_dispatch(iterator __first, iterator __last, __false_type) + { _M_destroy_data_aux(__first, __last); } + + // Called by ~deque(). + // NB: Doesn't deallocate the nodes. + template<typename _Alloc1> + void + _M_destroy_data(iterator __first, iterator __last, const _Alloc1&) + { _M_destroy_data_aux(__first, __last); } + + void + _M_destroy_data(iterator __first, iterator __last, + const std::allocator<_Tp>&) + { + typedef typename std::__is_scalar<value_type>::__type + _Has_trivial_destructor; + _M_destroy_data_dispatch(__first, __last, _Has_trivial_destructor()); + } + + // Called by erase(q1, q2). + void + _M_erase_at_begin(iterator __pos) + { + _M_destroy_data(begin(), __pos, _M_get_Tp_allocator()); + _M_destroy_nodes(this->_M_impl._M_start._M_node, __pos._M_node); + this->_M_impl._M_start = __pos; + } + + // Called by erase(q1, q2), resize(), clear(), _M_assign_aux, + // _M_fill_assign, operator=. + void + _M_erase_at_end(iterator __pos) + { + _M_destroy_data(__pos, end(), _M_get_Tp_allocator()); + _M_destroy_nodes(__pos._M_node + 1, + this->_M_impl._M_finish._M_node + 1); + this->_M_impl._M_finish = __pos; + } + //@{ /** * @if maint @@ -1402,13 +1507,13 @@ namespace _GLIBCXX_STD * @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.) + * 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) + _M_reserve_map_at_back(size_type __nodes_to_add = 1) { if (__nodes_to_add + 1 > this->_M_impl._M_map_size - (this->_M_impl._M_finish._M_node - this->_M_impl._M_map)) @@ -1416,9 +1521,10 @@ namespace _GLIBCXX_STD } void - _M_reserve_map_at_front (size_type __nodes_to_add = 1) + _M_reserve_map_at_front(size_type __nodes_to_add = 1) { - if (__nodes_to_add > size_type(this->_M_impl._M_start._M_node - this->_M_impl._M_map)) + if (__nodes_to_add > size_type(this->_M_impl._M_start._M_node + - this->_M_impl._M_map)) _M_reallocate_map(__nodes_to_add, true); } @@ -1460,8 +1566,8 @@ namespace _GLIBCXX_STD inline bool operator<(const deque<_Tp, _Alloc>& __x, const deque<_Tp, _Alloc>& __y) - { return lexicographical_compare(__x.begin(), __x.end(), - __y.begin(), __y.end()); } + { return std::lexicographical_compare(__x.begin(), __x.end(), + __y.begin(), __y.end()); } /// Based on operator== template<typename _Tp, typename _Alloc> @@ -1496,6 +1602,7 @@ namespace _GLIBCXX_STD inline void swap(deque<_Tp,_Alloc>& __x, deque<_Tp,_Alloc>& __y) { __x.swap(__y); } -} // namespace std + +_GLIBCXX_END_NESTED_NAMESPACE #endif /* _DEQUE_H */ diff --git a/contrib/libstdc++/include/bits/stl_function.h b/contrib/libstdc++/include/bits/stl_function.h index 74ddcce..db213dc 100644 --- a/contrib/libstdc++/include/bits/stl_function.h +++ b/contrib/libstdc++/include/bits/stl_function.h @@ -1,6 +1,6 @@ // Functor implementations -*- C++ -*- -// Copyright (C) 2001, 2002, 2004 Free Software Foundation, Inc. +// Copyright (C) 2001, 2002, 2004, 2005 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 @@ -15,7 +15,7 @@ // 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// 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 @@ -61,8 +61,8 @@ #ifndef _FUNCTION_H #define _FUNCTION_H 1 -namespace std -{ +_GLIBCXX_BEGIN_NAMESPACE(std) + // 20.3.1 base classes /** @defgroup s20_3_1_base Functor Base Classes * Function objects, or @e functors, are objects with an @c operator() @@ -88,7 +88,7 @@ namespace std * \endcode * The addition and negation functions will be inlined directly. * - * The standard functiors are derived from structs named @c unary_function + * The standard functors are derived from structs named @c unary_function * and @c binary_function. These two classes contain nothing but typedefs, * to aid in generic (template) programming. If you write your own * functors, you might consider doing the same. @@ -360,7 +360,7 @@ namespace std /** @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 + * example, a 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 @@ -566,19 +566,11 @@ namespace std // 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. + * There are a total of 8 = 2^3 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. + * (3) Const vs non-const member function. * * 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, @@ -714,137 +706,6 @@ namespace std _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> @@ -889,10 +750,6 @@ namespace std /** @} */ -} // namespace std +_GLIBCXX_END_NAMESPACE #endif /* _FUNCTION_H */ - -// Local Variables: -// mode:C++ -// End: diff --git a/contrib/libstdc++/include/bits/stl_heap.h b/contrib/libstdc++/include/bits/stl_heap.h index eff7fd3..2f0d04c 100644 --- a/contrib/libstdc++/include/bits/stl_heap.h +++ b/contrib/libstdc++/include/bits/stl_heap.h @@ -1,6 +1,6 @@ // Heap implementation -*- C++ -*- -// Copyright (C) 2001, 2004 Free Software Foundation, Inc. +// Copyright (C) 2001, 2004, 2005, 2006 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 @@ -15,7 +15,7 @@ // 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// 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 @@ -62,8 +62,8 @@ #include <debug/debug.h> -namespace std -{ +_GLIBCXX_BEGIN_NAMESPACE(std) + // is_heap, a predicate testing whether or not a range is // a heap. This function is an extension, not part of the C++ // standard. @@ -430,7 +430,7 @@ namespace std // __glibcxx_requires_heap(__first, __last); while (__last - __first > 1) - std::pop_heap(__first, __last--); + std::pop_heap(__first, _RandomAccessIterator(__last--)); } /** @@ -455,13 +455,9 @@ namespace std __glibcxx_requires_heap_pred(__first, __last, __comp); while (__last - __first > 1) - std::pop_heap(__first, __last--, __comp); + std::pop_heap(__first, _RandomAccessIterator(__last--), __comp); } -} // namespace std +_GLIBCXX_END_NAMESPACE #endif /* _STL_HEAP_H */ - -// Local Variables: -// mode:C++ -// End: diff --git a/contrib/libstdc++/include/bits/stl_iterator.h b/contrib/libstdc++/include/bits/stl_iterator.h index cc56431..f9425aa 100644 --- a/contrib/libstdc++/include/bits/stl_iterator.h +++ b/contrib/libstdc++/include/bits/stl_iterator.h @@ -1,6 +1,7 @@ // Iterators -*- C++ -*- -// Copyright (C) 2001, 2002, 2004 Free Software Foundation, Inc. +// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 +// 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 @@ -15,7 +16,7 @@ // 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// 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 @@ -65,8 +66,11 @@ #ifndef _ITERATOR_H #define _ITERATOR_H 1 -namespace std -{ +#include <bits/cpp_type_traits.h> +#include <ext/type_traits.h> + +_GLIBCXX_BEGIN_NAMESPACE(std) + // 24.4.1 Reverse iterators /** * "Bidirectional and random access iterators have corresponding reverse @@ -203,7 +207,8 @@ namespace std * * @doctodo */ - reverse_iterator operator--(int) + reverse_iterator + operator--(int) { reverse_iterator __tmp = *this; ++current; @@ -299,7 +304,7 @@ namespace std template<typename _Iterator> inline bool operator<=(const reverse_iterator<_Iterator>& __x, - const reverse_iterator<_Iterator>& __y) + const reverse_iterator<_Iterator>& __y) { return !(__y < __x); } template<typename _Iterator> @@ -319,6 +324,50 @@ namespace std operator+(typename reverse_iterator<_Iterator>::difference_type __n, const reverse_iterator<_Iterator>& __x) { return reverse_iterator<_Iterator>(__x.base() - __n); } + + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // DR 280. Comparison of reverse_iterator to const reverse_iterator. + template<typename _IteratorL, typename _IteratorR> + inline bool + operator==(const reverse_iterator<_IteratorL>& __x, + const reverse_iterator<_IteratorR>& __y) + { return __x.base() == __y.base(); } + + template<typename _IteratorL, typename _IteratorR> + inline bool + operator<(const reverse_iterator<_IteratorL>& __x, + const reverse_iterator<_IteratorR>& __y) + { return __y.base() < __x.base(); } + + template<typename _IteratorL, typename _IteratorR> + inline bool + operator!=(const reverse_iterator<_IteratorL>& __x, + const reverse_iterator<_IteratorR>& __y) + { return !(__x == __y); } + + template<typename _IteratorL, typename _IteratorR> + inline bool + operator>(const reverse_iterator<_IteratorL>& __x, + const reverse_iterator<_IteratorR>& __y) + { return __y < __x; } + + template<typename _IteratorL, typename _IteratorR> + inline bool + operator<=(const reverse_iterator<_IteratorL>& __x, + const reverse_iterator<_IteratorR>& __y) + { return !(__y < __x); } + + template<typename _IteratorL, typename _IteratorR> + inline bool + operator>=(const reverse_iterator<_IteratorL>& __x, + const reverse_iterator<_IteratorR>& __y) + { return !(__x < __y); } + + template<typename _IteratorL, typename _IteratorR> + inline typename reverse_iterator<_IteratorL>::difference_type + operator-(const reverse_iterator<_IteratorL>& __x, + const reverse_iterator<_IteratorR>& __y) + { return __y.base() - __x.base(); } //@} // 24.4.2.2.1 back_insert_iterator @@ -569,10 +618,11 @@ namespace std return insert_iterator<_Container>(__x, typename _Container::iterator(__i)); } -} // namespace std -namespace __gnu_cxx -{ +_GLIBCXX_END_NAMESPACE + +_GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) + // This iterator adapter is 'normal' in the sense that it does not // change the semantics of any of the operators of its iterator // parameter. Its primary purpose is to convert an iterator that is @@ -604,9 +654,11 @@ namespace __gnu_cxx // Allow iterator to const_iterator conversion template<typename _Iter> - inline __normal_iterator(const __normal_iterator<_Iter, - _Container>& __i) - : _M_current(__i.base()) { } + __normal_iterator(const __normal_iterator<_Iter, + typename __enable_if< + (std::__are_same<_Iter, typename _Container::pointer>::__value), + _Container>::__type>& __i) + : _M_current(__i.base()) { } // Forward iterator requirements reference @@ -759,14 +811,17 @@ namespace __gnu_cxx { return __lhs.base() - __rhs.base(); } template<typename _Iterator, typename _Container> + inline typename __normal_iterator<_Iterator, _Container>::difference_type + operator-(const __normal_iterator<_Iterator, _Container>& __lhs, + const __normal_iterator<_Iterator, _Container>& __rhs) + { return __lhs.base() - __rhs.base(); } + + template<typename _Iterator, typename _Container> inline __normal_iterator<_Iterator, _Container> operator+(typename __normal_iterator<_Iterator, _Container>::difference_type __n, const __normal_iterator<_Iterator, _Container>& __i) { return __normal_iterator<_Iterator, _Container>(__i.base() + __n); } -} // namespace __gnu_cxx -#endif +_GLIBCXX_END_NAMESPACE -// Local Variables: -// mode:C++ -// End: +#endif diff --git a/contrib/libstdc++/include/bits/stl_iterator_base_funcs.h b/contrib/libstdc++/include/bits/stl_iterator_base_funcs.h index c514e81..79fb667 100644 --- a/contrib/libstdc++/include/bits/stl_iterator_base_funcs.h +++ b/contrib/libstdc++/include/bits/stl_iterator_base_funcs.h @@ -1,6 +1,7 @@ // Functions used by iterators -*- C++ -*- -// Copyright (C) 2001, 2002, 2003, 2004 Free Software Foundation, Inc. +// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 +// 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 @@ -15,7 +16,7 @@ // 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// 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 @@ -67,8 +68,8 @@ #pragma GCC system_header #include <bits/concept_check.h> -namespace std -{ +_GLIBCXX_BEGIN_NAMESPACE(std) + template<typename _InputIterator> inline typename iterator_traits<_InputIterator>::difference_type __distance(_InputIterator __first, _InputIterator __last, @@ -131,7 +132,7 @@ namespace std template<typename _BidirectionalIterator, typename _Distance> inline void __advance(_BidirectionalIterator& __i, _Distance __n, - bidirectional_iterator_tag) + bidirectional_iterator_tag) { // concept requirements __glibcxx_function_requires(_BidirectionalIteratorConcept< @@ -172,8 +173,10 @@ namespace std advance(_InputIterator& __i, _Distance __n) { // concept requirements -- taken care of in __advance - std::__advance(__i, __n, std::__iterator_category(__i)); + typename iterator_traits<_InputIterator>::difference_type __d = __n; + std::__advance(__i, __d, std::__iterator_category(__i)); } -} // namespace std + +_GLIBCXX_END_NAMESPACE #endif /* _ITERATOR_BASE_FUNCS_H */ diff --git a/contrib/libstdc++/include/bits/stl_iterator_base_types.h b/contrib/libstdc++/include/bits/stl_iterator_base_types.h index c3bb1c5..c02cd26 100644 --- a/contrib/libstdc++/include/bits/stl_iterator_base_types.h +++ b/contrib/libstdc++/include/bits/stl_iterator_base_types.h @@ -1,6 +1,6 @@ // Types used in iterator implementation -*- C++ -*- -// Copyright (C) 2001, 2002, 2004 Free Software Foundation, Inc. +// Copyright (C) 2001, 2002, 2004, 2005 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 @@ -15,7 +15,7 @@ // 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// 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 @@ -66,8 +66,8 @@ #pragma GCC system_header -namespace std -{ +_GLIBCXX_BEGIN_NAMESPACE(std) + //@{ /** * @defgroup iterator_tags Iterator Tags @@ -164,7 +164,7 @@ namespace std __iterator_category(const _Iter&) { return typename iterator_traits<_Iter>::iterator_category(); } -} // namespace std +_GLIBCXX_END_NAMESPACE #endif /* _ITERATOR_BASE_TYPES_H */ diff --git a/contrib/libstdc++/include/bits/stl_list.h b/contrib/libstdc++/include/bits/stl_list.h index afb118b..e37e5ee 100644 --- a/contrib/libstdc++/include/bits/stl_list.h +++ b/contrib/libstdc++/include/bits/stl_list.h @@ -1,6 +1,7 @@ // List implementation -*- C++ -*- -// Copyright (C) 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. +// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 +// 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 @@ -15,7 +16,7 @@ // 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// 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 @@ -63,8 +64,8 @@ #include <bits/concept_check.h> -namespace _GLIBCXX_STD -{ +_GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD) + // Supporting structures are split into common and templated types; the // latter publicly inherits from the former in an effort to reduce code // duplication. This results in some "needless" static_cast'ing later on, @@ -110,18 +111,19 @@ namespace _GLIBCXX_STD template<typename _Tp> struct _List_iterator { - typedef _List_iterator<_Tp> _Self; - typedef _List_node<_Tp> _Node; + typedef _List_iterator<_Tp> _Self; + typedef _List_node<_Tp> _Node; - typedef ptrdiff_t difference_type; - typedef bidirectional_iterator_tag iterator_category; - typedef _Tp value_type; - typedef _Tp* pointer; - typedef _Tp& reference; + typedef ptrdiff_t difference_type; + typedef std::bidirectional_iterator_tag iterator_category; + typedef _Tp value_type; + typedef _Tp* pointer; + typedef _Tp& reference; _List_iterator() : _M_node() { } + explicit _List_iterator(_List_node_base* __x) : _M_node(__x) { } @@ -186,19 +188,20 @@ namespace _GLIBCXX_STD template<typename _Tp> struct _List_const_iterator { - typedef _List_const_iterator<_Tp> _Self; - typedef const _List_node<_Tp> _Node; - typedef _List_iterator<_Tp> iterator; + typedef _List_const_iterator<_Tp> _Self; + typedef const _List_node<_Tp> _Node; + typedef _List_iterator<_Tp> iterator; - typedef ptrdiff_t difference_type; - typedef bidirectional_iterator_tag iterator_category; - typedef _Tp value_type; - typedef const _Tp* pointer; - typedef const _Tp& reference; + typedef ptrdiff_t difference_type; + typedef std::bidirectional_iterator_tag iterator_category; + typedef _Tp value_type; + typedef const _Tp* pointer; + typedef const _Tp& reference; _List_const_iterator() : _M_node() { } + explicit _List_const_iterator(const _List_node_base* __x) : _M_node(__x) { } @@ -290,17 +293,20 @@ namespace _GLIBCXX_STD // // We put this to the test in the constructors and in // get_allocator, where we use conversions between - // allocator_type and _Node_Alloc_type. The conversion is + // allocator_type and _Node_alloc_type. The conversion is // required by table 32 in [20.1.5]. typedef typename _Alloc::template rebind<_List_node<_Tp> >::other + _Node_alloc_type; - _Node_Alloc_type; + typedef typename _Alloc::template rebind<_Tp>::other _Tp_alloc_type; struct _List_impl - : public _Node_Alloc_type { + : public _Node_alloc_type + { _List_node_base _M_node; - _List_impl (const _Node_Alloc_type& __a) - : _Node_Alloc_type(__a) + + _List_impl(const _Node_alloc_type& __a) + : _Node_alloc_type(__a), _M_node() { } }; @@ -308,21 +314,33 @@ namespace _GLIBCXX_STD _List_node<_Tp>* _M_get_node() - { return _M_impl._Node_Alloc_type::allocate(1); } + { return _M_impl._Node_alloc_type::allocate(1); } void _M_put_node(_List_node<_Tp>* __p) - { _M_impl._Node_Alloc_type::deallocate(__p, 1); } + { _M_impl._Node_alloc_type::deallocate(__p, 1); } public: typedef _Alloc allocator_type; + _Node_alloc_type& + _M_get_Node_allocator() + { return *static_cast<_Node_alloc_type*>(&this->_M_impl); } + + const _Node_alloc_type& + _M_get_Node_allocator() const + { return *static_cast<const _Node_alloc_type*>(&this->_M_impl); } + + _Tp_alloc_type + _M_get_Tp_allocator() const + { return _Tp_alloc_type(_M_get_Node_allocator()); } + allocator_type get_allocator() const - { return allocator_type(*static_cast<const _Node_Alloc_type*>(&this->_M_impl)); } + { return allocator_type(_M_get_Node_allocator()); } _List_base(const allocator_type& __a) - : _M_impl(__a) + : _M_impl(__a) { _M_init(); } // This is what actually destroys the list. @@ -385,42 +403,41 @@ namespace _GLIBCXX_STD * iterator's next/previous pointers refer to itself, the %list is * %empty. @endif */ - template<typename _Tp, typename _Alloc = allocator<_Tp> > + template<typename _Tp, typename _Alloc = std::allocator<_Tp> > class list : protected _List_base<_Tp, _Alloc> { // concept requirements + typedef typename _Alloc::value_type _Alloc_value_type; __glibcxx_class_requires(_Tp, _SGIAssignableConcept) + __glibcxx_class_requires2(_Tp, _Alloc_value_type, _SameTypeConcept) - typedef _List_base<_Tp, _Alloc> _Base; + typedef _List_base<_Tp, _Alloc> _Base; + typedef typename _Base::_Tp_alloc_type _Tp_alloc_type; public: typedef _Tp value_type; - typedef typename _Alloc::pointer pointer; - typedef typename _Alloc::const_pointer const_pointer; - typedef typename _Alloc::reference reference; - typedef typename _Alloc::const_reference const_reference; + typedef typename _Tp_alloc_type::pointer pointer; + typedef typename _Tp_alloc_type::const_pointer const_pointer; + typedef typename _Tp_alloc_type::reference reference; + typedef typename _Tp_alloc_type::const_reference const_reference; typedef _List_iterator<_Tp> iterator; typedef _List_const_iterator<_Tp> const_iterator; typedef std::reverse_iterator<const_iterator> const_reverse_iterator; typedef std::reverse_iterator<iterator> reverse_iterator; typedef size_t size_type; typedef ptrdiff_t difference_type; - typedef typename _Base::allocator_type allocator_type; + typedef _Alloc allocator_type; protected: // Note that pointers-to-_Node's can be ctor-converted to // iterator types. - typedef _List_node<_Tp> _Node; + typedef _List_node<_Tp> _Node; - /** @if maint - * One data member plus two memory-handling functions. If the - * _Alloc type requires separate instances, then one of those - * will also be included, accumulated from the topmost parent. - * @endif - */ using _Base::_M_impl; using _Base::_M_put_node; using _Base::_M_get_node; + using _Base::_M_get_Tp_allocator; + using _Base::_M_get_Node_allocator; /** * @if maint @@ -435,29 +452,7 @@ namespace _GLIBCXX_STD _Node* __p = this->_M_get_node(); try { - std::_Construct(&__p->_M_data, __x); - } - catch(...) - { - _M_put_node(__p); - __throw_exception_again; - } - return __p; - } - - /** - * @if maint - * Allocates space for a new node and default-constructs a new - * instance of @c value_type in it. - * @endif - */ - _Node* - _M_create_node() - { - _Node* __p = this->_M_get_node(); - try - { - std::_Construct(&__p->_M_data); + _M_get_Tp_allocator().construct(&__p->_M_data, __x); } catch(...) { @@ -484,22 +479,11 @@ namespace _GLIBCXX_STD * * This constructor fills the %list with @a n copies of @a value. */ - list(size_type __n, const value_type& __value, + explicit + list(size_type __n, const value_type& __value = value_type(), const allocator_type& __a = allocator_type()) : _Base(__a) - { this->insert(begin(), __n, __value); } - - /** - * @brief Create a %list with default elements. - * @param n The number of elements to initially create. - * - * This constructor fills the %list with @a n copies of a - * default-constructed element. - */ - explicit - list(size_type __n) - : _Base(allocator_type()) - { this->insert(begin(), __n, value_type()); } + { _M_fill_initialize(__n, __value); } /** * @brief %List copy constructor. @@ -509,8 +493,8 @@ namespace _GLIBCXX_STD * by @a x. */ list(const list& __x) - : _Base(__x.get_allocator()) - { this->insert(begin(), __x.begin(), __x.end()); } + : _Base(__x._M_get_Node_allocator()) + { _M_initialize_dispatch(__x.begin(), __x.end(), __false_type()); } /** * @brief Builds a %list from a range. @@ -520,17 +504,16 @@ namespace _GLIBCXX_STD * Create a %list consisting of copies of the elements from * [@a first,@a last). This is linear in N (where N is * distance(@a first,@a last)). - * - * @if maint - * We don't need any dispatching tricks here, because insert does all of - * that anyway. - * @endif */ template<typename _InputIterator> list(_InputIterator __first, _InputIterator __last, const allocator_type& __a = allocator_type()) : _Base(__a) - { this->insert(begin(), __first, __last); } + { + // Check whether it's an integral type. If so, it's not an iterator. + typedef typename std::__is_integer<_InputIterator>::__type _Integral; + _M_initialize_dispatch(__first, __last, _Integral()); + } /** * No explicit dtor needed as the _Base dtor takes care of @@ -581,7 +564,7 @@ namespace _GLIBCXX_STD assign(_InputIterator __first, _InputIterator __last) { // Check whether it's an integral type. If so, it's not an iterator. - typedef typename _Is_integer<_InputIterator>::_Integral _Integral; + typedef typename std::__is_integer<_InputIterator>::__type _Integral; _M_assign_dispatch(__first, __last, _Integral()); } @@ -597,7 +580,7 @@ namespace _GLIBCXX_STD */ iterator begin() - { return this->_M_impl._M_node._M_next; } + { return iterator(this->_M_impl._M_node._M_next); } /** * Returns a read-only (constant) iterator that points to the @@ -606,7 +589,7 @@ namespace _GLIBCXX_STD */ const_iterator begin() const - { return this->_M_impl._M_node._M_next; } + { return const_iterator(this->_M_impl._M_node._M_next); } /** * Returns a read/write iterator that points one past the last @@ -614,7 +597,8 @@ namespace _GLIBCXX_STD * order. */ iterator - end() { return &this->_M_impl._M_node; } + end() + { return iterator(&this->_M_impl._M_node); } /** * Returns a read-only (constant) iterator that points one past @@ -623,7 +607,7 @@ namespace _GLIBCXX_STD */ const_iterator end() const - { return &this->_M_impl._M_node; } + { return const_iterator(&this->_M_impl._M_node); } /** * Returns a read/write reverse iterator that points to the last @@ -678,7 +662,7 @@ namespace _GLIBCXX_STD /** Returns the size() of the largest possible %list. */ size_type max_size() const - { return size_type(-1); } + { return _M_get_Tp_allocator().max_size(); } /** * @brief Resizes the %list to the specified number of elements. @@ -691,20 +675,7 @@ namespace _GLIBCXX_STD * extended and new elements are populated with given data. */ void - resize(size_type __new_size, const value_type& __x); - - /** - * @brief Resizes the %list to the specified number of elements. - * @param new_size Number of elements the %list should contain. - * - * 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 default-constructed. - */ - void - resize(size_type __new_size) - { this->resize(__new_size, value_type()); } + resize(size_type __new_size, value_type __x = value_type()); // element access /** @@ -729,7 +700,11 @@ namespace _GLIBCXX_STD */ reference back() - { return *(--end()); } + { + iterator __tmp = end(); + --__tmp; + return *__tmp; + } /** * Returns a read-only (constant) reference to the data at the last @@ -737,7 +712,11 @@ namespace _GLIBCXX_STD */ const_reference back() const - { return *(--end()); } + { + const_iterator __tmp = end(); + --__tmp; + return *__tmp; + } // [23.2.2.3] modifiers /** @@ -797,7 +776,7 @@ namespace _GLIBCXX_STD */ void pop_back() - { this->_M_erase(this->_M_impl._M_node._M_prev); } + { this->_M_erase(iterator(this->_M_impl._M_node._M_prev)); } /** * @brief Inserts given value into %list before specified iterator. @@ -822,13 +801,15 @@ namespace _GLIBCXX_STD * This function will insert a specified number of copies of the * given data before the location specified by @a position. * - * Due to the nature of a %list this operation can be done in - * constant time, and does not invalidate iterators and - * references. + * 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) - { _M_fill_insert(__position, __n, __x); } + { + list __tmp(__n, __x, _M_get_Node_allocator()); + splice(__position, __tmp); + } /** * @brief Inserts a range into the %list. @@ -840,18 +821,16 @@ namespace _GLIBCXX_STD * first,@a last) into the %list before the location specified by * @a position. * - * Due to the nature of a %list this operation can be done in - * constant time, and does not invalidate iterators and - * references. + * This operation is linear in the number of elements inserted and + * does not invalidate iterators and references. */ template<typename _InputIterator> void insert(iterator __position, _InputIterator __first, _InputIterator __last) { - // Check whether it's an integral type. If so, it's not an iterator. - typedef typename _Is_integer<_InputIterator>::_Integral _Integral; - _M_insert_dispatch(__position, __first, __last, _Integral()); + list __tmp(__first, __last, _M_get_Node_allocator()); + splice(__position, __tmp); } /** @@ -883,13 +862,12 @@ namespace _GLIBCXX_STD * This function will erase the elements in the range @a * [first,last) and shorten the %list accordingly. * - * 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 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. + * 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 responsibilty. */ iterator erase(iterator __first, iterator __last) @@ -910,7 +888,14 @@ namespace _GLIBCXX_STD */ void swap(list& __x) - { _List_node_base::swap(this->_M_impl._M_node,__x._M_impl._M_node); } + { + _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<typename _Base::_Node_alloc_type>:: + _S_do_it(_M_get_Node_allocator(), __x._M_get_Node_allocator()); + } /** * Erases all the elements. Note that this function only erases @@ -934,12 +919,18 @@ namespace _GLIBCXX_STD * 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 splice(iterator __position, list& __x) { if (!__x.empty()) - this->_M_transfer(__position, __x.begin(), __x.end()); + { + _M_check_equal_allocators(__x); + + this->_M_transfer(__position, __x.begin(), __x.end()); + } } /** @@ -952,12 +943,16 @@ namespace _GLIBCXX_STD * inserts it into the current list before @a position. */ void - splice(iterator __position, list&, iterator __i) + splice(iterator __position, list& __x, iterator __i) { iterator __j = __i; ++__j; if (__position == __i || __position == __j) return; + + if (this != &__x) + _M_check_equal_allocators(__x); + this->_M_transfer(__position, __i, __j); } @@ -974,10 +969,15 @@ namespace _GLIBCXX_STD * Undefined if @a position is in [first,last). */ void - splice(iterator __position, list&, iterator __first, iterator __last) + splice(iterator __position, list& __x, iterator __first, iterator __last) { if (__first != __last) - this->_M_transfer(__position, __first, __last); + { + if (this != &__x) + _M_check_equal_allocators(__x); + + this->_M_transfer(__position, __first, __last); + } } /** @@ -1006,8 +1006,8 @@ namespace _GLIBCXX_STD * responsibilty. */ template<typename _Predicate> - void - remove_if(_Predicate); + void + remove_if(_Predicate); /** * @brief Remove consecutive duplicate elements. @@ -1095,66 +1095,64 @@ namespace _GLIBCXX_STD sort(_StrictWeakOrdering); protected: - // Internal assign functions follow. + // Internal constructor functions follow. - // Called by the range assign to implement [23.1.1]/9 + // Called by the range constructor to implement [23.1.1]/9 template<typename _Integer> void - _M_assign_dispatch(_Integer __n, _Integer __val, __true_type) + _M_initialize_dispatch(_Integer __n, _Integer __x, __true_type) { - _M_fill_assign(static_cast<size_type>(__n), - static_cast<value_type>(__val)); + _M_fill_initialize(static_cast<size_type>(__n), + static_cast<value_type>(__x)); } - // Called by the range assign to implement [23.1.1]/9 + // Called by the range constructor to implement [23.1.1]/9 template<typename _InputIterator> void - _M_assign_dispatch(_InputIterator __first, _InputIterator __last, - __false_type); + _M_initialize_dispatch(_InputIterator __first, _InputIterator __last, + __false_type) + { + for (; __first != __last; ++__first) + push_back(*__first); + } - // Called by assign(n,t), and the range assign when it turns out + // Called by list(n,v,a), and the range constructor when it turns out // to be the same thing. void - _M_fill_assign(size_type __n, const value_type& __val); + _M_fill_initialize(size_type __n, const value_type& __x) + { + for (; __n > 0; --__n) + push_back(__x); + } - // Internal insert functions follow. + // Internal assign functions follow. - // Called by the range insert to implement [23.1.1]/9 + // Called by the range assign to implement [23.1.1]/9 template<typename _Integer> void - _M_insert_dispatch(iterator __pos, _Integer __n, _Integer __x, - __true_type) + _M_assign_dispatch(_Integer __n, _Integer __val, __true_type) { - _M_fill_insert(__pos, static_cast<size_type>(__n), - static_cast<value_type>(__x)); + _M_fill_assign(static_cast<size_type>(__n), + static_cast<value_type>(__val)); } - // Called by the range insert to implement [23.1.1]/9 + // Called by the range assign to implement [23.1.1]/9 template<typename _InputIterator> void - _M_insert_dispatch(iterator __pos, - _InputIterator __first, _InputIterator __last, - __false_type) - { - for ( ; __first != __last; ++__first) - _M_insert(__pos, *__first); - } + _M_assign_dispatch(_InputIterator __first, _InputIterator __last, + __false_type); - // Called by insert(p,n,x), and the range insert when it turns out + // Called by assign(n,t), and the range assign when it turns out // to be the same thing. void - _M_fill_insert(iterator __pos, size_type __n, const value_type& __x) - { - for ( ; __n > 0; --__n) - _M_insert(__pos, __x); - } + _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); } + { __position._M_node->transfer(__first._M_node, __last._M_node); } // Inserts new element at position given and with value given. void @@ -1170,9 +1168,17 @@ namespace _GLIBCXX_STD { __position._M_node->unhook(); _Node* __n = static_cast<_Node*>(__position._M_node); - std::_Destroy(&__n->_M_data); + _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 (_M_get_Node_allocator() != __x._M_get_Node_allocator()) + __throw_runtime_error(__N("list::_M_check_equal_allocators")); + } }; /** @@ -1187,9 +1193,9 @@ namespace _GLIBCXX_STD */ template<typename _Tp, typename _Alloc> inline bool - operator==(const list<_Tp,_Alloc>& __x, const list<_Tp,_Alloc>& __y) + operator==(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) { - typedef typename list<_Tp,_Alloc>::const_iterator const_iterator; + typedef typename list<_Tp, _Alloc>::const_iterator const_iterator; const_iterator __end1 = __x.end(); const_iterator __end2 = __y.end(); @@ -1216,32 +1222,32 @@ namespace _GLIBCXX_STD */ template<typename _Tp, typename _Alloc> 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(), __y.begin(), __y.end()); } /// Based on operator== template<typename _Tp, typename _Alloc> 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 !(__x == __y); } /// Based on operator< template<typename _Tp, typename _Alloc> 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 __y < __x; } /// Based on operator< template<typename _Tp, typename _Alloc> 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 !(__y < __x); } /// Based on operator< template<typename _Tp, typename _Alloc> 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 !(__x < __y); } /// See std::list::swap(). @@ -1249,7 +1255,8 @@ namespace _GLIBCXX_STD inline void swap(list<_Tp, _Alloc>& __x, list<_Tp, _Alloc>& __y) { __x.swap(__y); } -} // namespace std + +_GLIBCXX_END_NESTED_NAMESPACE #endif /* _LIST_H */ diff --git a/contrib/libstdc++/include/bits/stl_map.h b/contrib/libstdc++/include/bits/stl_map.h index 8535ae5..13e62bc 100644 --- a/contrib/libstdc++/include/bits/stl_map.h +++ b/contrib/libstdc++/include/bits/stl_map.h @@ -1,6 +1,7 @@ // Map implementation -*- C++ -*- -// Copyright (C) 2001, 2002, 2004 Free Software Foundation, Inc. +// Copyright (C) 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 @@ -15,7 +16,7 @@ // 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// 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 @@ -61,10 +62,11 @@ #ifndef _MAP_H #define _MAP_H 1 +#include <bits/functexcept.h> #include <bits/concept_check.h> -namespace _GLIBCXX_STD -{ +_GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD) + /** * @brief A standard container made up of (key,value) pairs, which can be * retrieved based on a key, in logarithmic time. @@ -86,25 +88,30 @@ namespace _GLIBCXX_STD * called (*_unique versus *_equal, same as the standard). * @endif */ - template <typename _Key, typename _Tp, typename _Compare = less<_Key>, - typename _Alloc = allocator<pair<const _Key, _Tp> > > + template <typename _Key, typename _Tp, typename _Compare = std::less<_Key>, + typename _Alloc = std::allocator<std::pair<const _Key, _Tp> > > class map { + public: + typedef _Key key_type; + typedef _Tp mapped_type; + typedef std::pair<const _Key, _Tp> 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: - typedef _Key key_type; - typedef _Tp mapped_type; - typedef pair<const _Key, _Tp> value_type; - typedef _Compare key_compare; - class value_compare - : public binary_function<value_type, value_type, bool> + : public std::binary_function<value_type, value_type, bool> { - friend class map<_Key,_Tp,_Compare,_Alloc>; + friend class map<_Key, _Tp, _Compare, _Alloc>; protected: _Compare comp; @@ -118,19 +125,22 @@ namespace _GLIBCXX_STD private: /// @if maint This turns a red-black tree into a [multi]map. @endif - typedef _Rb_tree<key_type, value_type, - _Select1st<value_type>, key_compare, _Alloc> _Rep_type; + typedef typename _Alloc::template rebind<value_type>::other + _Pair_alloc_type; + + typedef _Rb_tree<key_type, value_type, _Select1st<value_type>, + key_compare, _Pair_alloc_type> _Rep_type; + /// @if maint The actual tree structure. @endif _Rep_type _M_t; public: // many of these are specified differently in ISO, but the following are // "functionally equivalent" - typedef typename _Alloc::pointer pointer; - typedef typename _Alloc::const_pointer const_pointer; - typedef typename _Alloc::reference reference; - typedef typename _Alloc::const_reference const_reference; - typedef typename _Rep_type::allocator_type allocator_type; + 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; @@ -177,7 +187,7 @@ namespace _GLIBCXX_STD template <typename _InputIterator> map(_InputIterator __first, _InputIterator __last) : _M_t(_Compare(), allocator_type()) - { _M_t.insert_unique(__first, __last); } + { _M_t._M_insert_unique(__first, __last); } /** * @brief Builds a %map from a range. @@ -194,11 +204,11 @@ namespace _GLIBCXX_STD map(_InputIterator __first, _InputIterator __last, const _Compare& __comp, const allocator_type& __a = allocator_type()) : _M_t(__comp, __a) - { _M_t.insert_unique(__first, __last); } + { _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: + // 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 @@ -244,8 +254,9 @@ namespace _GLIBCXX_STD { 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. + * 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() @@ -320,10 +331,10 @@ namespace _GLIBCXX_STD * @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. + * 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. */ @@ -340,14 +351,43 @@ namespace _GLIBCXX_STD 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. + + * @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 @@ -355,36 +395,39 @@ namespace _GLIBCXX_STD * * Insertion requires logarithmic time. */ - pair<iterator,bool> + std::pair<iterator, bool> insert(const value_type& __x) - { return _M_t.insert_unique(__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). + * @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. + + * 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++/23_containers/howto.html#4 + * 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_unique(position, __x); } + insert(iterator __position, const value_type& __x) + { return _M_t._M_insert_unique(__position, __x); } /** - * @brief A template function that attemps to insert a range of elements. + * @brief 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. @@ -394,16 +437,17 @@ namespace _GLIBCXX_STD template <typename _InputIterator> void insert(_InputIterator __first, _InputIterator __last) - { _M_t.insert_unique(__first, __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 responsibilty. + * 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 erase(iterator __position) @@ -443,22 +487,22 @@ namespace _GLIBCXX_STD * @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. + * 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 swap(map& __x) { _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 responsibilty. + * 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 responsibilty. */ void clear() @@ -589,7 +633,7 @@ namespace _GLIBCXX_STD * * This function probably only makes sense for multimaps. */ - pair<iterator,iterator> + std::pair<iterator, iterator> equal_range(const key_type& __x) { return _M_t.equal_range(__x); } @@ -608,19 +652,19 @@ namespace _GLIBCXX_STD * * This function probably only makes sense for multimaps. */ - pair<const_iterator,const_iterator> + std::pair<const_iterator, const_iterator> 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>&, - const map<_K1,_T1,_C1,_A1>&); + operator== (const map<_K1, _T1, _C1, _A1>&, + const map<_K1, _T1, _C1, _A1>&); template <typename _K1, typename _T1, typename _C1, typename _A1> friend bool - operator< (const map<_K1,_T1,_C1,_A1>&, - const map<_K1,_T1,_C1,_A1>&); + operator< (const map<_K1, _T1, _C1, _A1>&, + const map<_K1, _T1, _C1, _A1>&); }; /** @@ -635,8 +679,8 @@ namespace _GLIBCXX_STD */ template <typename _Key, typename _Tp, typename _Compare, typename _Alloc> inline bool - operator==(const map<_Key,_Tp,_Compare,_Alloc>& __x, - const map<_Key,_Tp,_Compare,_Alloc>& __y) + operator==(const map<_Key, _Tp, _Compare, _Alloc>& __x, + const map<_Key, _Tp, _Compare, _Alloc>& __y) { return __x._M_t == __y._M_t; } /** @@ -652,43 +696,45 @@ namespace _GLIBCXX_STD */ template <typename _Key, typename _Tp, typename _Compare, typename _Alloc> inline bool - operator<(const map<_Key,_Tp,_Compare,_Alloc>& __x, - const map<_Key,_Tp,_Compare,_Alloc>& __y) + 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 <typename _Key, typename _Tp, typename _Compare, typename _Alloc> inline bool - operator!=(const map<_Key,_Tp,_Compare,_Alloc>& __x, - const map<_Key,_Tp,_Compare,_Alloc>& __y) + operator!=(const map<_Key, _Tp, _Compare, _Alloc>& __x, + const map<_Key, _Tp, _Compare, _Alloc>& __y) { return !(__x == __y); } /// Based on operator< template <typename _Key, typename _Tp, typename _Compare, typename _Alloc> inline bool - operator>(const map<_Key,_Tp,_Compare,_Alloc>& __x, - const map<_Key,_Tp,_Compare,_Alloc>& __y) + operator>(const map<_Key, _Tp, _Compare, _Alloc>& __x, + const map<_Key, _Tp, _Compare, _Alloc>& __y) { return __y < __x; } /// Based on operator< template <typename _Key, typename _Tp, typename _Compare, typename _Alloc> inline bool - operator<=(const map<_Key,_Tp,_Compare,_Alloc>& __x, - const map<_Key,_Tp,_Compare,_Alloc>& __y) + operator<=(const map<_Key, _Tp, _Compare, _Alloc>& __x, + const map<_Key, _Tp, _Compare, _Alloc>& __y) { return !(__y < __x); } /// Based on operator< template <typename _Key, typename _Tp, typename _Compare, typename _Alloc> inline bool - operator>=(const map<_Key,_Tp,_Compare,_Alloc>& __x, - const map<_Key,_Tp,_Compare,_Alloc>& __y) + operator>=(const map<_Key, _Tp, _Compare, _Alloc>& __x, + const map<_Key, _Tp, _Compare, _Alloc>& __y) { return !(__x < __y); } /// See std::map::swap(). template <typename _Key, typename _Tp, typename _Compare, typename _Alloc> inline void - swap(map<_Key,_Tp,_Compare,_Alloc>& __x, map<_Key,_Tp,_Compare,_Alloc>& __y) + swap(map<_Key, _Tp, _Compare, _Alloc>& __x, + map<_Key, _Tp, _Compare, _Alloc>& __y) { __x.swap(__y); } -} // namespace std + +_GLIBCXX_END_NESTED_NAMESPACE #endif /* _MAP_H */ diff --git a/contrib/libstdc++/include/bits/stl_multimap.h b/contrib/libstdc++/include/bits/stl_multimap.h index e080f9a..b11b6e4 100644 --- a/contrib/libstdc++/include/bits/stl_multimap.h +++ b/contrib/libstdc++/include/bits/stl_multimap.h @@ -1,6 +1,6 @@ // Multimap implementation -*- C++ -*- -// Copyright (C) 2001, 2002, 2004 Free Software Foundation, Inc. +// Copyright (C) 2001, 2002, 2004, 2005, 2006 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 @@ -15,7 +15,7 @@ // 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// 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 @@ -63,24 +63,7 @@ #include <bits/concept_check.h> -namespace _GLIBCXX_STD -{ - // Forward declaration of operators < and ==, needed for friend declaration. - - template <typename _Key, typename _Tp, - typename _Compare = less<_Key>, - typename _Alloc = allocator<pair<const _Key, _Tp> > > - class multimap; - - template <typename _Key, typename _Tp, typename _Compare, typename _Alloc> - inline bool - operator==(const multimap<_Key,_Tp,_Compare,_Alloc>& __x, - const multimap<_Key,_Tp,_Compare,_Alloc>& __y); - - template <typename _Key, typename _Tp, typename _Compare, typename _Alloc> - inline bool - operator<(const multimap<_Key,_Tp,_Compare,_Alloc>& __x, - const multimap<_Key,_Tp,_Compare,_Alloc>& __y); +_GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD) /** * @brief A standard container made up of (key,value) pairs, which can be @@ -103,24 +86,31 @@ namespace _GLIBCXX_STD * called (*_unique versus *_equal, same as the standard). * @endif */ - template <typename _Key, typename _Tp, typename _Compare, typename _Alloc> + template <typename _Key, typename _Tp, + typename _Compare = std::less<_Key>, + typename _Alloc = std::allocator<std::pair<const _Key, _Tp> > > class multimap { + public: + typedef _Key key_type; + typedef _Tp mapped_type; + typedef std::pair<const _Key, _Tp> 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: - typedef _Key key_type; - typedef _Tp mapped_type; - typedef pair<const _Key, _Tp> value_type; - typedef _Compare key_compare; - class value_compare - : public binary_function<value_type, value_type, bool> + : public std::binary_function<value_type, value_type, bool> { - friend class multimap<_Key,_Tp,_Compare,_Alloc>; + friend class multimap<_Key, _Tp, _Compare, _Alloc>; protected: _Compare comp; @@ -134,19 +124,21 @@ namespace _GLIBCXX_STD private: /// @if maint This turns a red-black tree into a [multi]map. @endif - typedef _Rb_tree<key_type, value_type, - _Select1st<value_type>, key_compare, _Alloc> _Rep_type; + typedef typename _Alloc::template rebind<value_type>::other + _Pair_alloc_type; + + typedef _Rb_tree<key_type, value_type, _Select1st<value_type>, + key_compare, _Pair_alloc_type> _Rep_type; /// @if maint The actual tree structure. @endif _Rep_type _M_t; public: // many of these are specified differently in ISO, but the following are // "functionally equivalent" - typedef typename _Alloc::pointer pointer; - typedef typename _Alloc::const_pointer const_pointer; - typedef typename _Alloc::reference reference; - typedef typename _Alloc::const_reference const_reference; - typedef typename _Rep_type::allocator_type allocator_type; + 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; @@ -193,7 +185,7 @@ namespace _GLIBCXX_STD template <typename _InputIterator> multimap(_InputIterator __first, _InputIterator __last) : _M_t(_Compare(), allocator_type()) - { _M_t.insert_equal(__first, __last); } + { _M_t._M_insert_equal(__first, __last); } /** * @brief Builds a %multimap from a range. @@ -211,7 +203,7 @@ namespace _GLIBCXX_STD const _Compare& __comp, const allocator_type& __a = allocator_type()) : _M_t(__comp, __a) - { _M_t.insert_equal(__first, __last); } + { _M_t._M_insert_equal(__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 @@ -345,7 +337,7 @@ namespace _GLIBCXX_STD */ iterator insert(const value_type& __x) - { return _M_t.insert_equal(__x); } + { return _M_t._M_insert_equal(__x); } /** * @brief Inserts a std::pair into the %multimap. @@ -369,7 +361,7 @@ namespace _GLIBCXX_STD */ iterator insert(iterator __position, const value_type& __x) - { return _M_t.insert_equal(__position, __x); } + { return _M_t._M_insert_equal(__position, __x); } /** * @brief A template function that attemps to insert a range of elements. @@ -382,7 +374,7 @@ namespace _GLIBCXX_STD template <typename _InputIterator> void insert(_InputIterator __first, _InputIterator __last) - { _M_t.insert_equal(__first, __last); } + { _M_t._M_insert_equal(__first, __last); } /** * @brief Erases an element from a %multimap. @@ -573,7 +565,7 @@ namespace _GLIBCXX_STD * @endcode * (but is faster than making the calls separately). */ - pair<iterator,iterator> + std::pair<iterator, iterator> equal_range(const key_type& __x) { return _M_t.equal_range(__x); } @@ -590,19 +582,19 @@ namespace _GLIBCXX_STD * @endcode * (but is faster than making the calls separately). */ - pair<const_iterator,const_iterator> + std::pair<const_iterator, const_iterator> 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 multimap<_K1,_T1,_C1,_A1>&, - const multimap<_K1,_T1,_C1,_A1>&); + 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>&); + operator< (const multimap<_K1, _T1, _C1, _A1>&, + const multimap<_K1, _T1, _C1, _A1>&); }; /** @@ -617,8 +609,8 @@ namespace _GLIBCXX_STD */ template <typename _Key, typename _Tp, typename _Compare, typename _Alloc> inline bool - operator==(const multimap<_Key,_Tp,_Compare,_Alloc>& __x, - const multimap<_Key,_Tp,_Compare,_Alloc>& __y) + operator==(const multimap<_Key, _Tp, _Compare, _Alloc>& __x, + const multimap<_Key, _Tp, _Compare, _Alloc>& __y) { return __x._M_t == __y._M_t; } /** @@ -634,44 +626,45 @@ namespace _GLIBCXX_STD */ template <typename _Key, typename _Tp, typename _Compare, typename _Alloc> inline bool - operator<(const multimap<_Key,_Tp,_Compare,_Alloc>& __x, - const multimap<_Key,_Tp,_Compare,_Alloc>& __y) + operator<(const multimap<_Key, _Tp, _Compare, _Alloc>& __x, + const multimap<_Key, _Tp, _Compare, _Alloc>& __y) { return __x._M_t < __y._M_t; } /// Based on operator== template <typename _Key, typename _Tp, typename _Compare, typename _Alloc> inline bool - operator!=(const multimap<_Key,_Tp,_Compare,_Alloc>& __x, - const multimap<_Key,_Tp,_Compare,_Alloc>& __y) + operator!=(const multimap<_Key, _Tp, _Compare, _Alloc>& __x, + const multimap<_Key, _Tp, _Compare, _Alloc>& __y) { return !(__x == __y); } /// Based on operator< template <typename _Key, typename _Tp, typename _Compare, typename _Alloc> inline bool - operator>(const multimap<_Key,_Tp,_Compare,_Alloc>& __x, - const multimap<_Key,_Tp,_Compare,_Alloc>& __y) + operator>(const multimap<_Key, _Tp, _Compare, _Alloc>& __x, + const multimap<_Key, _Tp, _Compare, _Alloc>& __y) { return __y < __x; } /// Based on operator< template <typename _Key, typename _Tp, typename _Compare, typename _Alloc> inline bool - operator<=(const multimap<_Key,_Tp,_Compare,_Alloc>& __x, - const multimap<_Key,_Tp,_Compare,_Alloc>& __y) + operator<=(const multimap<_Key, _Tp, _Compare, _Alloc>& __x, + const multimap<_Key, _Tp, _Compare, _Alloc>& __y) { return !(__y < __x); } /// Based on operator< template <typename _Key, typename _Tp, typename _Compare, typename _Alloc> inline bool - operator>=(const multimap<_Key,_Tp,_Compare,_Alloc>& __x, - const multimap<_Key,_Tp,_Compare,_Alloc>& __y) + operator>=(const multimap<_Key, _Tp, _Compare, _Alloc>& __x, + const multimap<_Key, _Tp, _Compare, _Alloc>& __y) { return !(__x < __y); } /// See std::multimap::swap(). template <typename _Key, typename _Tp, typename _Compare, typename _Alloc> inline void - swap(multimap<_Key,_Tp,_Compare,_Alloc>& __x, - multimap<_Key,_Tp,_Compare,_Alloc>& __y) + swap(multimap<_Key, _Tp, _Compare, _Alloc>& __x, + multimap<_Key, _Tp, _Compare, _Alloc>& __y) { __x.swap(__y); } -} // namespace std + +_GLIBCXX_END_NESTED_NAMESPACE #endif /* _MULTIMAP_H */ diff --git a/contrib/libstdc++/include/bits/stl_multiset.h b/contrib/libstdc++/include/bits/stl_multiset.h index c82dee6..8c499c3 100644 --- a/contrib/libstdc++/include/bits/stl_multiset.h +++ b/contrib/libstdc++/include/bits/stl_multiset.h @@ -1,6 +1,6 @@ // Multiset implementation -*- C++ -*- -// Copyright (C) 2001, 2002, 2004 Free Software Foundation, Inc. +// Copyright (C) 2001, 2002, 2004, 2005, 2006 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 @@ -15,7 +15,7 @@ // 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// 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 @@ -63,23 +63,7 @@ #include <bits/concept_check.h> -namespace _GLIBCXX_STD -{ - - // 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, class _Alloc> - inline bool - operator==(const multiset<_Key,_Compare,_Alloc>& __x, - 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); +_GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD) /** * @brief A standard container made up of elements, which can be retrieved @@ -101,13 +85,16 @@ namespace _GLIBCXX_STD * called (*_unique versus *_equal, same as the standard). * @endif */ - template <class _Key, class _Compare, class _Alloc> + template <class _Key, class _Compare = std::less<_Key>, + class _Alloc = std::allocator<_Key> > class multiset { // concept requirements + typedef typename _Alloc::value_type _Alloc_value_type; __glibcxx_class_requires(_Key, _SGIAssignableConcept) __glibcxx_class_requires4(_Compare, bool, _Key, _Key, _BinaryFunctionConcept) + __glibcxx_class_requires2(_Key, _Alloc_value_type, _SameTypeConcept) public: // typedefs: @@ -115,35 +102,37 @@ namespace _GLIBCXX_STD typedef _Key value_type; typedef _Compare key_compare; typedef _Compare value_compare; + typedef _Alloc allocator_type; private: /// @if maint This turns a red-black tree into a [multi]set. @endif - typedef _Rb_tree<key_type, value_type, - _Identity<value_type>, key_compare, _Alloc> _Rep_type; + typedef typename _Alloc::template rebind<_Key>::other _Key_alloc_type; + + typedef _Rb_tree<key_type, value_type, _Identity<value_type>, + key_compare, _Key_alloc_type> _Rep_type; /// @if maint The actual tree structure. @endif _Rep_type _M_t; public: - typedef typename _Alloc::pointer pointer; - typedef typename _Alloc::const_pointer const_pointer; - typedef typename _Alloc::reference reference; - typedef typename _Alloc::const_reference const_reference; + typedef typename _Key_alloc_type::pointer pointer; + typedef typename _Key_alloc_type::const_pointer const_pointer; + typedef typename _Key_alloc_type::reference reference; + typedef typename _Key_alloc_type::const_reference const_reference; // _GLIBCXX_RESOLVE_LIB_DEFECTS // DR 103. set::iterator is required to be modifiable, // but this allows modification of keys. - typedef typename _Rep_type::const_iterator 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 const_reverse_iterator; - typedef typename _Rep_type::size_type size_type; - typedef typename _Rep_type::difference_type difference_type; - typedef typename _Rep_type::allocator_type allocator_type; - - // allocation/deallocation - - /** - * @brief Default constructor creates no elements. - */ + typedef typename _Rep_type::const_iterator 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 const_reverse_iterator; + typedef typename _Rep_type::size_type size_type; + typedef typename _Rep_type::difference_type difference_type; + + // allocation/deallocation + + /** + * @brief Default constructor creates no elements. + */ multiset() : _M_t(_Compare(), allocator_type()) { } @@ -164,7 +153,7 @@ namespace _GLIBCXX_STD template <class _InputIterator> multiset(_InputIterator __first, _InputIterator __last) : _M_t(_Compare(), allocator_type()) - { _M_t.insert_equal(__first, __last); } + { _M_t._M_insert_equal(__first, __last); } /** * @brief Builds a %multiset from a range. @@ -182,7 +171,7 @@ namespace _GLIBCXX_STD const _Compare& __comp, const allocator_type& __a = allocator_type()) : _M_t(__comp, __a) - { _M_t.insert_equal(__first, __last); } + { _M_t._M_insert_equal(__first, __last); } /** * @brief %Multiset copy constructor. @@ -286,7 +275,7 @@ namespace _GLIBCXX_STD * std::swap(s1,s2) will feed to this function. */ void - swap(multiset<_Key,_Compare,_Alloc>& __x) + swap(multiset<_Key, _Compare, _Alloc>& __x) { _M_t.swap(__x._M_t); } // insert/erase @@ -303,7 +292,7 @@ namespace _GLIBCXX_STD */ iterator insert(const value_type& __x) - { return _M_t.insert_equal(__x); } + { return _M_t._M_insert_equal(__x); } /** * @brief Inserts an element into the %multiset. @@ -327,10 +316,7 @@ namespace _GLIBCXX_STD */ iterator insert(iterator __position, const value_type& __x) - { - typedef typename _Rep_type::iterator _Rep_iterator; - return _M_t.insert_equal((_Rep_iterator&)__position, __x); - } + { return _M_t._M_insert_equal(__position, __x); } /** * @brief A template function that attemps to insert a range of elements. @@ -343,7 +329,7 @@ namespace _GLIBCXX_STD template <class _InputIterator> void insert(_InputIterator __first, _InputIterator __last) - { _M_t.insert_equal(__first, __last); } + { _M_t._M_insert_equal(__first, __last); } /** * @brief Erases an element from a %multiset. @@ -357,10 +343,7 @@ namespace _GLIBCXX_STD */ void erase(iterator __position) - { - typedef typename _Rep_type::iterator _Rep_iterator; - _M_t.erase((_Rep_iterator&)__position); - } + { _M_t.erase(__position); } /** * @brief Erases elements according to the provided key. @@ -390,10 +373,7 @@ namespace _GLIBCXX_STD */ void erase(iterator __first, iterator __last) - { - typedef typename _Rep_type::iterator _Rep_iterator; - _M_t.erase((_Rep_iterator&)__first, (_Rep_iterator&)__last); - } + { _M_t.erase(__first, __last); } /** * Erases all elements in a %multiset. Note that this function only @@ -492,23 +472,23 @@ namespace _GLIBCXX_STD * * This function probably only makes sense for multisets. */ - pair<iterator,iterator> + std::pair<iterator, iterator> equal_range(const key_type& __x) { return _M_t.equal_range(__x); } - pair<const_iterator,const_iterator> + std::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>&); + 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>&); + operator< (const multiset<_K1, _C1, _A1>&, + const multiset<_K1, _C1, _A1>&); }; /** @@ -524,8 +504,8 @@ namespace _GLIBCXX_STD */ template <class _Key, class _Compare, class _Alloc> inline bool - operator==(const multiset<_Key,_Compare,_Alloc>& __x, - const multiset<_Key,_Compare,_Alloc>& __y) + operator==(const multiset<_Key, _Compare, _Alloc>& __x, + const multiset<_Key, _Compare, _Alloc>& __y) { return __x._M_t == __y._M_t; } /** @@ -541,15 +521,15 @@ namespace _GLIBCXX_STD */ template <class _Key, class _Compare, class _Alloc> inline bool - operator<(const multiset<_Key,_Compare,_Alloc>& __x, - const multiset<_Key,_Compare,_Alloc>& __y) + operator<(const multiset<_Key, _Compare, _Alloc>& __x, + const multiset<_Key, _Compare, _Alloc>& __y) { return __x._M_t < __y._M_t; } /// Returns !(x == y). template <class _Key, class _Compare, class _Alloc> inline bool - operator!=(const multiset<_Key,_Compare,_Alloc>& __x, - const multiset<_Key,_Compare,_Alloc>& __y) + operator!=(const multiset<_Key, _Compare, _Alloc>& __x, + const multiset<_Key, _Compare, _Alloc>& __y) { return !(__x == __y); } /// Returns y < x. @@ -562,24 +542,24 @@ namespace _GLIBCXX_STD /// Returns !(y < x) template <class _Key, class _Compare, class _Alloc> inline bool - operator<=(const multiset<_Key,_Compare,_Alloc>& __x, - const multiset<_Key,_Compare,_Alloc>& __y) + operator<=(const multiset<_Key, _Compare, _Alloc>& __x, + const multiset<_Key, _Compare, _Alloc>& __y) { return !(__y < __x); } /// Returns !(x < y) template <class _Key, class _Compare, class _Alloc> inline bool - operator>=(const multiset<_Key,_Compare,_Alloc>& __x, - const multiset<_Key,_Compare,_Alloc>& __y) + operator>=(const multiset<_Key, _Compare, _Alloc>& __x, + const multiset<_Key, _Compare, _Alloc>& __y) { return !(__x < __y); } /// See std::multiset::swap(). template <class _Key, class _Compare, class _Alloc> inline void - swap(multiset<_Key,_Compare,_Alloc>& __x, - multiset<_Key,_Compare,_Alloc>& __y) + swap(multiset<_Key, _Compare, _Alloc>& __x, + multiset<_Key, _Compare, _Alloc>& __y) { __x.swap(__y); } -} // namespace std +_GLIBCXX_END_NESTED_NAMESPACE #endif /* _MULTISET_H */ diff --git a/contrib/libstdc++/include/bits/stl_numeric.h b/contrib/libstdc++/include/bits/stl_numeric.h index 58762a4..82bee21 100644 --- a/contrib/libstdc++/include/bits/stl_numeric.h +++ b/contrib/libstdc++/include/bits/stl_numeric.h @@ -1,6 +1,6 @@ // Numeric functions implementation -*- C++ -*- -// Copyright (C) 2001, 2004 Free Software Foundation, Inc. +// Copyright (C) 2001, 2004, 2005 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 @@ -15,7 +15,7 @@ // 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// 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 @@ -63,8 +63,7 @@ #include <debug/debug.h> -namespace std -{ +_GLIBCXX_BEGIN_NAMESPACE(std) /** * @brief Accumulate values in a range. @@ -85,7 +84,7 @@ namespace std __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>) __glibcxx_requires_valid_range(__first, __last); - for ( ; __first != __last; ++__first) + for (; __first != __last; ++__first) __init = __init + *__first; return __init; } @@ -112,7 +111,7 @@ namespace std __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>) __glibcxx_requires_valid_range(__first, __last); - for ( ; __first != __last; ++__first) + for (; __first != __last; ++__first) __init = __binary_op(__init, *__first); return __init; } @@ -141,7 +140,7 @@ namespace std __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>) __glibcxx_requires_valid_range(__first1, __last1); - for ( ; __first1 != __last1; ++__first1, ++__first2) + for (; __first1 != __last1; ++__first1, ++__first2) __init = __init + (*__first1 * *__first2); return __init; } @@ -175,7 +174,7 @@ namespace std __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>) __glibcxx_requires_valid_range(__first1, __last1); - for ( ; __first1 != __last1; ++__first1, ++__first2) + for (; __first1 != __last1; ++__first1, ++__first2) __init = __binary_op1(__init, __binary_op2(*__first1, *__first2)); return __init; } @@ -203,16 +202,19 @@ namespace std // concept requirements __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>) - __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator, _ValueType>) + __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator, + _ValueType>) __glibcxx_requires_valid_range(__first, __last); - if (__first == __last) return __result; - *__result = *__first; + if (__first == __last) + return __result; _ValueType __value = *__first; - while (++__first != __last) { - __value = __value + *__first; - *++__result = __value; - } + *__result = __value; + while (++__first != __last) + { + __value = __value + *__first; + *++__result = __value; + } return ++__result; } @@ -230,7 +232,8 @@ namespace std * @param result Output to write sums to. * @return Iterator pointing just beyond the values written to result. */ - template<typename _InputIterator, typename _OutputIterator, typename _BinaryOperation> + template<typename _InputIterator, typename _OutputIterator, + typename _BinaryOperation> _OutputIterator partial_sum(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _BinaryOperation __binary_op) @@ -239,16 +242,19 @@ namespace std // concept requirements __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>) - __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator, _ValueType>) + __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator, + _ValueType>) __glibcxx_requires_valid_range(__first, __last); - if (__first == __last) return __result; - *__result = *__first; + if (__first == __last) + return __result; _ValueType __value = *__first; - while (++__first != __last) { - __value = __binary_op(__value, *__first); - *++__result = __value; - } + *__result = __value; + while (++__first != __last) + { + __value = __binary_op(__value, *__first); + *++__result = __value; + } return ++__result; } @@ -272,17 +278,20 @@ namespace std // concept requirements __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>) - __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator, _ValueType>) + __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator, + _ValueType>) __glibcxx_requires_valid_range(__first, __last); - if (__first == __last) return __result; - *__result = *__first; + if (__first == __last) + return __result; _ValueType __value = *__first; - while (++__first != __last) { - _ValueType __tmp = *__first; - *++__result = __tmp - __value; - __value = __tmp; - } + *__result = __value; + while (++__first != __last) + { + _ValueType __tmp = *__first; + *++__result = __tmp - __value; + __value = __tmp; + } return ++__result; } @@ -298,7 +307,8 @@ namespace std * @param result Output to write sums to. * @return Iterator pointing just beyond the values written to result. */ - template<typename _InputIterator, typename _OutputIterator, typename _BinaryOperation> + template<typename _InputIterator, typename _OutputIterator, + typename _BinaryOperation> _OutputIterator adjacent_difference(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _BinaryOperation __binary_op) @@ -307,20 +317,23 @@ namespace std // concept requirements __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>) - __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator, _ValueType>) + __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator, + _ValueType>) __glibcxx_requires_valid_range(__first, __last); - if (__first == __last) return __result; - *__result = *__first; + if (__first == __last) + return __result; _ValueType __value = *__first; - while (++__first != __last) { - _ValueType __tmp = *__first; - *++__result = __binary_op(__tmp, __value); - __value = __tmp; - } + *__result = __value; + while (++__first != __last) + { + _ValueType __tmp = *__first; + *++__result = __binary_op(__tmp, __value); + __value = __tmp; + } return ++__result; } -} // namespace std +_GLIBCXX_END_NAMESPACE #endif /* _STL_NUMERIC_H */ diff --git a/contrib/libstdc++/include/bits/stl_pair.h b/contrib/libstdc++/include/bits/stl_pair.h index d5146bb..b4bb00c 100644 --- a/contrib/libstdc++/include/bits/stl_pair.h +++ b/contrib/libstdc++/include/bits/stl_pair.h @@ -1,6 +1,6 @@ // Pair implementation -*- C++ -*- -// Copyright (C) 2001, 2004 Free Software Foundation, Inc. +// Copyright (C) 2001, 2004, 2005 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 @@ -15,7 +15,7 @@ // 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// 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 @@ -61,8 +61,8 @@ #ifndef _PAIR_H #define _PAIR_H 1 -namespace std -{ +_GLIBCXX_BEGIN_NAMESPACE(std) + /// pair holds two objects of arbitrary type. template<class _T1, class _T2> struct pair @@ -141,7 +141,9 @@ namespace std // 181. make_pair() unintended behavior template<class _T1, class _T2> inline pair<_T1, _T2> - make_pair(_T1 __x, _T2 __y) { return pair<_T1, _T2>(__x, __y); } -} // namespace std + make_pair(_T1 __x, _T2 __y) + { return pair<_T1, _T2>(__x, __y); } + +_GLIBCXX_END_NAMESPACE #endif /* _PAIR_H */ diff --git a/contrib/libstdc++/include/bits/stl_queue.h b/contrib/libstdc++/include/bits/stl_queue.h index 3583547..04e3a7b 100644 --- a/contrib/libstdc++/include/bits/stl_queue.h +++ b/contrib/libstdc++/include/bits/stl_queue.h @@ -1,6 +1,7 @@ // Queue implementation -*- C++ -*- -// Copyright (C) 2001, 2002, 2003, 2004 Free Software Foundation, Inc. +// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 +// 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 @@ -15,7 +16,7 @@ // 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// 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 @@ -64,19 +65,7 @@ #include <bits/concept_check.h> #include <debug/debug.h> -namespace std -{ - // Forward declarations of operators < and ==, needed for friend declaration. - template<typename _Tp, typename _Sequence = deque<_Tp> > - class queue; - - template<typename _Tp, typename _Seq> - inline bool - operator==(const queue<_Tp,_Seq>&, const queue<_Tp,_Seq>&); - - template<typename _Tp, typename _Seq> - inline bool - operator<(const queue<_Tp,_Seq>&, const queue<_Tp,_Seq>&); +_GLIBCXX_BEGIN_NAMESPACE(std) /** * @brief A standard container giving FIFO behavior. @@ -102,7 +91,7 @@ namespace std * which is a typedef for the second Sequence parameter, and @c push and * @c pop, which are standard %queue/FIFO operations. */ - template<typename _Tp, typename _Sequence> + template<typename _Tp, typename _Sequence = deque<_Tp> > class queue { // concept requirements @@ -245,10 +234,9 @@ namespace std * linear in the size of the sequences, and queues are considered equivalent * if their sequences compare equal. */ - template<typename _Tp, typename _Sequence> + template<typename _Tp, typename _Seq> inline bool - operator==(const queue<_Tp,_Sequence>& __x, - const queue<_Tp,_Sequence>& __y) + operator==(const queue<_Tp, _Seq>& __x, const queue<_Tp, _Seq>& __y) { return __x.c == __y.c; } /** @@ -264,36 +252,33 @@ namespace std * std::lexicographical_compare() is usually used to make the * determination. */ - template<typename _Tp, typename _Sequence> + template<typename _Tp, typename _Seq> inline bool - operator<(const queue<_Tp,_Sequence>& __x, const queue<_Tp,_Sequence>& __y) + operator<(const queue<_Tp, _Seq>& __x, const queue<_Tp, _Seq>& __y) { return __x.c < __y.c; } /// Based on operator== - template<typename _Tp, typename _Sequence> + template<typename _Tp, typename _Seq> inline bool - operator!=(const queue<_Tp,_Sequence>& __x, - const queue<_Tp,_Sequence>& __y) + operator!=(const queue<_Tp, _Seq>& __x, const queue<_Tp, _Seq>& __y) { return !(__x == __y); } /// Based on operator< - template<typename _Tp, typename _Sequence> + template<typename _Tp, typename _Seq> inline bool - operator>(const queue<_Tp,_Sequence>& __x, const queue<_Tp,_Sequence>& __y) + operator>(const queue<_Tp, _Seq>& __x, const queue<_Tp, _Seq>& __y) { return __y < __x; } /// Based on operator< - template<typename _Tp, typename _Sequence> + template<typename _Tp, typename _Seq> inline bool - operator<=(const queue<_Tp,_Sequence>& __x, - const queue<_Tp,_Sequence>& __y) + operator<=(const queue<_Tp, _Seq>& __x, const queue<_Tp, _Seq>& __y) { return !(__y < __x); } /// Based on operator< - template<typename _Tp, typename _Sequence> + template<typename _Tp, typename _Seq> inline bool - operator>=(const queue<_Tp,_Sequence>& __x, - const queue<_Tp,_Sequence>& __y) + operator>=(const queue<_Tp, _Seq>& __x, const queue<_Tp, _Seq>& __y) { return !(__x < __y); } /** @@ -304,10 +289,9 @@ namespace std * * This is not a true container, but an @e adaptor. It holds * another container, and provides a wrapper interface to that - * container. The wrapper is what enforces sorting and - * first-in-first-out %queue behavior. Very few of the standard - * container/sequence interface requirements are met (e.g., - * iterators). + * container. The wrapper is what enforces priority-based sorting + * and %queue behavior. Very few of the standard container/sequence + * interface requirements are met (e.g., iterators). * * The second template parameter defines the type of the underlying * sequence/container. It defaults to std::vector, but it can be @@ -321,8 +305,7 @@ namespace std * * Members not found in "normal" containers are @c container_type, * which is a typedef for the second Sequence parameter, and @c - * push, @c pop, and @c top, which are standard %queue/FIFO - * operations. + * push, @c pop, and @c top, which are standard %queue operations. * * @note No equality/comparison operators are provided for * %priority_queue. @@ -344,7 +327,8 @@ namespace std __glibcxx_class_requires(_Sequence, _SequenceConcept) __glibcxx_class_requires(_Sequence, _RandomAccessContainerConcept) __glibcxx_class_requires2(_Tp, _Sequence_value_type, _SameTypeConcept) - __glibcxx_class_requires4(_Compare, bool, _Tp,_Tp,_BinaryFunctionConcept) + __glibcxx_class_requires4(_Compare, bool, _Tp, _Tp, + _BinaryFunctionConcept) public: typedef typename _Sequence::value_type value_type; @@ -398,11 +382,13 @@ namespace std * Returns true if the %queue is empty. */ bool - empty() const { return c.empty(); } + empty() const + { return c.empty(); } /** Returns the number of elements in the %queue. */ size_type - size() const { return c.size(); } + size() const + { return c.size(); } /** * Returns a read-only (constant) reference to the data at the first @@ -426,16 +412,8 @@ namespace std void push(const value_type& __x) { - try - { - c.push_back(__x); - std::push_heap(c.begin(), c.end(), comp); - } - catch(...) - { - c.clear(); - __throw_exception_again; - } + c.push_back(__x); + std::push_heap(c.begin(), c.end(), comp); } /** @@ -453,20 +431,13 @@ namespace std pop() { __glibcxx_requires_nonempty(); - try - { - std::pop_heap(c.begin(), c.end(), comp); - c.pop_back(); - } - catch(...) - { - c.clear(); - __throw_exception_again; - } + std::pop_heap(c.begin(), c.end(), comp); + c.pop_back(); } }; // No equality/comparison operators are provided for priority_queue. -} // namespace std + +_GLIBCXX_END_NAMESPACE #endif /* _QUEUE_H */ diff --git a/contrib/libstdc++/include/bits/stl_raw_storage_iter.h b/contrib/libstdc++/include/bits/stl_raw_storage_iter.h index 732142e..615da28 100644 --- a/contrib/libstdc++/include/bits/stl_raw_storage_iter.h +++ b/contrib/libstdc++/include/bits/stl_raw_storage_iter.h @@ -1,6 +1,6 @@ // -*- C++ -*- -// Copyright (C) 2001, 2004 Free Software Foundation, Inc. +// Copyright (C) 2001, 2004, 2005 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 @@ -15,7 +15,7 @@ // 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// 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 @@ -61,8 +61,8 @@ #ifndef _STL_RAW_STORAGE_ITERATOR_H #define _STL_RAW_STORAGE_ITERATOR_H 1 -namespace std -{ +_GLIBCXX_BEGIN_NAMESPACE(std) + /** * This iterator class lets algorithms store their results into * uninitialized memory. @@ -104,10 +104,7 @@ namespace std return __tmp; } }; -} // namespace std -#endif +_GLIBCXX_END_NAMESPACE -// Local Variables: -// mode:C++ -// End: +#endif diff --git a/contrib/libstdc++/include/bits/stl_relops.h b/contrib/libstdc++/include/bits/stl_relops.h index 3e9f060..11fc30d 100644 --- a/contrib/libstdc++/include/bits/stl_relops.h +++ b/contrib/libstdc++/include/bits/stl_relops.h @@ -1,6 +1,6 @@ // std::rel_ops implementation -*- C++ -*- -// Copyright (C) 2001, 2002, 2004 Free Software Foundation, Inc. +// Copyright (C) 2001, 2002, 2004, 2005 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 @@ -15,7 +15,7 @@ // 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// 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 @@ -71,8 +71,8 @@ #ifndef _STL_RELOPS_H #define _STL_RELOPS_H 1 -namespace std -{ +_GLIBCXX_BEGIN_NAMESPACE(std) + namespace rel_ops { /** @namespace std::rel_ops @@ -132,6 +132,7 @@ namespace std { return !(__x < __y); } } // namespace rel_ops -} // namespace std + +_GLIBCXX_END_NAMESPACE #endif /* _STL_RELOPS_H */ diff --git a/contrib/libstdc++/include/bits/stl_set.h b/contrib/libstdc++/include/bits/stl_set.h index bb28bdd..b61106a 100644 --- a/contrib/libstdc++/include/bits/stl_set.h +++ b/contrib/libstdc++/include/bits/stl_set.h @@ -1,6 +1,6 @@ // Set implementation -*- C++ -*- -// Copyright (C) 2001, 2002, 2004 Free Software Foundation, Inc. +// Copyright (C) 2001, 2002, 2004, 2005, 2006 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 @@ -15,7 +15,7 @@ // 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// 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 @@ -63,22 +63,7 @@ #include <bits/concept_check.h> -namespace _GLIBCXX_STD -{ - // Forward declarations of operators < and ==, needed for friend declaration. - template<class _Key, class _Compare = less<_Key>, - class _Alloc = allocator<_Key> > - class set; - - template<class _Key, class _Compare, class _Alloc> - inline bool - operator==(const set<_Key,_Compare,_Alloc>& __x, - const set<_Key,_Compare,_Alloc>& __y); - - template<class _Key, class _Compare, class _Alloc> - inline bool - operator<(const set<_Key,_Compare,_Alloc>& __x, - const set<_Key,_Compare,_Alloc>& __y); +_GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD) /** * @brief A standard container made up of unique keys, which can be @@ -103,13 +88,16 @@ namespace _GLIBCXX_STD * called (*_unique versus *_equal, same as the standard). * @endif */ - template<class _Key, class _Compare, class _Alloc> + template<class _Key, class _Compare = std::less<_Key>, + class _Alloc = std::allocator<_Key> > class set { // concept requirements + typedef typename _Alloc::value_type _Alloc_value_type; __glibcxx_class_requires(_Key, _SGIAssignableConcept) __glibcxx_class_requires4(_Compare, bool, _Key, _Key, _BinaryFunctionConcept) + __glibcxx_class_requires2(_Key, _Alloc_value_type, _SameTypeConcept) public: // typedefs: @@ -119,29 +107,32 @@ namespace _GLIBCXX_STD typedef _Key value_type; typedef _Compare key_compare; typedef _Compare value_compare; + typedef _Alloc allocator_type; //@} private: - typedef _Rb_tree<key_type, value_type, - _Identity<value_type>, key_compare, _Alloc> _Rep_type; + typedef typename _Alloc::template rebind<_Key>::other _Key_alloc_type; + + typedef _Rb_tree<key_type, value_type, _Identity<value_type>, + key_compare, _Key_alloc_type> _Rep_type; _Rep_type _M_t; // red-black tree representing set + public: //@{ /// Iterator-related typedefs. - typedef typename _Alloc::pointer pointer; - typedef typename _Alloc::const_pointer const_pointer; - typedef typename _Alloc::reference reference; - typedef typename _Alloc::const_reference const_reference; + typedef typename _Key_alloc_type::pointer pointer; + typedef typename _Key_alloc_type::const_pointer const_pointer; + typedef typename _Key_alloc_type::reference reference; + typedef typename _Key_alloc_type::const_reference const_reference; // _GLIBCXX_RESOLVE_LIB_DEFECTS // DR 103. set::iterator is required to be modifiable, // but this allows modification of keys. - typedef typename _Rep_type::const_iterator 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 const_reverse_iterator; - typedef typename _Rep_type::size_type size_type; - typedef typename _Rep_type::difference_type difference_type; - typedef typename _Rep_type::allocator_type allocator_type; + typedef typename _Rep_type::const_iterator 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 const_reverse_iterator; + typedef typename _Rep_type::size_type size_type; + typedef typename _Rep_type::difference_type difference_type; //@} // allocation/deallocation @@ -155,8 +146,9 @@ namespace _GLIBCXX_STD * @param comp Comparator to use. * @param a Allocator to use. */ - explicit set(const _Compare& __comp, - const allocator_type& __a = allocator_type()) + explicit + set(const _Compare& __comp, + const allocator_type& __a = allocator_type()) : _M_t(__comp, __a) {} /** @@ -171,7 +163,7 @@ namespace _GLIBCXX_STD template<class _InputIterator> set(_InputIterator __first, _InputIterator __last) : _M_t(_Compare(), allocator_type()) - { _M_t.insert_unique(__first, __last); } + { _M_t._M_insert_unique(__first, __last); } /** * @brief Builds a %set from a range. @@ -189,7 +181,7 @@ namespace _GLIBCXX_STD const _Compare& __comp, const allocator_type& __a = allocator_type()) : _M_t(__comp, __a) - { _M_t.insert_unique(__first, __last); } + { _M_t._M_insert_unique(__first, __last); } /** * @brief Set copy constructor. @@ -308,11 +300,12 @@ namespace _GLIBCXX_STD * * Insertion requires logarithmic time. */ - pair<iterator,bool> + std::pair<iterator,bool> insert(const value_type& __x) { - pair<typename _Rep_type::iterator, bool> __p = _M_t.insert_unique(__x); - return pair<iterator, bool>(__p.first, __p.second); + std::pair<typename _Rep_type::iterator, bool> __p = + _M_t._M_insert_unique(__x); + return std::pair<iterator, bool>(__p.first, __p.second); } /** @@ -336,10 +329,7 @@ namespace _GLIBCXX_STD */ iterator insert(iterator __position, const value_type& __x) - { - typedef typename _Rep_type::iterator _Rep_iterator; - return _M_t.insert_unique((_Rep_iterator&)__position, __x); - } + { return _M_t._M_insert_unique(__position, __x); } /** * @brief A template function that attemps to insert a range of elements. @@ -350,9 +340,9 @@ namespace _GLIBCXX_STD * Complexity similar to that of the range constructor. */ template<class _InputIterator> - void - insert(_InputIterator __first, _InputIterator __last) - { _M_t.insert_unique(__first, __last); } + void + insert(_InputIterator __first, _InputIterator __last) + { _M_t._M_insert_unique(__first, __last); } /** * @brief Erases an element from a %set. @@ -365,10 +355,7 @@ namespace _GLIBCXX_STD */ void erase(iterator __position) - { - typedef typename _Rep_type::iterator _Rep_iterator; - _M_t.erase((_Rep_iterator&)__position); - } + { _M_t.erase(__position); } /** * @brief Erases elements according to the provided key. @@ -382,7 +369,8 @@ namespace _GLIBCXX_STD * in any way. Managing the pointer is the user's responsibilty. */ size_type - erase(const key_type& __x) { return _M_t.erase(__x); } + erase(const key_type& __x) + { return _M_t.erase(__x); } /** * @brief Erases a [first,last) range of elements from a %set. @@ -397,10 +385,7 @@ namespace _GLIBCXX_STD */ void erase(iterator __first, iterator __last) - { - typedef typename _Rep_type::iterator _Rep_iterator; - _M_t.erase((_Rep_iterator&)__first, (_Rep_iterator&)__last); - } + { _M_t.erase(__first, __last); } /** * Erases all elements in a %set. Note that this function only erases @@ -502,22 +487,22 @@ namespace _GLIBCXX_STD * * This function probably only makes sense for multisets. */ - pair<iterator,iterator> + std::pair<iterator, iterator> equal_range(const key_type& __x) { return _M_t.equal_range(__x); } - pair<const_iterator,const_iterator> + std::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 set<_K1,_C1,_A1>&, const set<_K1,_C1,_A1>&); + operator== (const set<_K1, _C1, _A1>&, const set<_K1, _C1, _A1>&); template<class _K1, class _C1, class _A1> friend bool - operator< (const set<_K1,_C1,_A1>&, const set<_K1,_C1,_A1>&); + operator< (const set<_K1, _C1, _A1>&, const set<_K1, _C1, _A1>&); }; @@ -533,8 +518,8 @@ namespace _GLIBCXX_STD */ template<class _Key, class _Compare, class _Alloc> inline bool - operator==(const set<_Key,_Compare,_Alloc>& __x, - const set<_Key,_Compare,_Alloc>& __y) + operator==(const set<_Key, _Compare, _Alloc>& __x, + const set<_Key, _Compare, _Alloc>& __y) { return __x._M_t == __y._M_t; } /** @@ -550,44 +535,44 @@ namespace _GLIBCXX_STD */ template<class _Key, class _Compare, class _Alloc> inline bool - operator<(const set<_Key,_Compare,_Alloc>& __x, - const set<_Key,_Compare,_Alloc>& __y) + operator<(const set<_Key, _Compare, _Alloc>& __x, + const set<_Key, _Compare, _Alloc>& __y) { return __x._M_t < __y._M_t; } /// Returns !(x == y). template<class _Key, class _Compare, class _Alloc> inline bool - operator!=(const set<_Key,_Compare,_Alloc>& __x, - const set<_Key,_Compare,_Alloc>& __y) + operator!=(const set<_Key, _Compare, _Alloc>& __x, + const set<_Key, _Compare, _Alloc>& __y) { return !(__x == __y); } /// Returns y < x. template<class _Key, class _Compare, class _Alloc> inline bool - operator>(const set<_Key,_Compare,_Alloc>& __x, - const set<_Key,_Compare,_Alloc>& __y) + operator>(const set<_Key, _Compare, _Alloc>& __x, + const set<_Key, _Compare, _Alloc>& __y) { return __y < __x; } /// Returns !(y < x) template<class _Key, class _Compare, class _Alloc> inline bool - operator<=(const set<_Key,_Compare,_Alloc>& __x, - const set<_Key,_Compare,_Alloc>& __y) + operator<=(const set<_Key, _Compare, _Alloc>& __x, + const set<_Key, _Compare, _Alloc>& __y) { return !(__y < __x); } /// Returns !(x < y) template<class _Key, class _Compare, class _Alloc> inline bool - operator>=(const set<_Key,_Compare,_Alloc>& __x, - const set<_Key,_Compare,_Alloc>& __y) + operator>=(const set<_Key, _Compare, _Alloc>& __x, + const set<_Key, _Compare, _Alloc>& __y) { return !(__x < __y); } /// See std::set::swap(). template<class _Key, class _Compare, class _Alloc> inline void - swap(set<_Key,_Compare,_Alloc>& __x, set<_Key,_Compare,_Alloc>& __y) + swap(set<_Key, _Compare, _Alloc>& __x, set<_Key, _Compare, _Alloc>& __y) { __x.swap(__y); } -} // namespace std +_GLIBCXX_END_NESTED_NAMESPACE #endif /* _SET_H */ diff --git a/contrib/libstdc++/include/bits/stl_stack.h b/contrib/libstdc++/include/bits/stl_stack.h index ada50ee..f5b41fa 100644 --- a/contrib/libstdc++/include/bits/stl_stack.h +++ b/contrib/libstdc++/include/bits/stl_stack.h @@ -1,6 +1,7 @@ // Stack implementation -*- C++ -*- -// Copyright (C) 2001, 2002, 2004 Free Software Foundation, Inc. +// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 +// 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 @@ -15,7 +16,7 @@ // 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// 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 @@ -64,20 +65,7 @@ #include <bits/concept_check.h> #include <debug/debug.h> -namespace std -{ - // Forward declarations of operators == and <, needed for friend - // declaration. - template<typename _Tp, typename _Sequence = deque<_Tp> > - class stack; - - template<typename _Tp, typename _Seq> - inline bool - operator==(const stack<_Tp,_Seq>& __x, const stack<_Tp,_Seq>& __y); - - template<typename _Tp, typename _Seq> - inline bool - operator<(const stack<_Tp,_Seq>& __x, const stack<_Tp,_Seq>& __y); +_GLIBCXX_BEGIN_NAMESPACE(std) /** * @brief A standard container giving FILO behavior. @@ -106,7 +94,7 @@ namespace std * push, @c pop, and @c top, which are standard %stack/FILO * operations. */ - template<typename _Tp, typename _Sequence> + template<typename _Tp, typename _Sequence = deque<_Tp> > class stack { // concept requirements @@ -141,7 +129,7 @@ namespace std */ explicit stack(const _Sequence& __c = _Sequence()) - : c(__c) {} + : c(__c) { } /** * Returns true if the %stack is empty. @@ -267,6 +255,7 @@ namespace std inline bool operator>=(const stack<_Tp, _Seq>& __x, const stack<_Tp, _Seq>& __y) { return !(__x < __y); } -} // namespace std + +_GLIBCXX_END_NAMESPACE #endif /* _STACK_H */ diff --git a/contrib/libstdc++/include/bits/stl_tempbuf.h b/contrib/libstdc++/include/bits/stl_tempbuf.h index 399cffb..fbe24e7 100644 --- a/contrib/libstdc++/include/bits/stl_tempbuf.h +++ b/contrib/libstdc++/include/bits/stl_tempbuf.h @@ -1,6 +1,7 @@ // Temporary buffer implementation -*- C++ -*- -// Copyright (C) 2001, 2002, 2004 Free Software Foundation, Inc. +// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 +// 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 @@ -15,7 +16,7 @@ // 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// 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 @@ -63,8 +64,8 @@ #include <memory> -namespace std -{ +_GLIBCXX_BEGIN_NAMESPACE(std) + /** * @if maint * This class is used in two places: stl_algo.h and ext/memory, @@ -78,7 +79,7 @@ namespace std // concept requirements __glibcxx_class_requires(_ForwardIterator, _ForwardIteratorConcept) - public: + public: typedef _Tp value_type; typedef value_type* pointer; typedef pointer iterator; @@ -93,8 +94,8 @@ namespace std _M_initialize_buffer(const _Tp&, __true_type) { } void - _M_initialize_buffer(const _Tp& val, __false_type) - { std::uninitialized_fill_n(_M_buffer, _M_len, val); } + _M_initialize_buffer(const _Tp& __val, __false_type) + { std::uninitialized_fill_n(_M_buffer, _M_len, __val); } public: /// As per Table mumble. @@ -145,8 +146,7 @@ namespace std _M_len(0), _M_buffer(0) { // Workaround for a __type_traits bug in the pre-7.3 compiler. - typedef typename __type_traits<_Tp>::has_trivial_default_constructor - _Trivial; + typedef typename std::__is_scalar<_Tp>::__type _Trivial; try { @@ -165,7 +165,8 @@ namespace std __throw_exception_again; } } -} // namespace std + +_GLIBCXX_END_NAMESPACE #endif /* _TEMPBUF_H */ diff --git a/contrib/libstdc++/include/bits/stl_tree.h b/contrib/libstdc++/include/bits/stl_tree.h index cea16f1..22e132f 100644 --- a/contrib/libstdc++/include/bits/stl_tree.h +++ b/contrib/libstdc++/include/bits/stl_tree.h @@ -1,6 +1,7 @@ // RB tree implementation -*- C++ -*- -// Copyright (C) 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. +// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 +// 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 @@ -15,7 +16,7 @@ // 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// 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 @@ -69,8 +70,8 @@ #include <bits/stl_function.h> #include <bits/cpp_type_traits.h> -namespace std -{ +_GLIBCXX_BEGIN_NAMESPACE(std) + // Red-black tree class, designed for use in implementing STL // associative containers (set, multiset, map, and multimap). The // insertion and deletion algorithms are based on those in Cormen, @@ -164,6 +165,7 @@ namespace std _Rb_tree_iterator() : _M_node() { } + explicit _Rb_tree_iterator(_Link_type __x) : _M_node(__x) { } @@ -235,6 +237,7 @@ namespace std _Rb_tree_const_iterator() : _M_node() { } + explicit _Rb_tree_const_iterator(_Link_type __x) : _M_node(__x) { } @@ -346,10 +349,18 @@ namespace std typedef ptrdiff_t difference_type; typedef _Alloc allocator_type; - allocator_type - get_allocator() const + _Node_allocator& + _M_get_Node_allocator() + { return *static_cast<_Node_allocator*>(&this->_M_impl); } + + const _Node_allocator& + _M_get_Node_allocator() const { return *static_cast<const _Node_allocator*>(&this->_M_impl); } + allocator_type + get_allocator() const + { return allocator_type(_M_get_Node_allocator()); } + protected: _Rb_tree_node* _M_get_node() @@ -364,7 +375,7 @@ namespace std { _Link_type __tmp = _M_get_node(); try - { std::_Construct(&__tmp->_M_value_field, __x); } + { get_allocator().construct(&__tmp->_M_value_field, __x); } catch(...) { _M_put_node(__tmp); @@ -384,15 +395,15 @@ namespace std } void - destroy_node(_Link_type __p) + _M_destroy_node(_Link_type __p) { - std::_Destroy(&__p->_M_value_field); + get_allocator().destroy(&__p->_M_value_field); _M_put_node(__p); } protected: template<typename _Key_compare, - bool _Is_pod_comparator = std::__is_pod<_Key_compare>::_M_type> + bool _Is_pod_comparator = std::__is_pod<_Key_compare>::__value> struct _Rb_tree_impl : public _Node_allocator { _Key_compare _M_key_compare; @@ -401,7 +412,8 @@ namespace std _Rb_tree_impl(const _Node_allocator& __a = _Node_allocator(), const _Key_compare& __comp = _Key_compare()) - : _Node_allocator(__a), _M_key_compare(__comp), _M_node_count(0) + : _Node_allocator(__a), _M_key_compare(__comp), _M_header(), + _M_node_count(0) { this->_M_header._M_color = _S_red; this->_M_header._M_parent = 0; @@ -421,7 +433,8 @@ namespace std _Rb_tree_impl(const _Node_allocator& __a = _Node_allocator(), const _Key_compare& __comp = _Key_compare()) - : _Node_allocator(__a), _M_key_compare(__comp), _M_node_count(0) + : _Node_allocator(__a), _M_key_compare(__comp), _M_header(), + _M_node_count(0) { this->_M_header._M_color = _S_red; this->_M_header._M_parent = 0; @@ -463,7 +476,10 @@ namespace std _Const_Link_type _M_begin() const - { return static_cast<_Const_Link_type>(this->_M_impl._M_header._M_parent); } + { + return static_cast<_Const_Link_type> + (this->_M_impl._M_header._M_parent); + } _Link_type _M_end() @@ -532,6 +548,15 @@ namespace std iterator _M_insert(_Base_ptr __x, _Base_ptr __y, const value_type& __v); + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 233. Insertion hints in associative containers. + iterator + _M_insert_lower(_Base_ptr __x, _Base_ptr __y, const value_type& __v); + + const_iterator + _M_insert(_Const_Base_ptr __x, _Const_Base_ptr __y, + const value_type& __v); + _Link_type _M_copy(_Const_Link_type __x, _Link_type __p); @@ -551,8 +576,8 @@ namespace std : _M_impl(__a, __comp) { } - _Rb_tree(const _Rb_tree<_Key,_Val,_KeyOfValue,_Compare,_Alloc>& __x) - : _M_impl(__x.get_allocator(), __x._M_impl._M_key_compare) + _Rb_tree(const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x) + : _M_impl(__x._M_get_Node_allocator(), __x._M_impl._M_key_compare) { if (__x._M_root() != 0) { @@ -566,8 +591,8 @@ namespace std ~_Rb_tree() { _M_erase(_M_begin()); } - _Rb_tree<_Key,_Val,_KeyOfValue,_Compare,_Alloc>& - operator=(const _Rb_tree<_Key,_Val,_KeyOfValue,_Compare,_Alloc>& __x); + _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& + operator=(const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x); // Accessors. _Compare @@ -576,19 +601,28 @@ namespace std iterator begin() - { return static_cast<_Link_type>(this->_M_impl._M_header._M_left); } + { + return iterator(static_cast<_Link_type> + (this->_M_impl._M_header._M_left)); + } const_iterator begin() const - { return static_cast<_Const_Link_type>(this->_M_impl._M_header._M_left); } + { + return const_iterator(static_cast<_Const_Link_type> + (this->_M_impl._M_header._M_left)); + } iterator end() - { return static_cast<_Link_type>(&this->_M_impl._M_header); } + { return iterator(static_cast<_Link_type>(&this->_M_impl._M_header)); } const_iterator end() const - { return static_cast<_Const_Link_type>(&this->_M_impl._M_header); } + { + return const_iterator(static_cast<_Const_Link_type> + (&this->_M_impl._M_header)); + } reverse_iterator rbegin() @@ -616,35 +650,49 @@ namespace std size_type max_size() const - { return size_type(-1); } + { return get_allocator().max_size(); } void - swap(_Rb_tree<_Key,_Val,_KeyOfValue,_Compare,_Alloc>& __t); + swap(_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __t); // Insert/erase. - pair<iterator,bool> - insert_unique(const value_type& __x); + pair<iterator, bool> + _M_insert_unique(const value_type& __x); + + iterator + _M_insert_equal(const value_type& __x); + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 233. Insertion hints in associative containers. iterator - insert_equal(const value_type& __x); + _M_insert_equal_lower(const value_type& __x); iterator - insert_unique(iterator __position, const value_type& __x); + _M_insert_unique(iterator __position, const value_type& __x); + + const_iterator + _M_insert_unique(const_iterator __position, const value_type& __x); iterator - insert_equal(iterator __position, const value_type& __x); + _M_insert_equal(iterator __position, const value_type& __x); + + const_iterator + _M_insert_equal(const_iterator __position, const value_type& __x); template<typename _InputIterator> - void - insert_unique(_InputIterator __first, _InputIterator __last); + void + _M_insert_unique(_InputIterator __first, _InputIterator __last); template<typename _InputIterator> - void - insert_equal(_InputIterator __first, _InputIterator __last); + void + _M_insert_equal(_InputIterator __first, _InputIterator __last); void erase(iterator __position); + void + erase(const_iterator __position); + size_type erase(const key_type& __x); @@ -652,6 +700,9 @@ namespace std erase(iterator __first, iterator __last); void + erase(const_iterator __first, const_iterator __last); + + void erase(const key_type* __first, const key_type* __last); void @@ -700,8 +751,8 @@ namespace std template<typename _Key, typename _Val, typename _KeyOfValue, typename _Compare, typename _Alloc> inline bool - operator==(const _Rb_tree<_Key,_Val,_KeyOfValue,_Compare,_Alloc>& __x, - const _Rb_tree<_Key,_Val,_KeyOfValue,_Compare,_Alloc>& __y) + operator==(const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x, + const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __y) { return __x.size() == __y.size() && std::equal(__x.begin(), __x.end(), __y.begin()); @@ -710,8 +761,8 @@ namespace std template<typename _Key, typename _Val, typename _KeyOfValue, typename _Compare, typename _Alloc> inline bool - operator<(const _Rb_tree<_Key,_Val,_KeyOfValue,_Compare,_Alloc>& __x, - const _Rb_tree<_Key,_Val,_KeyOfValue,_Compare,_Alloc>& __y) + operator<(const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x, + const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __y) { return std::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end()); @@ -720,43 +771,43 @@ namespace std template<typename _Key, typename _Val, typename _KeyOfValue, typename _Compare, typename _Alloc> inline bool - operator!=(const _Rb_tree<_Key,_Val,_KeyOfValue,_Compare,_Alloc>& __x, - const _Rb_tree<_Key,_Val,_KeyOfValue,_Compare,_Alloc>& __y) + operator!=(const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x, + const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __y) { return !(__x == __y); } template<typename _Key, typename _Val, typename _KeyOfValue, typename _Compare, typename _Alloc> inline bool - operator>(const _Rb_tree<_Key,_Val,_KeyOfValue,_Compare,_Alloc>& __x, - const _Rb_tree<_Key,_Val,_KeyOfValue,_Compare,_Alloc>& __y) + operator>(const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x, + const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __y) { return __y < __x; } template<typename _Key, typename _Val, typename _KeyOfValue, typename _Compare, typename _Alloc> inline bool - operator<=(const _Rb_tree<_Key,_Val,_KeyOfValue,_Compare,_Alloc>& __x, - const _Rb_tree<_Key,_Val,_KeyOfValue,_Compare,_Alloc>& __y) + operator<=(const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x, + const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __y) { return !(__y < __x); } template<typename _Key, typename _Val, typename _KeyOfValue, typename _Compare, typename _Alloc> inline bool - operator>=(const _Rb_tree<_Key,_Val,_KeyOfValue,_Compare,_Alloc>& __x, - const _Rb_tree<_Key,_Val,_KeyOfValue,_Compare,_Alloc>& __y) + operator>=(const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x, + const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __y) { return !(__x < __y); } template<typename _Key, typename _Val, typename _KeyOfValue, typename _Compare, typename _Alloc> inline void - swap(_Rb_tree<_Key,_Val,_KeyOfValue,_Compare,_Alloc>& __x, - _Rb_tree<_Key,_Val,_KeyOfValue,_Compare,_Alloc>& __y) + swap(_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x, + _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __y) { __x.swap(__y); } template<typename _Key, typename _Val, typename _KeyOfValue, typename _Compare, typename _Alloc> - _Rb_tree<_Key,_Val,_KeyOfValue,_Compare,_Alloc>& - _Rb_tree<_Key,_Val,_KeyOfValue,_Compare,_Alloc>:: - operator=(const _Rb_tree<_Key,_Val,_KeyOfValue,_Compare,_Alloc>& __x) + _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& + _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: + operator=(const _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __x) { if (this != &__x) { @@ -776,16 +827,33 @@ namespace std template<typename _Key, typename _Val, typename _KeyOfValue, typename _Compare, typename _Alloc> - typename _Rb_tree<_Key,_Val,_KeyOfValue,_Compare,_Alloc>::iterator - _Rb_tree<_Key,_Val,_KeyOfValue,_Compare,_Alloc>:: + typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator + _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: _M_insert(_Base_ptr __x, _Base_ptr __p, const _Val& __v) { + bool __insert_left = (__x != 0 || __p == _M_end() + || _M_impl._M_key_compare(_KeyOfValue()(__v), + _S_key(__p))); + _Link_type __z = _M_create_node(__v); - bool __insert_left; - __insert_left = __x != 0 || __p == _M_end() - || _M_impl._M_key_compare(_KeyOfValue()(__v), - _S_key(__p)); + _Rb_tree_insert_and_rebalance(__insert_left, __z, __p, + this->_M_impl._M_header); + ++_M_impl._M_node_count; + return iterator(__z); + } + + template<typename _Key, typename _Val, typename _KeyOfValue, + typename _Compare, typename _Alloc> + typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator + _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: + _M_insert_lower(_Base_ptr __x, _Base_ptr __p, const _Val& __v) + { + bool __insert_left = (__x != 0 || __p == _M_end() + || !_M_impl._M_key_compare(_S_key(__p), + _KeyOfValue()(__v))); + + _Link_type __z = _M_create_node(__v); _Rb_tree_insert_and_rebalance(__insert_left, __z, __p, this->_M_impl._M_header); @@ -795,9 +863,28 @@ namespace std template<typename _Key, typename _Val, typename _KeyOfValue, typename _Compare, typename _Alloc> - typename _Rb_tree<_Key,_Val,_KeyOfValue,_Compare,_Alloc>::iterator - _Rb_tree<_Key,_Val,_KeyOfValue,_Compare,_Alloc>:: - insert_equal(const _Val& __v) + typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::const_iterator + _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: + _M_insert(_Const_Base_ptr __x, _Const_Base_ptr __p, const _Val& __v) + { + bool __insert_left = (__x != 0 || __p == _M_end() + || _M_impl._M_key_compare(_KeyOfValue()(__v), + _S_key(__p))); + + _Link_type __z = _M_create_node(__v); + + _Rb_tree_insert_and_rebalance(__insert_left, __z, + const_cast<_Base_ptr>(__p), + this->_M_impl._M_header); + ++_M_impl._M_node_count; + return const_iterator(__z); + } + + template<typename _Key, typename _Val, typename _KeyOfValue, + typename _Compare, typename _Alloc> + typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator + _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: + _M_insert_equal(const _Val& __v) { _Link_type __x = _M_begin(); _Link_type __y = _M_end(); @@ -812,55 +899,77 @@ namespace std template<typename _Key, typename _Val, typename _KeyOfValue, typename _Compare, typename _Alloc> + typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator + _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: + _M_insert_equal_lower(const _Val& __v) + { + _Link_type __x = _M_begin(); + _Link_type __y = _M_end(); + while (__x != 0) + { + __y = __x; + __x = !_M_impl._M_key_compare(_S_key(__x), _KeyOfValue()(__v)) ? + _S_left(__x) : _S_right(__x); + } + return _M_insert_lower(__x, __y, __v); + } + + template<typename _Key, typename _Val, typename _KeyOfValue, + typename _Compare, typename _Alloc> void - _Rb_tree<_Key,_Val,_KeyOfValue,_Compare,_Alloc>:: - swap(_Rb_tree<_Key,_Val,_KeyOfValue,_Compare,_Alloc>& __t) + _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: + swap(_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>& __t) { if (_M_root() == 0) - { - if (__t._M_root() != 0) { - _M_root() = __t._M_root(); - _M_leftmost() = __t._M_leftmost(); - _M_rightmost() = __t._M_rightmost(); - _M_root()->_M_parent = _M_end(); - - __t._M_root() = 0; - __t._M_leftmost() = __t._M_end(); - __t._M_rightmost() = __t._M_end(); + if (__t._M_root() != 0) + { + _M_root() = __t._M_root(); + _M_leftmost() = __t._M_leftmost(); + _M_rightmost() = __t._M_rightmost(); + _M_root()->_M_parent = _M_end(); + + __t._M_root() = 0; + __t._M_leftmost() = __t._M_end(); + __t._M_rightmost() = __t._M_end(); + } } - } else if (__t._M_root() == 0) - { - __t._M_root() = _M_root(); - __t._M_leftmost() = _M_leftmost(); - __t._M_rightmost() = _M_rightmost(); - __t._M_root()->_M_parent = __t._M_end(); - - _M_root() = 0; - _M_leftmost() = _M_end(); - _M_rightmost() = _M_end(); - } + { + __t._M_root() = _M_root(); + __t._M_leftmost() = _M_leftmost(); + __t._M_rightmost() = _M_rightmost(); + __t._M_root()->_M_parent = __t._M_end(); + + _M_root() = 0; + _M_leftmost() = _M_end(); + _M_rightmost() = _M_end(); + } else - { - std::swap(_M_root(),__t._M_root()); - std::swap(_M_leftmost(),__t._M_leftmost()); - std::swap(_M_rightmost(),__t._M_rightmost()); - - _M_root()->_M_parent = _M_end(); - __t._M_root()->_M_parent = __t._M_end(); - } + { + std::swap(_M_root(),__t._M_root()); + std::swap(_M_leftmost(),__t._M_leftmost()); + std::swap(_M_rightmost(),__t._M_rightmost()); + + _M_root()->_M_parent = _M_end(); + __t._M_root()->_M_parent = __t._M_end(); + } // No need to swap header's color as it does not change. std::swap(this->_M_impl._M_node_count, __t._M_impl._M_node_count); std::swap(this->_M_impl._M_key_compare, __t._M_impl._M_key_compare); + + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 431. Swapping containers with unequal allocators. + std::__alloc_swap<_Node_allocator>:: + _S_do_it(_M_get_Node_allocator(), __t._M_get_Node_allocator()); } template<typename _Key, typename _Val, typename _KeyOfValue, typename _Compare, typename _Alloc> - pair<typename _Rb_tree<_Key,_Val,_KeyOfValue,_Compare,_Alloc>::iterator, - bool> - _Rb_tree<_Key,_Val,_KeyOfValue,_Compare,_Alloc>:: - insert_unique(const _Val& __v) + pair<typename _Rb_tree<_Key, _Val, _KeyOfValue, + _Compare, _Alloc>::iterator, bool> + _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: + _M_insert_unique(const _Val& __v) { _Link_type __x = _M_begin(); _Link_type __y = _M_end(); @@ -878,99 +987,229 @@ namespace std else --__j; if (_M_impl._M_key_compare(_S_key(__j._M_node), _KeyOfValue()(__v))) - return pair<iterator,bool>(_M_insert(__x, __y, __v), true); - return pair<iterator,bool>(__j, false); + return pair<iterator, bool>(_M_insert(__x, __y, __v), true); + return pair<iterator, bool>(__j, false); } template<typename _Key, typename _Val, typename _KeyOfValue, typename _Compare, typename _Alloc> typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: - insert_unique(iterator __position, const _Val& __v) + _M_insert_unique(iterator __position, const _Val& __v) { - if (__position._M_node == _M_leftmost()) + // end() + if (__position._M_node == _M_end()) { - // begin() if (size() > 0 - && _M_impl._M_key_compare(_KeyOfValue()(__v), - _S_key(__position._M_node))) - return _M_insert(__position._M_node, __position._M_node, __v); - // First argument just needs to be non-null. + && _M_impl._M_key_compare(_S_key(_M_rightmost()), + _KeyOfValue()(__v))) + return _M_insert(0, _M_rightmost(), __v); else - return insert_unique(__v).first; + return _M_insert_unique(__v).first; } - else if (__position._M_node == _M_end()) + else if (_M_impl._M_key_compare(_KeyOfValue()(__v), + _S_key(__position._M_node))) { - // end() - if (_M_impl._M_key_compare(_S_key(_M_rightmost()), - _KeyOfValue()(__v))) + // First, try before... + iterator __before = __position; + if (__position._M_node == _M_leftmost()) // begin() + return _M_insert(_M_leftmost(), _M_leftmost(), __v); + else if (_M_impl._M_key_compare(_S_key((--__before)._M_node), + _KeyOfValue()(__v))) + { + if (_S_right(__before._M_node) == 0) + return _M_insert(0, __before._M_node, __v); + else + return _M_insert(__position._M_node, + __position._M_node, __v); + } + else + return _M_insert_unique(__v).first; + } + else if (_M_impl._M_key_compare(_S_key(__position._M_node), + _KeyOfValue()(__v))) + { + // ... then try after. + iterator __after = __position; + if (__position._M_node == _M_rightmost()) return _M_insert(0, _M_rightmost(), __v); + else if (_M_impl._M_key_compare(_KeyOfValue()(__v), + _S_key((++__after)._M_node))) + { + if (_S_right(__position._M_node) == 0) + return _M_insert(0, __position._M_node, __v); + else + return _M_insert(__after._M_node, __after._M_node, __v); + } else - return insert_unique(__v).first; + return _M_insert_unique(__v).first; } else + return __position; // Equivalent keys. + } + + template<typename _Key, typename _Val, typename _KeyOfValue, + typename _Compare, typename _Alloc> + typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::const_iterator + _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: + _M_insert_unique(const_iterator __position, const _Val& __v) + { + // end() + if (__position._M_node == _M_end()) { - iterator __before = __position; - --__before; - if (_M_impl._M_key_compare(_S_key(__before._M_node), - _KeyOfValue()(__v)) - && _M_impl._M_key_compare(_KeyOfValue()(__v), - _S_key(__position._M_node))) + if (size() > 0 + && _M_impl._M_key_compare(_S_key(_M_rightmost()), + _KeyOfValue()(__v))) + return _M_insert(0, _M_rightmost(), __v); + else + return const_iterator(_M_insert_unique(__v).first); + } + else if (_M_impl._M_key_compare(_KeyOfValue()(__v), + _S_key(__position._M_node))) + { + // First, try before... + const_iterator __before = __position; + if (__position._M_node == _M_leftmost()) // begin() + return _M_insert(_M_leftmost(), _M_leftmost(), __v); + else if (_M_impl._M_key_compare(_S_key((--__before)._M_node), + _KeyOfValue()(__v))) { if (_S_right(__before._M_node) == 0) return _M_insert(0, __before._M_node, __v); else - return _M_insert(__position._M_node, __position._M_node, __v); - // First argument just needs to be non-null. + return _M_insert(__position._M_node, + __position._M_node, __v); } else - return insert_unique(__v).first; + return const_iterator(_M_insert_unique(__v).first); } + else if (_M_impl._M_key_compare(_S_key(__position._M_node), + _KeyOfValue()(__v))) + { + // ... then try after. + const_iterator __after = __position; + if (__position._M_node == _M_rightmost()) + return _M_insert(0, _M_rightmost(), __v); + else if (_M_impl._M_key_compare(_KeyOfValue()(__v), + _S_key((++__after)._M_node))) + { + if (_S_right(__position._M_node) == 0) + return _M_insert(0, __position._M_node, __v); + else + return _M_insert(__after._M_node, __after._M_node, __v); + } + else + return const_iterator(_M_insert_unique(__v).first); + } + else + return __position; // Equivalent keys. } template<typename _Key, typename _Val, typename _KeyOfValue, typename _Compare, typename _Alloc> - typename _Rb_tree<_Key,_Val,_KeyOfValue,_Compare,_Alloc>::iterator - _Rb_tree<_Key,_Val,_KeyOfValue,_Compare,_Alloc>:: - insert_equal(iterator __position, const _Val& __v) + typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator + _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: + _M_insert_equal(iterator __position, const _Val& __v) { - if (__position._M_node == _M_leftmost()) + // end() + if (__position._M_node == _M_end()) { - // begin() if (size() > 0 - && !_M_impl._M_key_compare(_S_key(__position._M_node), - _KeyOfValue()(__v))) - return _M_insert(__position._M_node, __position._M_node, __v); - // first argument just needs to be non-null + && !_M_impl._M_key_compare(_KeyOfValue()(__v), + _S_key(_M_rightmost()))) + return _M_insert(0, _M_rightmost(), __v); else - return insert_equal(__v); + return _M_insert_equal(__v); } - else if (__position._M_node == _M_end()) + else if (!_M_impl._M_key_compare(_S_key(__position._M_node), + _KeyOfValue()(__v))) { - // end() - if (!_M_impl._M_key_compare(_KeyOfValue()(__v), - _S_key(_M_rightmost()))) - return _M_insert(0, _M_rightmost(), __v); + // First, try before... + iterator __before = __position; + if (__position._M_node == _M_leftmost()) // begin() + return _M_insert(_M_leftmost(), _M_leftmost(), __v); + else if (!_M_impl._M_key_compare(_KeyOfValue()(__v), + _S_key((--__before)._M_node))) + { + if (_S_right(__before._M_node) == 0) + return _M_insert(0, __before._M_node, __v); + else + return _M_insert(__position._M_node, + __position._M_node, __v); + } else - return insert_equal(__v); + return _M_insert_equal(__v); } else { - iterator __before = __position; - --__before; - if (!_M_impl._M_key_compare(_KeyOfValue()(__v), - _S_key(__before._M_node)) - && !_M_impl._M_key_compare(_S_key(__position._M_node), - _KeyOfValue()(__v))) + // ... then try after. + iterator __after = __position; + if (__position._M_node == _M_rightmost()) + return _M_insert(0, _M_rightmost(), __v); + else if (!_M_impl._M_key_compare(_S_key((++__after)._M_node), + _KeyOfValue()(__v))) + { + if (_S_right(__position._M_node) == 0) + return _M_insert(0, __position._M_node, __v); + else + return _M_insert(__after._M_node, __after._M_node, __v); + } + else + return _M_insert_equal_lower(__v); + } + } + + template<typename _Key, typename _Val, typename _KeyOfValue, + typename _Compare, typename _Alloc> + typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::const_iterator + _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: + _M_insert_equal(const_iterator __position, const _Val& __v) + { + // end() + if (__position._M_node == _M_end()) + { + if (size() > 0 + && !_M_impl._M_key_compare(_KeyOfValue()(__v), + _S_key(_M_rightmost()))) + return _M_insert(0, _M_rightmost(), __v); + else + return const_iterator(_M_insert_equal(__v)); + } + else if (!_M_impl._M_key_compare(_S_key(__position._M_node), + _KeyOfValue()(__v))) + { + // First, try before... + const_iterator __before = __position; + if (__position._M_node == _M_leftmost()) // begin() + return _M_insert(_M_leftmost(), _M_leftmost(), __v); + else if (!_M_impl._M_key_compare(_KeyOfValue()(__v), + _S_key((--__before)._M_node))) { if (_S_right(__before._M_node) == 0) return _M_insert(0, __before._M_node, __v); else - return _M_insert(__position._M_node, __position._M_node, __v); - // First argument just needs to be non-null. + return _M_insert(__position._M_node, + __position._M_node, __v); } else - return insert_equal(__v); + return const_iterator(_M_insert_equal(__v)); + } + else + { + // ... then try after. + const_iterator __after = __position; + if (__position._M_node == _M_rightmost()) + return _M_insert(0, _M_rightmost(), __v); + else if (!_M_impl._M_key_compare(_S_key((++__after)._M_node), + _KeyOfValue()(__v))) + { + if (_S_right(__position._M_node) == 0) + return _M_insert(0, __position._M_node, __v); + else + return _M_insert(__after._M_node, __after._M_node, __v); + } + else + return const_iterator(_M_insert_equal_lower(__v)); } } @@ -978,51 +1217,68 @@ namespace std typename _Cmp, typename _Alloc> template<class _II> void - _Rb_tree<_Key,_Val,_KoV,_Cmp,_Alloc>:: - insert_equal(_II __first, _II __last) + _Rb_tree<_Key, _Val, _KoV, _Cmp, _Alloc>:: + _M_insert_equal(_II __first, _II __last) { - for ( ; __first != __last; ++__first) - insert_equal(*__first); + for (; __first != __last; ++__first) + _M_insert_equal(end(), *__first); } template<typename _Key, typename _Val, typename _KoV, typename _Cmp, typename _Alloc> template<class _II> - void - _Rb_tree<_Key,_Val,_KoV,_Cmp,_Alloc>:: - insert_unique(_II __first, _II __last) + void + _Rb_tree<_Key, _Val, _KoV, _Cmp, _Alloc>:: + _M_insert_unique(_II __first, _II __last) + { + for (; __first != __last; ++__first) + _M_insert_unique(end(), *__first); + } + + template<typename _Key, typename _Val, typename _KeyOfValue, + typename _Compare, typename _Alloc> + inline void + _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: + erase(iterator __position) { - for ( ; __first != __last; ++__first) - insert_unique(*__first); + _Link_type __y = + static_cast<_Link_type>(_Rb_tree_rebalance_for_erase + (__position._M_node, + this->_M_impl._M_header)); + _M_destroy_node(__y); + --_M_impl._M_node_count; } template<typename _Key, typename _Val, typename _KeyOfValue, typename _Compare, typename _Alloc> inline void - _Rb_tree<_Key,_Val,_KeyOfValue,_Compare,_Alloc>::erase(iterator __position) + _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: + erase(const_iterator __position) { _Link_type __y = - static_cast<_Link_type>(_Rb_tree_rebalance_for_erase(__position._M_node, - this->_M_impl._M_header)); - destroy_node(__y); + static_cast<_Link_type>(_Rb_tree_rebalance_for_erase + (const_cast<_Base_ptr>(__position._M_node), + this->_M_impl._M_header)); + _M_destroy_node(__y); --_M_impl._M_node_count; } template<typename _Key, typename _Val, typename _KeyOfValue, typename _Compare, typename _Alloc> - typename _Rb_tree<_Key,_Val,_KeyOfValue,_Compare,_Alloc>::size_type - _Rb_tree<_Key,_Val,_KeyOfValue,_Compare,_Alloc>::erase(const _Key& __x) + typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::size_type + _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: + erase(const _Key& __x) { - pair<iterator,iterator> __p = equal_range(__x); - size_type __n = std::distance(__p.first, __p.second); + pair<iterator, iterator> __p = equal_range(__x); + const size_type __old_size = size(); erase(__p.first, __p.second); - return __n; + return __old_size - size(); } template<typename _Key, typename _Val, typename _KoV, typename _Compare, typename _Alloc> typename _Rb_tree<_Key, _Val, _KoV, _Compare, _Alloc>::_Link_type - _Rb_tree<_Key,_Val,_KoV,_Compare,_Alloc>:: + _Rb_tree<_Key, _Val, _KoV, _Compare, _Alloc>:: _M_copy(_Const_Link_type __x, _Link_type __p) { // Structural copy. __x and __p must be non-null. @@ -1058,14 +1314,15 @@ namespace std template<typename _Key, typename _Val, typename _KeyOfValue, typename _Compare, typename _Alloc> void - _Rb_tree<_Key,_Val,_KeyOfValue,_Compare,_Alloc>::_M_erase(_Link_type __x) + _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: + _M_erase(_Link_type __x) { // Erase without rebalancing. while (__x != 0) { _M_erase(_S_right(__x)); _Link_type __y = _S_left(__x); - destroy_node(__x); + _M_destroy_node(__x); __x = __y; } } @@ -1073,19 +1330,33 @@ namespace std template<typename _Key, typename _Val, typename _KeyOfValue, typename _Compare, typename _Alloc> void - _Rb_tree<_Key,_Val,_KeyOfValue,_Compare,_Alloc>:: + _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: erase(iterator __first, iterator __last) { if (__first == begin() && __last == end()) clear(); else - while (__first != __last) erase(__first++); + while (__first != __last) + erase(__first++); } template<typename _Key, typename _Val, typename _KeyOfValue, typename _Compare, typename _Alloc> void - _Rb_tree<_Key,_Val,_KeyOfValue,_Compare,_Alloc>:: + _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: + erase(const_iterator __first, const_iterator __last) + { + if (__first == begin() && __last == end()) + clear(); + else + while (__first != __last) + erase(__first++); + } + + template<typename _Key, typename _Val, typename _KeyOfValue, + typename _Compare, typename _Alloc> + void + _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: erase(const _Key* __first, const _Key* __last) { while (__first != __last) @@ -1094,8 +1365,9 @@ namespace std template<typename _Key, typename _Val, typename _KeyOfValue, typename _Compare, typename _Alloc> - typename _Rb_tree<_Key,_Val,_KeyOfValue,_Compare,_Alloc>::iterator - _Rb_tree<_Key,_Val,_KeyOfValue,_Compare,_Alloc>::find(const _Key& __k) + typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator + _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: + find(const _Key& __k) { _Link_type __x = _M_begin(); // Current node. _Link_type __y = _M_end(); // Last node which is not less than __k. @@ -1107,14 +1379,15 @@ namespace std __x = _S_right(__x); iterator __j = iterator(__y); - return (__j == end() - || _M_impl._M_key_compare(__k, _S_key(__j._M_node))) ? end() : __j; + return (__j == end() + || _M_impl._M_key_compare(__k, + _S_key(__j._M_node))) ? end() : __j; } template<typename _Key, typename _Val, typename _KeyOfValue, typename _Compare, typename _Alloc> - typename _Rb_tree<_Key,_Val,_KeyOfValue,_Compare,_Alloc>::const_iterator - _Rb_tree<_Key,_Val,_KeyOfValue,_Compare,_Alloc>:: + typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::const_iterator + _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: find(const _Key& __k) const { _Const_Link_type __x = _M_begin(); // Current node. @@ -1128,14 +1401,15 @@ namespace std __x = _S_right(__x); } const_iterator __j = const_iterator(__y); - return (__j == end() - || _M_impl._M_key_compare(__k, _S_key(__j._M_node))) ? end() : __j; + return (__j == end() + || _M_impl._M_key_compare(__k, + _S_key(__j._M_node))) ? end() : __j; } template<typename _Key, typename _Val, typename _KeyOfValue, typename _Compare, typename _Alloc> - typename _Rb_tree<_Key,_Val,_KeyOfValue,_Compare,_Alloc>::size_type - _Rb_tree<_Key,_Val,_KeyOfValue,_Compare,_Alloc>:: + typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::size_type + _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: count(const _Key& __k) const { pair<const_iterator, const_iterator> __p = equal_range(__k); @@ -1145,8 +1419,8 @@ namespace std template<typename _Key, typename _Val, typename _KeyOfValue, typename _Compare, typename _Alloc> - typename _Rb_tree<_Key,_Val,_KeyOfValue,_Compare,_Alloc>::iterator - _Rb_tree<_Key,_Val,_KeyOfValue,_Compare,_Alloc>:: + typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator + _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: lower_bound(const _Key& __k) { _Link_type __x = _M_begin(); // Current node. @@ -1163,8 +1437,8 @@ namespace std template<typename _Key, typename _Val, typename _KeyOfValue, typename _Compare, typename _Alloc> - typename _Rb_tree<_Key,_Val,_KeyOfValue,_Compare,_Alloc>::const_iterator - _Rb_tree<_Key,_Val,_KeyOfValue,_Compare,_Alloc>:: + typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::const_iterator + _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: lower_bound(const _Key& __k) const { _Const_Link_type __x = _M_begin(); // Current node. @@ -1181,8 +1455,8 @@ namespace std template<typename _Key, typename _Val, typename _KeyOfValue, typename _Compare, typename _Alloc> - typename _Rb_tree<_Key,_Val,_KeyOfValue,_Compare,_Alloc>::iterator - _Rb_tree<_Key,_Val,_KeyOfValue,_Compare,_Alloc>:: + typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator + _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: upper_bound(const _Key& __k) { _Link_type __x = _M_begin(); // Current node. @@ -1199,8 +1473,8 @@ namespace std template<typename _Key, typename _Val, typename _KeyOfValue, typename _Compare, typename _Alloc> - typename _Rb_tree<_Key,_Val,_KeyOfValue,_Compare,_Alloc>::const_iterator - _Rb_tree<_Key,_Val,_KeyOfValue,_Compare,_Alloc>:: + typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::const_iterator + _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: upper_bound(const _Key& __k) const { _Const_Link_type __x = _M_begin(); // Current node. @@ -1218,10 +1492,10 @@ namespace std template<typename _Key, typename _Val, typename _KeyOfValue, typename _Compare, typename _Alloc> inline - pair<typename _Rb_tree<_Key,_Val,_KeyOfValue, - _Compare,_Alloc>::iterator, - typename _Rb_tree<_Key,_Val,_KeyOfValue,_Compare,_Alloc>::iterator> - _Rb_tree<_Key,_Val,_KeyOfValue,_Compare,_Alloc>:: + pair<typename _Rb_tree<_Key, _Val, _KeyOfValue, + _Compare, _Alloc>::iterator, + typename _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator> + _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>:: equal_range(const _Key& __k) { return pair<iterator, iterator>(lower_bound(__k), upper_bound(__k)); } @@ -1277,7 +1551,7 @@ namespace std return false; return true; } -} // namespace std -#endif +_GLIBCXX_END_NAMESPACE +#endif diff --git a/contrib/libstdc++/include/bits/stl_uninitialized.h b/contrib/libstdc++/include/bits/stl_uninitialized.h index f4f8d18..2c947f6 100644 --- a/contrib/libstdc++/include/bits/stl_uninitialized.h +++ b/contrib/libstdc++/include/bits/stl_uninitialized.h @@ -1,6 +1,7 @@ // Raw memory manipulators -*- C++ -*- -// Copyright (C) 2001, 2004 Free Software Foundation, Inc. +// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 +// 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 @@ -15,7 +16,7 @@ // 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// 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 @@ -63,8 +64,8 @@ #include <cstring> -namespace std -{ +_GLIBCXX_BEGIN_NAMESPACE(std) + // uninitialized_copy template<typename _InputIterator, typename _ForwardIterator> inline _ForwardIterator @@ -82,7 +83,7 @@ namespace std _ForwardIterator __cur = __result; try { - for ( ; __first != __last; ++__first, ++__cur) + for (; __first != __last; ++__first, ++__cur) std::_Construct(&*__cur, *__first); return __cur; } @@ -108,7 +109,7 @@ namespace std _ForwardIterator __result) { typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType; - typedef typename __type_traits<_ValueType>::is_POD_type _Is_POD; + typedef typename std::__is_scalar<_ValueType>::__type _Is_POD; return std::__uninitialized_copy_aux(__first, __last, __result, _Is_POD()); } @@ -145,7 +146,7 @@ namespace std _ForwardIterator __cur = __first; try { - for ( ; __cur != __last; ++__cur) + for (; __cur != __last; ++__cur) std::_Construct(&*__cur, __x); } catch(...) @@ -170,29 +171,28 @@ namespace std const _Tp& __x) { typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType; - typedef typename __type_traits<_ValueType>::is_POD_type _Is_POD; + typedef typename std::__is_scalar<_ValueType>::__type _Is_POD; std::__uninitialized_fill_aux(__first, __last, __x, _Is_POD()); } // Valid if copy construction is equivalent to assignment, and if the // destructor is trivial. template<typename _ForwardIterator, typename _Size, typename _Tp> - inline _ForwardIterator + inline void __uninitialized_fill_n_aux(_ForwardIterator __first, _Size __n, const _Tp& __x, __true_type) - { return std::fill_n(__first, __n, __x); } + { std::fill_n(__first, __n, __x); } template<typename _ForwardIterator, typename _Size, typename _Tp> - _ForwardIterator + void __uninitialized_fill_n_aux(_ForwardIterator __first, _Size __n, const _Tp& __x, __false_type) { _ForwardIterator __cur = __first; try { - for ( ; __n > 0; --__n, ++__cur) + for (; __n > 0; --__n, ++__cur) std::_Construct(&*__cur, __x); - return __cur; } catch(...) { @@ -206,21 +206,109 @@ namespace std * @param first An input iterator. * @param n The number of copies to make. * @param x The source value. - * @return first+n + * @return Nothing. * * Like fill_n(), but does not require an initialized output range. */ template<typename _ForwardIterator, typename _Size, typename _Tp> - inline _ForwardIterator + inline void uninitialized_fill_n(_ForwardIterator __first, _Size __n, const _Tp& __x) { typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType; - typedef typename __type_traits<_ValueType>::is_POD_type _Is_POD; - return std::__uninitialized_fill_n_aux(__first, __n, __x, _Is_POD()); + typedef typename std::__is_scalar<_ValueType>::__type _Is_POD; + std::__uninitialized_fill_n_aux(__first, __n, __x, _Is_POD()); + } + + // Extensions: versions of uninitialized_copy, uninitialized_fill, + // and uninitialized_fill_n that take an allocator parameter. + // We dispatch back to the standard versions when we're given the + // default allocator. For nondefault allocators we do not use + // any of the POD optimizations. + + template<typename _InputIterator, typename _ForwardIterator, + typename _Allocator> + _ForwardIterator + __uninitialized_copy_a(_InputIterator __first, _InputIterator __last, + _ForwardIterator __result, + _Allocator __alloc) + { + _ForwardIterator __cur = __result; + try + { + for (; __first != __last; ++__first, ++__cur) + __alloc.construct(&*__cur, *__first); + return __cur; + } + catch(...) + { + std::_Destroy(__result, __cur, __alloc); + __throw_exception_again; + } + } + + template<typename _InputIterator, typename _ForwardIterator, typename _Tp> + inline _ForwardIterator + __uninitialized_copy_a(_InputIterator __first, _InputIterator __last, + _ForwardIterator __result, + allocator<_Tp>) + { return std::uninitialized_copy(__first, __last, __result); } + + template<typename _ForwardIterator, typename _Tp, typename _Allocator> + void + __uninitialized_fill_a(_ForwardIterator __first, _ForwardIterator __last, + const _Tp& __x, _Allocator __alloc) + { + _ForwardIterator __cur = __first; + try + { + for (; __cur != __last; ++__cur) + __alloc.construct(&*__cur, __x); + } + catch(...) + { + std::_Destroy(__first, __cur, __alloc); + __throw_exception_again; + } + } + + template<typename _ForwardIterator, typename _Tp, typename _Tp2> + inline void + __uninitialized_fill_a(_ForwardIterator __first, _ForwardIterator __last, + const _Tp& __x, allocator<_Tp2>) + { std::uninitialized_fill(__first, __last, __x); } + + template<typename _ForwardIterator, typename _Size, typename _Tp, + typename _Allocator> + void + __uninitialized_fill_n_a(_ForwardIterator __first, _Size __n, + const _Tp& __x, + _Allocator __alloc) + { + _ForwardIterator __cur = __first; + try + { + for (; __n > 0; --__n, ++__cur) + __alloc.construct(&*__cur, __x); + } + catch(...) + { + std::_Destroy(__first, __cur, __alloc); + __throw_exception_again; + } } + template<typename _ForwardIterator, typename _Size, typename _Tp, + typename _Tp2> + inline void + __uninitialized_fill_n_a(_ForwardIterator __first, _Size __n, + const _Tp& __x, + allocator<_Tp2>) + { std::uninitialized_fill_n(__first, __n, __x); } + + // Extensions: __uninitialized_copy_copy, __uninitialized_copy_fill, - // __uninitialized_fill_copy. + // __uninitialized_fill_copy. All of these algorithms take a user- + // supplied allocator, which is used for construction and destruction. // __uninitialized_copy_copy // Copies [first1, last1) into [result, result + (last1 - first1)), and @@ -228,23 +316,25 @@ namespace std // [result, result + (last1 - first1) + (last2 - first2)). template<typename _InputIterator1, typename _InputIterator2, - typename _ForwardIterator> + typename _ForwardIterator, typename _Allocator> inline _ForwardIterator __uninitialized_copy_copy(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, - _ForwardIterator __result) + _ForwardIterator __result, + _Allocator __alloc) { - _ForwardIterator __mid = std::uninitialized_copy(__first1, __last1, - __result); + _ForwardIterator __mid = std::__uninitialized_copy_a(__first1, __last1, + __result, + __alloc); try { - return std::uninitialized_copy(__first2, __last2, __mid); + return std::__uninitialized_copy_a(__first2, __last2, __mid, __alloc); } catch(...) { - std::_Destroy(__result, __mid); + std::_Destroy(__result, __mid, __alloc); __throw_exception_again; } } @@ -252,20 +342,22 @@ namespace std // __uninitialized_fill_copy // Fills [result, mid) with x, and copies [first, last) into // [mid, mid + (last - first)). - template<typename _ForwardIterator, typename _Tp, typename _InputIterator> + template<typename _ForwardIterator, typename _Tp, typename _InputIterator, + typename _Allocator> inline _ForwardIterator __uninitialized_fill_copy(_ForwardIterator __result, _ForwardIterator __mid, const _Tp& __x, _InputIterator __first, - _InputIterator __last) + _InputIterator __last, + _Allocator __alloc) { - std::uninitialized_fill(__result, __mid, __x); + std::__uninitialized_fill_a(__result, __mid, __x, __alloc); try { - return std::uninitialized_copy(__first, __last, __mid); + return std::__uninitialized_copy_a(__first, __last, __mid, __alloc); } catch(...) { - std::_Destroy(__result, __mid); + std::_Destroy(__result, __mid, __alloc); __throw_exception_again; } } @@ -273,25 +365,28 @@ namespace std // __uninitialized_copy_fill // Copies [first1, last1) into [first2, first2 + (last1 - first1)), and // fills [first2 + (last1 - first1), last2) with x. - template<typename _InputIterator, typename _ForwardIterator, typename _Tp> + template<typename _InputIterator, typename _ForwardIterator, typename _Tp, + typename _Allocator> inline void __uninitialized_copy_fill(_InputIterator __first1, _InputIterator __last1, _ForwardIterator __first2, - _ForwardIterator __last2, const _Tp& __x) + _ForwardIterator __last2, const _Tp& __x, + _Allocator __alloc) { - _ForwardIterator __mid2 = std::uninitialized_copy(__first1, __last1, - __first2); + _ForwardIterator __mid2 = std::__uninitialized_copy_a(__first1, __last1, + __first2, + __alloc); try { - std::uninitialized_fill(__mid2, __last2, __x); + std::__uninitialized_fill_a(__mid2, __last2, __x, __alloc); } catch(...) { - std::_Destroy(__first2, __mid2); + std::_Destroy(__first2, __mid2, __alloc); __throw_exception_again; } } -} // namespace std +_GLIBCXX_END_NAMESPACE #endif /* _STL_UNINITIALIZED_H */ diff --git a/contrib/libstdc++/include/bits/stl_vector.h b/contrib/libstdc++/include/bits/stl_vector.h index fee413d..a81c597 100644 --- a/contrib/libstdc++/include/bits/stl_vector.h +++ b/contrib/libstdc++/include/bits/stl_vector.h @@ -1,6 +1,7 @@ // Vector implementation -*- C++ -*- -// Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. +// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 +// 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 @@ -15,7 +16,7 @@ // 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// 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 @@ -65,8 +66,8 @@ #include <bits/functexcept.h> #include <bits/concept_check.h> -namespace _GLIBCXX_STD -{ +_GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD) + /** * @if maint * See bits/stl_deque.h's _Deque_base for an explanation. @@ -75,27 +76,40 @@ namespace _GLIBCXX_STD template<typename _Tp, typename _Alloc> struct _Vector_base { + typedef typename _Alloc::template rebind<_Tp>::other _Tp_alloc_type; + struct _Vector_impl - : public _Alloc { + : public _Tp_alloc_type + { _Tp* _M_start; _Tp* _M_finish; _Tp* _M_end_of_storage; - _Vector_impl (_Alloc const& __a) - : _Alloc(__a), _M_start(0), _M_finish(0), _M_end_of_storage(0) + _Vector_impl(_Tp_alloc_type const& __a) + : _Tp_alloc_type(__a), _M_start(0), _M_finish(0), _M_end_of_storage(0) { } }; public: typedef _Alloc allocator_type; + _Tp_alloc_type& + _M_get_Tp_allocator() + { return *static_cast<_Tp_alloc_type*>(&this->_M_impl); } + + const _Tp_alloc_type& + _M_get_Tp_allocator() const + { return *static_cast<const _Tp_alloc_type*>(&this->_M_impl); } + allocator_type - get_allocator() const { return *static_cast<const _Alloc*>(&this->_M_impl); } + get_allocator() const + { return allocator_type(_M_get_Tp_allocator()); } - _Vector_base(const allocator_type& __a) : _M_impl(__a) + _Vector_base(const allocator_type& __a) + : _M_impl(__a) { } _Vector_base(size_t __n, const allocator_type& __a) - : _M_impl(__a) + : _M_impl(__a) { this->_M_impl._M_start = this->_M_allocate(__n); this->_M_impl._M_finish = this->_M_impl._M_start; @@ -103,18 +117,22 @@ namespace _GLIBCXX_STD } ~_Vector_base() - { _M_deallocate(this->_M_impl._M_start, - this->_M_impl._M_end_of_storage - this->_M_impl._M_start); } + { _M_deallocate(this->_M_impl._M_start, this->_M_impl._M_end_of_storage + - this->_M_impl._M_start); } public: _Vector_impl _M_impl; _Tp* - _M_allocate(size_t __n) { return _M_impl.allocate(__n); } + _M_allocate(size_t __n) + { return _M_impl.allocate(__n); } void _M_deallocate(_Tp* __p, size_t __n) - { if (__p) _M_impl.deallocate(__p, __n); } + { + if (__p) + _M_impl.deallocate(__p, __n); + } }; @@ -137,21 +155,24 @@ namespace _GLIBCXX_STD * memory and size allocation. Subscripting ( @c [] ) access is * also provided as with C-style arrays. */ - template<typename _Tp, typename _Alloc = allocator<_Tp> > + template<typename _Tp, typename _Alloc = std::allocator<_Tp> > class vector : protected _Vector_base<_Tp, _Alloc> { // Concept requirements. + typedef typename _Alloc::value_type _Alloc_value_type; __glibcxx_class_requires(_Tp, _SGIAssignableConcept) - - typedef _Vector_base<_Tp, _Alloc> _Base; - typedef vector<_Tp, _Alloc> vector_type; + __glibcxx_class_requires2(_Tp, _Alloc_value_type, _SameTypeConcept) + + typedef _Vector_base<_Tp, _Alloc> _Base; + typedef vector<_Tp, _Alloc> vector_type; + typedef typename _Base::_Tp_alloc_type _Tp_alloc_type; public: typedef _Tp value_type; - typedef typename _Alloc::pointer pointer; - typedef typename _Alloc::const_pointer const_pointer; - typedef typename _Alloc::reference reference; - typedef typename _Alloc::const_reference const_reference; + typedef typename _Tp_alloc_type::pointer pointer; + typedef typename _Tp_alloc_type::const_pointer const_pointer; + typedef typename _Tp_alloc_type::reference reference; + typedef typename _Tp_alloc_type::const_reference const_reference; typedef __gnu_cxx::__normal_iterator<pointer, vector_type> iterator; typedef __gnu_cxx::__normal_iterator<const_pointer, vector_type> const_iterator; @@ -159,17 +180,13 @@ namespace _GLIBCXX_STD typedef std::reverse_iterator<iterator> reverse_iterator; typedef size_t size_type; typedef ptrdiff_t difference_type; - typedef typename _Base::allocator_type allocator_type; + typedef _Alloc allocator_type; protected: - /** @if maint - * These two functions and three data members are all from the - * base class. They should be pretty self-explanatory, as - * %vector uses a simple contiguous allocation scheme. @endif - */ using _Base::_M_allocate; using _Base::_M_deallocate; using _Base::_M_impl; + using _Base::_M_get_Tp_allocator; public: // [23.2.4.1] construct/copy/destroy @@ -179,7 +196,8 @@ namespace _GLIBCXX_STD */ explicit vector(const allocator_type& __a = allocator_type()) - : _Base(__a) { } + : _Base(__a) + { } /** * @brief Create a %vector with copies of an exemplar element. @@ -188,24 +206,15 @@ namespace _GLIBCXX_STD * * This constructor fills the %vector with @a n copies of @a value. */ - vector(size_type __n, const value_type& __value, + explicit + vector(size_type __n, const value_type& __value = value_type(), const allocator_type& __a = allocator_type()) : _Base(__n, __a) - { this->_M_impl._M_finish = std::uninitialized_fill_n(this->_M_impl._M_start, - __n, __value); } - - /** - * @brief Create a %vector with default elements. - * @param n The number of elements to initially create. - * - * This constructor fills the %vector with @a n copies of a - * default-constructed element. - */ - explicit - vector(size_type __n) - : _Base(__n, allocator_type()) - { this->_M_impl._M_finish = std::uninitialized_fill_n(this->_M_impl._M_start, - __n, value_type()); } + { + std::__uninitialized_fill_n_a(this->_M_impl._M_start, __n, __value, + _M_get_Tp_allocator()); + this->_M_impl._M_finish = this->_M_impl._M_start + __n; + } /** * @brief %Vector copy constructor. @@ -217,9 +226,11 @@ namespace _GLIBCXX_STD * @a x (for fast expansion) will not be copied. */ vector(const vector& __x) - : _Base(__x.size(), __x.get_allocator()) - { this->_M_impl._M_finish = std::uninitialized_copy(__x.begin(), __x.end(), - this->_M_impl._M_start); + : _Base(__x.size(), __x._M_get_Tp_allocator()) + { this->_M_impl._M_finish = + std::__uninitialized_copy_a(__x.begin(), __x.end(), + this->_M_impl._M_start, + _M_get_Tp_allocator()); } /** @@ -243,7 +254,7 @@ namespace _GLIBCXX_STD : _Base(__a) { // Check whether it's an integral type. If so, it's not an iterator. - typedef typename _Is_integer<_InputIterator>::_Integral _Integral; + typedef typename std::__is_integer<_InputIterator>::__type _Integral; _M_initialize_dispatch(__first, __last, _Integral()); } @@ -253,7 +264,9 @@ namespace _GLIBCXX_STD * not touched in any way. Managing the pointer is the user's * responsibilty. */ - ~vector() { std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish); } + ~vector() + { std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish, + _M_get_Tp_allocator()); } /** * @brief %Vector assignment operator. @@ -297,7 +310,7 @@ namespace _GLIBCXX_STD assign(_InputIterator __first, _InputIterator __last) { // Check whether it's an integral type. If so, it's not an iterator. - typedef typename _Is_integer<_InputIterator>::_Integral _Integral; + typedef typename std::__is_integer<_InputIterator>::__type _Integral; _M_assign_dispatch(__first, __last, _Integral()); } @@ -311,7 +324,8 @@ namespace _GLIBCXX_STD * element order. */ iterator - begin() { return iterator (this->_M_impl._M_start); } + begin() + { return iterator(this->_M_impl._M_start); } /** * Returns a read-only (constant) iterator that points to the @@ -319,7 +333,8 @@ namespace _GLIBCXX_STD * element order. */ const_iterator - begin() const { return const_iterator (this->_M_impl._M_start); } + begin() const + { return const_iterator(this->_M_impl._M_start); } /** * Returns a read/write iterator that points one past the last @@ -327,7 +342,8 @@ namespace _GLIBCXX_STD * element order. */ iterator - end() { return iterator (this->_M_impl._M_finish); } + end() + { return iterator(this->_M_impl._M_finish); } /** * Returns a read-only (constant) iterator that points one past @@ -335,7 +351,8 @@ namespace _GLIBCXX_STD * ordinary element order. */ const_iterator - end() const { return const_iterator (this->_M_impl._M_finish); } + end() const + { return const_iterator(this->_M_impl._M_finish); } /** * Returns a read/write reverse iterator that points to the @@ -343,7 +360,8 @@ namespace _GLIBCXX_STD * element order. */ reverse_iterator - rbegin() { return reverse_iterator(end()); } + rbegin() + { return reverse_iterator(end()); } /** * Returns a read-only (constant) reverse iterator that points @@ -351,7 +369,8 @@ namespace _GLIBCXX_STD * reverse element order. */ 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 @@ -359,7 +378,8 @@ namespace _GLIBCXX_STD * in reverse element order. */ reverse_iterator - rend() { return reverse_iterator(begin()); } + rend() + { return reverse_iterator(begin()); } /** * Returns a read-only (constant) reverse iterator that points @@ -367,16 +387,19 @@ namespace _GLIBCXX_STD * is done in reverse element order. */ const_reverse_iterator - rend() const { return const_reverse_iterator(begin()); } + rend() const + { return const_reverse_iterator(begin()); } // [23.2.4.2] capacity /** Returns the number of elements in the %vector. */ size_type - size() const { return size_type(end() - begin()); } + size() const + { return size_type(this->_M_impl._M_finish - this->_M_impl._M_start); } /** Returns the size() of the largest possible %vector. */ size_type - max_size() const { return size_type(-1) / sizeof(value_type); } + max_size() const + { return _M_get_Tp_allocator().max_size(); } /** * @brief Resizes the %vector to the specified number of elements. @@ -390,41 +413,30 @@ namespace _GLIBCXX_STD * given data. */ void - resize(size_type __new_size, const value_type& __x) + resize(size_type __new_size, value_type __x = value_type()) { if (__new_size < size()) - erase(begin() + __new_size, end()); + _M_erase_at_end(this->_M_impl._M_start + __new_size); else insert(end(), __new_size - size(), __x); } /** - * @brief Resizes the %vector to the specified number of elements. - * @param new_size Number of elements the %vector should contain. - * - * This function will resize the %vector to the specified - * number of elements. If the number is smaller than the - * %vector's current size the %vector is truncated, otherwise - * the %vector is extended and new elements are - * default-constructed. - */ - void - resize(size_type __new_size) { resize(__new_size, value_type()); } - - /** * Returns the total number of elements that the %vector can * hold before needing to allocate more memory. */ size_type capacity() const - { return size_type(const_iterator(this->_M_impl._M_end_of_storage) - begin()); } + { return size_type(this->_M_impl._M_end_of_storage + - this->_M_impl._M_start); } /** * Returns true if the %vector is empty. (Thus begin() would * equal end().) */ bool - empty() const { return begin() == end(); } + empty() const + { return begin() == end(); } /** * @brief Attempt to preallocate enough memory for specified number of @@ -459,7 +471,8 @@ namespace _GLIBCXX_STD * see at().) */ reference - operator[](size_type __n) { return *(begin() + __n); } + operator[](size_type __n) + { return *(this->_M_impl._M_start + __n); } /** * @brief Subscript access to the data contained in the %vector. @@ -473,7 +486,8 @@ namespace _GLIBCXX_STD * see at().) */ const_reference - operator[](size_type __n) const { return *(begin() + __n); } + operator[](size_type __n) const + { return *(this->_M_impl._M_start + __n); } protected: /// @if maint Safety check used only from at(). @endif @@ -497,7 +511,11 @@ namespace _GLIBCXX_STD * function throws out_of_range if the check fails. */ reference - at(size_type __n) { _M_range_check(__n); return (*this)[__n]; } + at(size_type __n) + { + _M_range_check(__n); + return (*this)[__n]; + } /** * @brief Provides access to the data contained in the %vector. @@ -511,35 +529,58 @@ namespace _GLIBCXX_STD * function throws out_of_range if the check fails. */ const_reference - at(size_type __n) const { _M_range_check(__n); return (*this)[__n]; } + 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 %vector. */ reference - front() { return *begin(); } + front() + { return *begin(); } /** * Returns a read-only (constant) reference to the data at the first * element of the %vector. */ const_reference - front() const { return *begin(); } + front() const + { return *begin(); } /** * Returns a read/write reference to the data at the last * element of the %vector. */ reference - back() { return *(end() - 1); } - + back() + { return *(end() - 1); } + /** * Returns a read-only (constant) reference to the data at the * last element of the %vector. */ const_reference - back() const { return *(end() - 1); } + back() const + { return *(end() - 1); } + + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // DR 464. Suggestion for new member functions in standard containers. + // data access + /** + * Returns a pointer such that [data(), data() + size()) is a valid + * range. For a non-empty %vector, data() == &front(). + */ + pointer + data() + { return pointer(this->_M_impl._M_start); } + + const_pointer + data() const + { return const_pointer(this->_M_impl._M_start); } // [23.2.4.3] modifiers /** @@ -557,7 +598,7 @@ namespace _GLIBCXX_STD { if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage) { - std::_Construct(this->_M_impl._M_finish, __x); + this->_M_impl.construct(this->_M_impl._M_finish, __x); ++this->_M_impl._M_finish; } else @@ -577,7 +618,7 @@ namespace _GLIBCXX_STD pop_back() { --this->_M_impl._M_finish; - std::_Destroy(this->_M_impl._M_finish); + this->_M_impl.destroy(this->_M_impl._M_finish); } /** @@ -631,7 +672,7 @@ namespace _GLIBCXX_STD _InputIterator __last) { // Check whether it's an integral type. If so, it's not an iterator. - typedef typename _Is_integer<_InputIterator>::_Integral _Integral; + typedef typename std::__is_integer<_InputIterator>::__type _Integral; _M_insert_dispatch(__position, __first, __last, _Integral()); } @@ -688,7 +729,13 @@ namespace _GLIBCXX_STD { std::swap(this->_M_impl._M_start, __x._M_impl._M_start); std::swap(this->_M_impl._M_finish, __x._M_impl._M_finish); - std::swap(this->_M_impl._M_end_of_storage, __x._M_impl._M_end_of_storage); + std::swap(this->_M_impl._M_end_of_storage, + __x._M_impl._M_end_of_storage); + + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 431. Swapping containers with unequal allocators. + std::__alloc_swap<_Tp_alloc_type>::_S_do_it(_M_get_Tp_allocator(), + __x._M_get_Tp_allocator()); } /** @@ -698,7 +745,8 @@ namespace _GLIBCXX_STD * the user's responsibilty. */ void - clear() { erase(begin(), end()); } + clear() + { _M_erase_at_end(this->_M_impl._M_start); } protected: /** @@ -715,7 +763,8 @@ namespace _GLIBCXX_STD pointer __result = this->_M_allocate(__n); try { - std::uninitialized_copy(__first, __last, __result); + std::__uninitialized_copy_a(__first, __last, __result, + _M_get_Tp_allocator()); return __result; } catch(...) @@ -735,8 +784,9 @@ namespace _GLIBCXX_STD { this->_M_impl._M_start = _M_allocate(__n); this->_M_impl._M_end_of_storage = this->_M_impl._M_start + __n; - this->_M_impl._M_finish = std::uninitialized_fill_n(this->_M_impl._M_start, - __n, __value); + std::__uninitialized_fill_n_a(this->_M_impl._M_start, __n, __value, + _M_get_Tp_allocator()); + this->_M_impl._M_finish = this->_M_impl._M_end_of_storage; } // Called by the range constructor to implement [23.1.1]/9 @@ -745,8 +795,8 @@ namespace _GLIBCXX_STD _M_initialize_dispatch(_InputIterator __first, _InputIterator __last, __false_type) { - typedef typename iterator_traits<_InputIterator>::iterator_category - _IterCategory; + typedef typename std::iterator_traits<_InputIterator>:: + iterator_category _IterCategory; _M_range_initialize(__first, __last, _IterCategory()); } @@ -754,9 +804,9 @@ namespace _GLIBCXX_STD template<typename _InputIterator> void _M_range_initialize(_InputIterator __first, - _InputIterator __last, input_iterator_tag) + _InputIterator __last, std::input_iterator_tag) { - for ( ; __first != __last; ++__first) + for (; __first != __last; ++__first) push_back(*__first); } @@ -764,13 +814,15 @@ namespace _GLIBCXX_STD template<typename _ForwardIterator> void _M_range_initialize(_ForwardIterator __first, - _ForwardIterator __last, forward_iterator_tag) + _ForwardIterator __last, std::forward_iterator_tag) { - size_type __n = std::distance(__first, __last); + const size_type __n = std::distance(__first, __last); this->_M_impl._M_start = this->_M_allocate(__n); this->_M_impl._M_end_of_storage = this->_M_impl._M_start + __n; - this->_M_impl._M_finish = std::uninitialized_copy(__first, __last, - this->_M_impl._M_start); + this->_M_impl._M_finish = + std::__uninitialized_copy_a(__first, __last, + this->_M_impl._M_start, + _M_get_Tp_allocator()); } @@ -792,8 +844,8 @@ namespace _GLIBCXX_STD _M_assign_dispatch(_InputIterator __first, _InputIterator __last, __false_type) { - typedef typename iterator_traits<_InputIterator>::iterator_category - _IterCategory; + typedef typename std::iterator_traits<_InputIterator>:: + iterator_category _IterCategory; _M_assign_aux(__first, __last, _IterCategory()); } @@ -801,13 +853,13 @@ namespace _GLIBCXX_STD template<typename _InputIterator> void _M_assign_aux(_InputIterator __first, _InputIterator __last, - input_iterator_tag); + std::input_iterator_tag); // Called by the second assign_dispatch above template<typename _ForwardIterator> void _M_assign_aux(_ForwardIterator __first, _ForwardIterator __last, - forward_iterator_tag); + std::forward_iterator_tag); // Called by assign(n,t), and the range assign when it turns out // to be the same thing. @@ -833,8 +885,8 @@ namespace _GLIBCXX_STD _M_insert_dispatch(iterator __pos, _InputIterator __first, _InputIterator __last, __false_type) { - typedef typename iterator_traits<_InputIterator>::iterator_category - _IterCategory; + typedef typename std::iterator_traits<_InputIterator>:: + iterator_category _IterCategory; _M_range_insert(__pos, __first, __last, _IterCategory()); } @@ -842,13 +894,13 @@ namespace _GLIBCXX_STD template<typename _InputIterator> void _M_range_insert(iterator __pos, _InputIterator __first, - _InputIterator __last, input_iterator_tag); + _InputIterator __last, std::input_iterator_tag); // Called by the second insert_dispatch above template<typename _ForwardIterator> void _M_range_insert(iterator __pos, _ForwardIterator __first, - _ForwardIterator __last, forward_iterator_tag); + _ForwardIterator __last, std::forward_iterator_tag); // Called by insert(p,n,x), and the range insert when it turns out to be // the same thing. @@ -858,6 +910,17 @@ namespace _GLIBCXX_STD // Called by insert(p,x) void _M_insert_aux(iterator __position, const value_type& __x); + + // Internal erase functions follow. + + // Called by erase(q1,q2), clear(), resize(), _M_fill_assign, + // _M_assign_aux. + void + _M_erase_at_end(pointer __pos) + { + std::_Destroy(__pos, this->_M_impl._M_finish, _M_get_Tp_allocator()); + this->_M_impl._M_finish = __pos; + } }; @@ -873,11 +936,9 @@ namespace _GLIBCXX_STD */ template<typename _Tp, typename _Alloc> inline bool - operator==(const vector<_Tp,_Alloc>& __x, const vector<_Tp,_Alloc>& __y) - { - return __x.size() == __y.size() && - std::equal(__x.begin(), __x.end(), __y.begin()); - } + operator==(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y) + { return (__x.size() == __y.size() + && std::equal(__x.begin(), __x.end(), __y.begin())); } /** * @brief Vector ordering relation. @@ -892,41 +953,40 @@ namespace _GLIBCXX_STD */ template<typename _Tp, typename _Alloc> inline bool - operator<(const vector<_Tp,_Alloc>& __x, const vector<_Tp,_Alloc>& __y) - { - return std::lexicographical_compare(__x.begin(), __x.end(), - __y.begin(), __y.end()); - } + operator<(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y) + { return std::lexicographical_compare(__x.begin(), __x.end(), + __y.begin(), __y.end()); } /// Based on operator== template<typename _Tp, typename _Alloc> inline bool - operator!=(const vector<_Tp,_Alloc>& __x, const vector<_Tp,_Alloc>& __y) + operator!=(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y) { return !(__x == __y); } /// Based on operator< template<typename _Tp, typename _Alloc> inline bool - operator>(const vector<_Tp,_Alloc>& __x, const vector<_Tp,_Alloc>& __y) + operator>(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y) { return __y < __x; } /// Based on operator< template<typename _Tp, typename _Alloc> inline bool - operator<=(const vector<_Tp,_Alloc>& __x, const vector<_Tp,_Alloc>& __y) + operator<=(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y) { return !(__y < __x); } /// Based on operator< template<typename _Tp, typename _Alloc> inline bool - operator>=(const vector<_Tp,_Alloc>& __x, const vector<_Tp,_Alloc>& __y) + operator>=(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y) { return !(__x < __y); } /// See std::vector::swap(). template<typename _Tp, typename _Alloc> inline void - swap(vector<_Tp,_Alloc>& __x, vector<_Tp,_Alloc>& __y) + swap(vector<_Tp, _Alloc>& __x, vector<_Tp, _Alloc>& __y) { __x.swap(__y); } -} // namespace std + +_GLIBCXX_END_NESTED_NAMESPACE #endif /* _VECTOR_H */ diff --git a/contrib/libstdc++/include/bits/stream_iterator.h b/contrib/libstdc++/include/bits/stream_iterator.h index fa11bd6..ce3e675 100644 --- a/contrib/libstdc++/include/bits/stream_iterator.h +++ b/contrib/libstdc++/include/bits/stream_iterator.h @@ -1,6 +1,6 @@ // Stream iterators -// Copyright (C) 2001, 2004 Free Software Foundation, Inc. +// Copyright (C) 2001, 2004, 2005 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 @@ -15,7 +15,7 @@ // 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// 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 @@ -39,8 +39,8 @@ #include <debug/debug.h> -namespace std -{ +_GLIBCXX_BEGIN_NAMESPACE(std) + /// Provides input iterator semantics for streams. template<typename _Tp, typename _CharT = char, typename _Traits = char_traits<_CharT>, typename _Dist = ptrdiff_t> @@ -60,7 +60,7 @@ namespace std public: /// Construct end of input stream iterator. istream_iterator() - : _M_stream(0), _M_ok(false) {} + : _M_stream(0), _M_value(), _M_ok(false) {} /// Construct start of input stream iterator. istream_iterator(istream_type& __s) @@ -210,5 +210,7 @@ namespace std operator++(int) { return *this; } }; -} // namespace std + +_GLIBCXX_END_NAMESPACE + #endif diff --git a/contrib/libstdc++/include/bits/streambuf.tcc b/contrib/libstdc++/include/bits/streambuf.tcc index 554d061..c4b8605 100644 --- a/contrib/libstdc++/include/bits/streambuf.tcc +++ b/contrib/libstdc++/include/bits/streambuf.tcc @@ -1,6 +1,6 @@ // Stream buffer classes -*- C++ -*- -// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003 +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 // Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free @@ -16,7 +16,7 @@ // 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// 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 @@ -28,6 +28,11 @@ // invalidate any other reasons why the executable file might be covered by // the GNU General Public License. +/** @file streambuf.tcc + * This is an internal header file, included by other library headers. + * You should not attempt to use it directly. + */ + // // ISO C++ 14882: 27.5 Stream buffers // @@ -37,8 +42,8 @@ #pragma GCC system_header -namespace std -{ +_GLIBCXX_BEGIN_NAMESPACE(std) + template<typename _CharT, typename _Traits> streamsize basic_streambuf<_CharT, _Traits>:: @@ -47,11 +52,11 @@ namespace std streamsize __ret = 0; while (__ret < __n) { - const size_t __buf_len = this->egptr() - this->gptr(); + const streamsize __buf_len = this->egptr() - this->gptr(); if (__buf_len) { - const size_t __remaining = __n - __ret; - const size_t __len = std::min(__buf_len, __remaining); + const streamsize __remaining = __n - __ret; + const streamsize __len = std::min(__buf_len, __remaining); traits_type::copy(__s, this->gptr(), __len); __ret += __len; __s += __len; @@ -81,11 +86,11 @@ namespace std streamsize __ret = 0; while (__ret < __n) { - const size_t __buf_len = this->epptr() - this->pptr(); + const streamsize __buf_len = this->epptr() - this->pptr(); if (__buf_len) { - const size_t __remaining = __n - __ret; - const size_t __len = std::min(__buf_len, __remaining); + const streamsize __remaining = __n - __ret; + const streamsize __len = std::min(__buf_len, __remaining); traits_type::copy(this->pptr(), __s, __len); __ret += __len; __s += __len; @@ -109,39 +114,39 @@ namespace std // Conceivably, this could be used to implement buffer-to-buffer // copies, if this was ever desired in an un-ambiguous way by the - // standard. If so, then checks for __ios being zero would be - // necessary. + // standard. template<typename _CharT, typename _Traits> streamsize - __copy_streambufs(basic_streambuf<_CharT, _Traits>* __sbin, - basic_streambuf<_CharT, _Traits>* __sbout) + __copy_streambufs_eof(basic_streambuf<_CharT, _Traits>* __sbin, + basic_streambuf<_CharT, _Traits>* __sbout, + bool& __ineof) { streamsize __ret = 0; + __ineof = true; typename _Traits::int_type __c = __sbin->sgetc(); while (!_Traits::eq_int_type(__c, _Traits::eof())) { - const size_t __n = __sbin->egptr() - __sbin->gptr(); - if (__n > 1) - { - const size_t __wrote = __sbout->sputn(__sbin->gptr(), __n); - __sbin->gbump(__wrote); - __ret += __wrote; - if (__wrote < __n) - break; - __c = __sbin->underflow(); - } - else + __c = __sbout->sputc(_Traits::to_char_type(__c)); + if (_Traits::eq_int_type(__c, _Traits::eof())) { - __c = __sbout->sputc(_Traits::to_char_type(__c)); - if (_Traits::eq_int_type(__c, _Traits::eof())) - break; - ++__ret; - __c = __sbin->snextc(); + __ineof = false; + break; } + ++__ret; + __c = __sbin->snextc(); } return __ret; } + template<typename _CharT, typename _Traits> + inline streamsize + __copy_streambufs(basic_streambuf<_CharT, _Traits>* __sbin, + basic_streambuf<_CharT, _Traits>* __sbout) + { + bool __ineof; + return __copy_streambufs_eof(__sbin, __sbout, __ineof); + } + // Inhibit implicit instantiations for required instantiations, // which are defined via explicit instantiations elsewhere. // NB: This syntax is a GNU extension. @@ -149,15 +154,26 @@ namespace std extern template class basic_streambuf<char>; extern template streamsize - __copy_streambufs(basic_streambuf<char>*, basic_streambuf<char>*); + __copy_streambufs(basic_streambuf<char>*, + basic_streambuf<char>*); + extern template + streamsize + __copy_streambufs_eof(basic_streambuf<char>*, + basic_streambuf<char>*, bool&); #ifdef _GLIBCXX_USE_WCHAR_T extern template class basic_streambuf<wchar_t>; extern template streamsize - __copy_streambufs(basic_streambuf<wchar_t>*, basic_streambuf<wchar_t>*); + __copy_streambufs(basic_streambuf<wchar_t>*, + basic_streambuf<wchar_t>*); + extern template + streamsize + __copy_streambufs_eof(basic_streambuf<wchar_t>*, + basic_streambuf<wchar_t>*, bool&); #endif #endif -} // namespace std + +_GLIBCXX_END_NAMESPACE #endif diff --git a/contrib/libstdc++/include/bits/streambuf_iterator.h b/contrib/libstdc++/include/bits/streambuf_iterator.h index 9709335..a1cf234 100644 --- a/contrib/libstdc++/include/bits/streambuf_iterator.h +++ b/contrib/libstdc++/include/bits/streambuf_iterator.h @@ -1,6 +1,6 @@ // Streambuf iterators -// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004 +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 // Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free @@ -16,7 +16,7 @@ // 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// 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 @@ -41,10 +41,8 @@ #include <streambuf> #include <debug/debug.h> -// NB: Should specialize copy, find algorithms for streambuf iterators. - -namespace std -{ +_GLIBCXX_BEGIN_NAMESPACE(std) + // 24.5.3 Template class istreambuf_iterator /// Provides input iterator semantics for streambufs. template<typename _CharT, typename _Traits> @@ -63,6 +61,24 @@ namespace std typedef basic_istream<_CharT, _Traits> istream_type; //@} + template<typename _CharT2> + friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value, + ostreambuf_iterator<_CharT2> >::__type + copy(istreambuf_iterator<_CharT2>, istreambuf_iterator<_CharT2>, + ostreambuf_iterator<_CharT2>); + + template<typename _CharT2> + friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value, + _CharT2*>::__type + __copy_aux(istreambuf_iterator<_CharT2>, istreambuf_iterator<_CharT2>, + _CharT2*); + + template<typename _CharT2> + friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value, + istreambuf_iterator<_CharT2> >::__type + find(istreambuf_iterator<_CharT2>, istreambuf_iterator<_CharT2>, + const _CharT2&); + private: // 24.5.3 istreambuf_iterator // p 1 @@ -72,7 +88,7 @@ namespace std // NB: This implementation assumes the "end of stream" value // is EOF, or -1. mutable streambuf_type* _M_sbuf; - int_type _M_c; + mutable int_type _M_c; public: /// Construct end of input stream iterator. @@ -110,11 +126,11 @@ namespace std __glibcxx_requires_cond(!_M_at_eof(), _M_message(__gnu_debug::__msg_inc_istreambuf) ._M_iterator(*this)); - const int_type __eof = traits_type::eof(); - if (_M_sbuf && traits_type::eq_int_type(_M_sbuf->sbumpc(), __eof)) - _M_sbuf = 0; - else - _M_c = __eof; + if (_M_sbuf) + { + _M_sbuf->sbumpc(); + _M_c = traits_type::eof(); + } return *this; } @@ -126,14 +142,12 @@ namespace std _M_message(__gnu_debug::__msg_inc_istreambuf) ._M_iterator(*this)); - const int_type __eof = traits_type::eof(); istreambuf_iterator __old = *this; - if (_M_sbuf - && traits_type::eq_int_type((__old._M_c = _M_sbuf->sbumpc()), - __eof)) - _M_sbuf = 0; - else - _M_c = __eof; + if (_M_sbuf) + { + __old._M_c = _M_sbuf->sbumpc(); + _M_c = traits_type::eof(); + } return __old; } @@ -159,8 +173,10 @@ namespace std { if (!traits_type::eq_int_type(_M_c, __eof)) __ret = _M_c; - else if (traits_type::eq_int_type((__ret = _M_sbuf->sgetc()), - __eof)) + else if (!traits_type::eq_int_type((__ret = _M_sbuf->sgetc()), + __eof)) + _M_c = __ret; + else _M_sbuf = 0; } return __ret; @@ -201,6 +217,12 @@ namespace std typedef basic_ostream<_CharT, _Traits> ostream_type; //@} + template<typename _CharT2> + friend typename __gnu_cxx::__enable_if<__is_char<_CharT2>::__value, + ostreambuf_iterator<_CharT2> >::__type + copy(istreambuf_iterator<_CharT2>, istreambuf_iterator<_CharT2>, + ostreambuf_iterator<_CharT2>); + private: streambuf_type* _M_sbuf; bool _M_failed; @@ -254,5 +276,125 @@ namespace std return *this; } }; -} // namespace std + + // Overloads for streambuf iterators. + template<typename _CharT> + typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value, + ostreambuf_iterator<_CharT> >::__type + copy(istreambuf_iterator<_CharT> __first, + istreambuf_iterator<_CharT> __last, + ostreambuf_iterator<_CharT> __result) + { + if (__first._M_sbuf && !__last._M_sbuf && !__result._M_failed) + { + bool __ineof; + __copy_streambufs_eof(__first._M_sbuf, __result._M_sbuf, __ineof); + if (!__ineof) + __result._M_failed = true; + } + return __result; + } + + template<typename _CharT> + typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value, + ostreambuf_iterator<_CharT> >::__type + __copy_aux(_CharT* __first, _CharT* __last, + ostreambuf_iterator<_CharT> __result) + { + const streamsize __num = __last - __first; + if (__num > 0) + __result._M_put(__first, __num); + return __result; + } + + template<typename _CharT> + typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value, + ostreambuf_iterator<_CharT> >::__type + __copy_aux(const _CharT* __first, const _CharT* __last, + ostreambuf_iterator<_CharT> __result) + { + const streamsize __num = __last - __first; + if (__num > 0) + __result._M_put(__first, __num); + return __result; + } + + template<typename _CharT> + typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value, + _CharT*>::__type + __copy_aux(istreambuf_iterator<_CharT> __first, + istreambuf_iterator<_CharT> __last, _CharT* __result) + { + typedef istreambuf_iterator<_CharT> __is_iterator_type; + typedef typename __is_iterator_type::traits_type traits_type; + typedef typename __is_iterator_type::streambuf_type streambuf_type; + typedef typename traits_type::int_type int_type; + + if (__first._M_sbuf && !__last._M_sbuf) + { + streambuf_type* __sb = __first._M_sbuf; + int_type __c = __sb->sgetc(); + while (!traits_type::eq_int_type(__c, traits_type::eof())) + { + const streamsize __n = __sb->egptr() - __sb->gptr(); + if (__n > 1) + { + traits_type::copy(__result, __sb->gptr(), __n); + __sb->gbump(__n); + __result += __n; + __c = __sb->underflow(); + } + else + { + *__result++ = traits_type::to_char_type(__c); + __c = __sb->snextc(); + } + } + } + return __result; + } + + template<typename _CharT> + typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value, + istreambuf_iterator<_CharT> >::__type + find(istreambuf_iterator<_CharT> __first, + istreambuf_iterator<_CharT> __last, const _CharT& __val) + { + typedef istreambuf_iterator<_CharT> __is_iterator_type; + typedef typename __is_iterator_type::traits_type traits_type; + typedef typename __is_iterator_type::streambuf_type streambuf_type; + typedef typename traits_type::int_type int_type; + + if (__first._M_sbuf && !__last._M_sbuf) + { + const int_type __ival = traits_type::to_int_type(__val); + streambuf_type* __sb = __first._M_sbuf; + int_type __c = __sb->sgetc(); + while (!traits_type::eq_int_type(__c, traits_type::eof()) + && !traits_type::eq_int_type(__c, __ival)) + { + streamsize __n = __sb->egptr() - __sb->gptr(); + if (__n > 1) + { + const _CharT* __p = traits_type::find(__sb->gptr(), + __n, __val); + if (__p) + __n = __p - __sb->gptr(); + __sb->gbump(__n); + __c = __sb->sgetc(); + } + else + __c = __sb->snextc(); + } + + if (!traits_type::eq_int_type(__c, traits_type::eof())) + __first._M_c = __c; + else + __first._M_sbuf = 0; + } + return __first; + } + +_GLIBCXX_END_NAMESPACE + #endif diff --git a/contrib/libstdc++/include/bits/stringfwd.h b/contrib/libstdc++/include/bits/stringfwd.h index 99d3ce3..d27ef14 100644 --- a/contrib/libstdc++/include/bits/stringfwd.h +++ b/contrib/libstdc++/include/bits/stringfwd.h @@ -1,6 +1,6 @@ // String support -*- C++ -*- -// Copyright (C) 2001, 2002 Free Software Foundation, Inc. +// Copyright (C) 2001, 2002, 2005 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 @@ -15,7 +15,7 @@ // 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// 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 @@ -27,15 +27,15 @@ // invalidate any other reasons why the executable file might be covered by // the GNU General Public License. -// -// ISO C++ 14882: 21 Strings library -// - /** @file stringfwd.h * This is an internal header file, included by other library headers. * You should not attempt to use it directly. */ +// +// ISO C++ 14882: 21 Strings library +// + #ifndef _STRINGFWD_H #define _STRINGFWD_H 1 @@ -43,8 +43,8 @@ #include <bits/c++config.h> -namespace std -{ +_GLIBCXX_BEGIN_NAMESPACE(std) + template<typename _Alloc> class allocator; @@ -64,6 +64,7 @@ namespace std typedef basic_string<wchar_t> wstring; #endif -} // namespace std + +_GLIBCXX_END_NAMESPACE #endif // _STRINGFWD_H diff --git a/contrib/libstdc++/include/bits/valarray_after.h b/contrib/libstdc++/include/bits/valarray_after.h index b74cab5..723df61 100644 --- a/contrib/libstdc++/include/bits/valarray_after.h +++ b/contrib/libstdc++/include/bits/valarray_after.h @@ -1,6 +1,7 @@ // The template and inlines for the -*- C++ -*- internal _Meta class. -// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc. +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 +// 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 @@ -15,7 +16,7 @@ // 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// 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 @@ -27,106 +28,136 @@ // invalidate any other reasons why the executable file might be covered by // the GNU General Public License. -// Written by Gabriel Dos Reis <Gabriel.Dos-Reis@cmla.ens-cachan.fr> - -/** @file valarray_meta.h +/** @file valarray_after.h * This is an internal header file, included by other library headers. * You should not attempt to use it directly. */ +// Written by Gabriel Dos Reis <Gabriel.Dos-Reis@cmla.ens-cachan.fr> + #ifndef _VALARRAY_AFTER_H #define _VALARRAY_AFTER_H 1 #pragma GCC system_header -namespace std -{ +_GLIBCXX_BEGIN_NAMESPACE(std) - // - // gslice_array closure. - // - template<class _Dom> class _GBase { + // + // gslice_array closure. + // + template<class _Dom> + class _GBase + { public: - typedef typename _Dom::value_type value_type; - - _GBase (const _Dom& __e, const valarray<size_t>& __i) - : _M_expr (__e), _M_index(__i) {} - value_type operator[] (size_t __i) const - { return _M_expr[_M_index[__i]]; } - size_t size () const { return _M_index.size(); } + typedef typename _Dom::value_type value_type; + + _GBase (const _Dom& __e, const valarray<size_t>& __i) + : _M_expr (__e), _M_index(__i) {} + + value_type + operator[] (size_t __i) const + { return _M_expr[_M_index[__i]]; } + + size_t + size () const + { return _M_index.size(); } private: - const _Dom& _M_expr; - const valarray<size_t>& _M_index; + const _Dom& _M_expr; + const valarray<size_t>& _M_index; }; - template<typename _Tp> class _GBase<_Array<_Tp> > { + template<typename _Tp> + class _GBase<_Array<_Tp> > + { public: - typedef _Tp value_type; - - _GBase (_Array<_Tp> __a, const valarray<size_t>& __i) - : _M_array (__a), _M_index(__i) {} - value_type operator[] (size_t __i) const - { return _M_array._M_data[_M_index[__i]]; } - size_t size () const { return _M_index.size(); } + typedef _Tp value_type; + + _GBase (_Array<_Tp> __a, const valarray<size_t>& __i) + : _M_array (__a), _M_index(__i) {} + + value_type + operator[] (size_t __i) const + { return _M_array._M_data[_M_index[__i]]; } + + size_t + size () const + { return _M_index.size(); } private: - const _Array<_Tp> _M_array; - const valarray<size_t>& _M_index; + const _Array<_Tp> _M_array; + const valarray<size_t>& _M_index; }; - template<class _Dom> struct _GClos<_Expr,_Dom> : _GBase<_Dom> { - typedef _GBase<_Dom> _Base; - typedef typename _Base::value_type value_type; - - _GClos (const _Dom& __e, const valarray<size_t>& __i) - : _Base (__e, __i) {} + template<class _Dom> + struct _GClos<_Expr, _Dom> + : _GBase<_Dom> + { + typedef _GBase<_Dom> _Base; + typedef typename _Base::value_type value_type; + + _GClos (const _Dom& __e, const valarray<size_t>& __i) + : _Base (__e, __i) {} }; - template<typename _Tp> - struct _GClos<_ValArray,_Tp> : _GBase<_Array<_Tp> > { - typedef _GBase<_Array<_Tp> > _Base; - typedef typename _Base::value_type value_type; - - _GClos (_Array<_Tp> __a, const valarray<size_t>& __i) - : _Base (__a, __i) {} + template<typename _Tp> + struct _GClos<_ValArray, _Tp> + : _GBase<_Array<_Tp> > + { + typedef _GBase<_Array<_Tp> > _Base; + typedef typename _Base::value_type value_type; + + _GClos (_Array<_Tp> __a, const valarray<size_t>& __i) + : _Base (__a, __i) {} }; - // - // indirect_array closure - // - template<class _Dom> class _IBase { + // + // indirect_array closure + // + template<class _Dom> + class _IBase + { public: - typedef typename _Dom::value_type value_type; - - _IBase (const _Dom& __e, const valarray<size_t>& __i) - : _M_expr (__e), _M_index (__i) {} - value_type operator[] (size_t __i) const - { return _M_expr[_M_index[__i]]; } - size_t size() const { return _M_index.size(); } + typedef typename _Dom::value_type value_type; + + _IBase (const _Dom& __e, const valarray<size_t>& __i) + : _M_expr (__e), _M_index (__i) {} + + value_type + operator[] (size_t __i) const + { return _M_expr[_M_index[__i]]; } + + size_t + size() const + { return _M_index.size(); } private: - const _Dom& _M_expr; - const valarray<size_t>& _M_index; + const _Dom& _M_expr; + const valarray<size_t>& _M_index; }; - template<class _Dom> struct _IClos<_Expr,_Dom> : _IBase<_Dom> { - typedef _IBase<_Dom> _Base; - typedef typename _Base::value_type value_type; - - _IClos (const _Dom& __e, const valarray<size_t>& __i) - : _Base (__e, __i) {} + template<class _Dom> + struct _IClos<_Expr, _Dom> + : _IBase<_Dom> + { + typedef _IBase<_Dom> _Base; + typedef typename _Base::value_type value_type; + + _IClos (const _Dom& __e, const valarray<size_t>& __i) + : _Base (__e, __i) {} }; - template<typename _Tp> - struct _IClos<_ValArray,_Tp> : _IBase<valarray<_Tp> > { - typedef _IBase<valarray<_Tp> > _Base; - typedef _Tp value_type; - - _IClos (const valarray<_Tp>& __a, const valarray<size_t>& __i) - : _Base (__a, __i) {} + template<typename _Tp> + struct _IClos<_ValArray, _Tp> + : _IBase<valarray<_Tp> > + { + typedef _IBase<valarray<_Tp> > _Base; + typedef _Tp value_type; + + _IClos (const valarray<_Tp>& __a, const valarray<size_t>& __i) + : _Base (__a, __i) {} }; - + // // class _Expr // @@ -146,17 +177,17 @@ namespace std valarray<value_type> operator[](const valarray<bool>&) const; valarray<value_type> operator[](const valarray<size_t>&) const; - _Expr<_UnClos<__unary_plus,std::_Expr,_Clos>, value_type> - operator+() const; + _Expr<_UnClos<__unary_plus, std::_Expr, _Clos>, value_type> + operator+() const; - _Expr<_UnClos<__negate,std::_Expr,_Clos>, value_type> - operator-() const; + _Expr<_UnClos<__negate, std::_Expr, _Clos>, value_type> + operator-() const; - _Expr<_UnClos<__bitwise_not,std::_Expr,_Clos>, value_type> - operator~() const; + _Expr<_UnClos<__bitwise_not, std::_Expr, _Clos>, value_type> + operator~() const; - _Expr<_UnClos<__logical_not,std::_Expr,_Clos>, bool> - operator!() const; + _Expr<_UnClos<__logical_not, std::_Expr, _Clos>, bool> + operator!() const; size_t size() const; value_type sum() const; @@ -176,66 +207,91 @@ namespace std template<class _Clos, typename _Tp> inline - _Expr<_Clos,_Tp>::_Expr(const _Clos& __c) : _M_closure(__c) {} + _Expr<_Clos, _Tp>::_Expr(const _Clos& __c) : _M_closure(__c) {} template<class _Clos, typename _Tp> inline const _Clos& - _Expr<_Clos,_Tp>::operator()() const + _Expr<_Clos, _Tp>::operator()() const { return _M_closure; } template<class _Clos, typename _Tp> inline _Tp - _Expr<_Clos,_Tp>::operator[](size_t __i) const + _Expr<_Clos, _Tp>::operator[](size_t __i) const { return _M_closure[__i]; } template<class _Clos, typename _Tp> inline valarray<_Tp> - _Expr<_Clos,_Tp>::operator[](slice __s) const - { return _M_closure[__s]; } + _Expr<_Clos, _Tp>::operator[](slice __s) const + { + valarray<_Tp> __v = valarray<_Tp>(*this)[__s]; + return __v; + } template<class _Clos, typename _Tp> inline valarray<_Tp> - _Expr<_Clos,_Tp>::operator[](const gslice& __gs) const - { return _M_closure[__gs]; } + _Expr<_Clos, _Tp>::operator[](const gslice& __gs) const + { + valarray<_Tp> __v = valarray<_Tp>(*this)[__gs]; + return __v; + } template<class _Clos, typename _Tp> inline valarray<_Tp> - _Expr<_Clos,_Tp>::operator[](const valarray<bool>& __m) const - { return _M_closure[__m]; } + _Expr<_Clos, _Tp>::operator[](const valarray<bool>& __m) const + { + valarray<_Tp> __v = valarray<_Tp>(*this)[__m]; + return __v; + } template<class _Clos, typename _Tp> inline valarray<_Tp> - _Expr<_Clos,_Tp>::operator[](const valarray<size_t>& __i) const - { return _M_closure[__i]; } + _Expr<_Clos, _Tp>::operator[](const valarray<size_t>& __i) const + { + valarray<_Tp> __v = valarray<_Tp>(*this)[__i]; + return __v; + } template<class _Clos, typename _Tp> inline size_t - _Expr<_Clos,_Tp>::size() const { return _M_closure.size (); } + _Expr<_Clos, _Tp>::size() const + { return _M_closure.size(); } template<class _Clos, typename _Tp> inline valarray<_Tp> _Expr<_Clos, _Tp>::shift(int __n) const - { return valarray<_Tp>(_M_closure).shift(__n); } + { + valarray<_Tp> __v = valarray<_Tp>(*this).shift(__n); + return __v; + } template<class _Clos, typename _Tp> inline valarray<_Tp> _Expr<_Clos, _Tp>::cshift(int __n) const - { return valarray<_Tp>(_M_closure).cshift(__n); } + { + valarray<_Tp> __v = valarray<_Tp>(*this).cshift(__n); + return __v; + } template<class _Clos, typename _Tp> inline valarray<_Tp> _Expr<_Clos, _Tp>::apply(_Tp __f(const _Tp&)) const - { return valarray<_Tp>(_M_closure).apply(__f); } + { + valarray<_Tp> __v = valarray<_Tp>(*this).apply(__f); + return __v; + } template<class _Clos, typename _Tp> inline valarray<_Tp> _Expr<_Clos, _Tp>::apply(_Tp __f(_Tp)) const - { return valarray<_Tp>(_M_closure).apply(__f); } + { + valarray<_Tp> __v = valarray<_Tp>(*this).apply(__f); + return __v; + } // XXX: replace this with a more robust summation algorithm. template<class _Clos, typename _Tp> inline _Tp - _Expr<_Clos,_Tp>::sum() const + _Expr<_Clos, _Tp>::sum() const { size_t __n = _M_closure.size(); if (__n == 0) @@ -260,20 +316,20 @@ namespace std { return __valarray_max(_M_closure); } template<class _Dom, typename _Tp> - inline _Expr<_UnClos<__logical_not,_Expr,_Dom>, bool> - _Expr<_Dom,_Tp>::operator!() const + inline _Expr<_UnClos<__logical_not, _Expr, _Dom>, bool> + _Expr<_Dom, _Tp>::operator!() const { - typedef _UnClos<__logical_not,std::_Expr,_Dom> _Closure; - return _Expr<_Closure,_Tp>(_Closure(this->_M_closure)); + typedef _UnClos<__logical_not, std::_Expr, _Dom> _Closure; + return _Expr<_Closure, _Tp>(_Closure(this->_M_closure)); } #define _DEFINE_EXPR_UNARY_OPERATOR(_Op, _Name) \ template<class _Dom, typename _Tp> \ - inline _Expr<_UnClos<_Name,std::_Expr,_Dom>,_Tp> \ - _Expr<_Dom,_Tp>::operator _Op() const \ + inline _Expr<_UnClos<_Name, std::_Expr, _Dom>, _Tp> \ + _Expr<_Dom, _Tp>::operator _Op() const \ { \ - typedef _UnClos<_Name,std::_Expr,_Dom> _Closure; \ - return _Expr<_Closure,_Tp>(_Closure(this->_M_closure)); \ + typedef _UnClos<_Name, std::_Expr, _Dom> _Closure; \ + return _Expr<_Closure, _Tp>(_Closure(this->_M_closure)); \ } _DEFINE_EXPR_UNARY_OPERATOR(+, __unary_plus) @@ -282,67 +338,70 @@ namespace std #undef _DEFINE_EXPR_UNARY_OPERATOR - #define _DEFINE_EXPR_BINARY_OPERATOR(_Op, _Name) \ template<class _Dom1, class _Dom2> \ - inline _Expr<_BinClos<_Name,_Expr,_Expr,_Dom1,_Dom2>, \ - typename __fun<_Name, typename _Dom1::value_type>::result_type>\ - operator _Op(const _Expr<_Dom1,typename _Dom1::value_type>& __v, \ - const _Expr<_Dom2,typename _Dom2::value_type>& __w) \ - { \ - typedef typename _Dom1::value_type _Arg; \ - typedef typename __fun<_Name, _Arg>::result_type _Value; \ - typedef _BinClos<_Name,_Expr,_Expr,_Dom1,_Dom2> _Closure; \ - return _Expr<_Closure,_Value>(_Closure(__v(), __w())); \ - } \ + inline _Expr<_BinClos<_Name, _Expr, _Expr, _Dom1, _Dom2>, \ + typename __fun<_Name, typename _Dom1::value_type>::result_type> \ + operator _Op(const _Expr<_Dom1, typename _Dom1::value_type>& __v, \ + const _Expr<_Dom2, typename _Dom2::value_type>& __w) \ + { \ + typedef typename _Dom1::value_type _Arg; \ + typedef typename __fun<_Name, _Arg>::result_type _Value; \ + typedef _BinClos<_Name, _Expr, _Expr, _Dom1, _Dom2> _Closure; \ + return _Expr<_Closure, _Value>(_Closure(__v(), __w())); \ + } \ \ -template<class _Dom> \ -inline _Expr<_BinClos<_Name,_Expr,_Constant,_Dom,typename _Dom::value_type>,\ - typename __fun<_Name, typename _Dom::value_type>::result_type>\ -operator _Op(const _Expr<_Dom,typename _Dom::value_type>& __v, \ - const typename _Dom::value_type& __t) \ -{ \ - typedef typename _Dom::value_type _Arg; \ - typedef typename __fun<_Name, _Arg>::result_type _Value; \ - typedef _BinClos<_Name,_Expr,_Constant,_Dom,_Arg> _Closure; \ - return _Expr<_Closure,_Value>(_Closure(__v(), __t)); \ -} \ + template<class _Dom> \ + inline _Expr<_BinClos<_Name, _Expr, _Constant, _Dom, \ + typename _Dom::value_type>, \ + typename __fun<_Name, typename _Dom::value_type>::result_type> \ + operator _Op(const _Expr<_Dom, typename _Dom::value_type>& __v, \ + const typename _Dom::value_type& __t) \ + { \ + typedef typename _Dom::value_type _Arg; \ + typedef typename __fun<_Name, _Arg>::result_type _Value; \ + typedef _BinClos<_Name, _Expr, _Constant, _Dom, _Arg> _Closure; \ + return _Expr<_Closure, _Value>(_Closure(__v(), __t)); \ + } \ \ -template<class _Dom> \ -inline _Expr<_BinClos<_Name,_Constant,_Expr,typename _Dom::value_type,_Dom>,\ - typename __fun<_Name, typename _Dom::value_type>::result_type>\ -operator _Op(const typename _Dom::value_type& __t, \ - const _Expr<_Dom,typename _Dom::value_type>& __v) \ -{ \ - typedef typename _Dom::value_type _Arg; \ - typedef typename __fun<_Name, _Arg>::result_type _Value; \ - typedef _BinClos<_Name,_Constant,_Expr,_Arg,_Dom> _Closure; \ - return _Expr<_Closure,_Value>(_Closure(__t, __v())); \ -} \ + template<class _Dom> \ + inline _Expr<_BinClos<_Name, _Constant, _Expr, \ + typename _Dom::value_type, _Dom>, \ + typename __fun<_Name, typename _Dom::value_type>::result_type> \ + operator _Op(const typename _Dom::value_type& __t, \ + const _Expr<_Dom, typename _Dom::value_type>& __v) \ + { \ + typedef typename _Dom::value_type _Arg; \ + typedef typename __fun<_Name, _Arg>::result_type _Value; \ + typedef _BinClos<_Name, _Constant, _Expr, _Arg, _Dom> _Closure; \ + return _Expr<_Closure, _Value>(_Closure(__t, __v())); \ + } \ \ -template<class _Dom> \ -inline _Expr<_BinClos<_Name,_Expr,_ValArray,_Dom,typename _Dom::value_type>,\ - typename __fun<_Name, typename _Dom::value_type>::result_type>\ -operator _Op(const _Expr<_Dom,typename _Dom::value_type>& __e, \ - const valarray<typename _Dom::value_type>& __v) \ -{ \ - typedef typename _Dom::value_type _Arg; \ - typedef typename __fun<_Name, _Arg>::result_type _Value; \ - typedef _BinClos<_Name,_Expr,_ValArray,_Dom,_Arg> _Closure; \ - return _Expr<_Closure,_Value>(_Closure(__e(), __v)); \ -} \ + template<class _Dom> \ + inline _Expr<_BinClos<_Name, _Expr, _ValArray, \ + _Dom, typename _Dom::value_type>, \ + typename __fun<_Name, typename _Dom::value_type>::result_type> \ + operator _Op(const _Expr<_Dom,typename _Dom::value_type>& __e, \ + const valarray<typename _Dom::value_type>& __v) \ + { \ + typedef typename _Dom::value_type _Arg; \ + typedef typename __fun<_Name, _Arg>::result_type _Value; \ + typedef _BinClos<_Name, _Expr, _ValArray, _Dom, _Arg> _Closure; \ + return _Expr<_Closure, _Value>(_Closure(__e(), __v)); \ + } \ \ -template<class _Dom> \ -inline _Expr<_BinClos<_Name,_ValArray,_Expr,typename _Dom::value_type,_Dom>,\ - typename __fun<_Name, typename _Dom::value_type>::result_type>\ -operator _Op(const valarray<typename _Dom::value_type>& __v, \ - const _Expr<_Dom,typename _Dom::value_type>& __e) \ -{ \ - typedef typename _Dom::value_type _Tp; \ - typedef typename __fun<_Name, _Tp>::result_type _Value; \ - typedef _BinClos<_Name,_ValArray,_Expr,_Tp,_Dom> _Closure; \ - return _Expr<_Closure,_Value> (_Closure (__v, __e ())); \ -} + template<class _Dom> \ + inline _Expr<_BinClos<_Name, _ValArray, _Expr, \ + typename _Dom::value_type, _Dom>, \ + typename __fun<_Name, typename _Dom::value_type>::result_type> \ + operator _Op(const valarray<typename _Dom::value_type>& __v, \ + const _Expr<_Dom, typename _Dom::value_type>& __e) \ + { \ + typedef typename _Dom::value_type _Tp; \ + typedef typename __fun<_Name, _Tp>::result_type _Value; \ + typedef _BinClos<_Name, _ValArray, _Expr, _Tp, _Dom> _Closure; \ + return _Expr<_Closure, _Value>(_Closure(__v, __e ())); \ + } _DEFINE_EXPR_BINARY_OPERATOR(+, __plus) _DEFINE_EXPR_BINARY_OPERATOR(-, __minus) @@ -367,20 +426,21 @@ operator _Op(const valarray<typename _Dom::value_type>& __v, \ #define _DEFINE_EXPR_UNARY_FUNCTION(_Name) \ template<class _Dom> \ - inline _Expr<_UnClos<__##_Name,_Expr,_Dom>,typename _Dom::value_type>\ - _Name(const _Expr<_Dom,typename _Dom::value_type>& __e) \ + inline _Expr<_UnClos<__##_Name, _Expr, _Dom>, \ + typename _Dom::value_type> \ + _Name(const _Expr<_Dom, typename _Dom::value_type>& __e) \ { \ typedef typename _Dom::value_type _Tp; \ - typedef _UnClos<__##_Name,_Expr,_Dom> _Closure; \ - return _Expr<_Closure,_Tp>(_Closure(__e())); \ + typedef _UnClos<__##_Name, _Expr, _Dom> _Closure; \ + return _Expr<_Closure, _Tp>(_Closure(__e())); \ } \ \ template<typename _Tp> \ - inline _Expr<_UnClos<__##_Name,_ValArray,_Tp>,_Tp> \ + inline _Expr<_UnClos<__##_Name, _ValArray, _Tp>, _Tp> \ _Name(const valarray<_Tp>& __v) \ { \ - typedef _UnClos<__##_Name,_ValArray,_Tp> _Closure; \ - return _Expr<_Closure,_Tp>(_Closure(__v)); \ + typedef _UnClos<__##_Name, _ValArray, _Tp> _Closure; \ + return _Expr<_Closure, _Tp>(_Closure(__v)); \ } _DEFINE_EXPR_UNARY_FUNCTION(abs) @@ -402,86 +462,86 @@ operator _Op(const valarray<typename _Dom::value_type>& __v, \ #define _DEFINE_EXPR_BINARY_FUNCTION(_Fun) \ template<class _Dom1, class _Dom2> \ - inline _Expr<_BinClos<__##_Fun,_Expr,_Expr,_Dom1,_Dom2>, \ + inline _Expr<_BinClos<__##_Fun, _Expr, _Expr, _Dom1, _Dom2>, \ typename _Dom1::value_type> \ - _Fun(const _Expr<_Dom1,typename _Dom1::value_type>& __e1, \ - const _Expr<_Dom2,typename _Dom2::value_type>& __e2) \ + _Fun(const _Expr<_Dom1, typename _Dom1::value_type>& __e1, \ + const _Expr<_Dom2, typename _Dom2::value_type>& __e2) \ { \ typedef typename _Dom1::value_type _Tp; \ - typedef _BinClos<__##_Fun,_Expr,_Expr,_Dom1,_Dom2> _Closure; \ - return _Expr<_Closure,_Tp>(_Closure(__e1(), __e2())); \ + typedef _BinClos<__##_Fun, _Expr, _Expr, _Dom1, _Dom2> _Closure; \ + return _Expr<_Closure, _Tp>(_Closure(__e1(), __e2())); \ } \ \ template<class _Dom> \ inline _Expr<_BinClos<__##_Fun, _Expr, _ValArray, _Dom, \ typename _Dom::value_type>, \ typename _Dom::value_type> \ - _Fun(const _Expr<_Dom,typename _Dom::value_type>& __e, \ + _Fun(const _Expr<_Dom, typename _Dom::value_type>& __e, \ const valarray<typename _Dom::value_type>& __v) \ { \ typedef typename _Dom::value_type _Tp; \ - typedef _BinClos<__##_Fun, _Expr, _ValArray, _Dom, _Tp> _Closure;\ - return _Expr<_Closure,_Tp>(_Closure(__e(), __v)); \ + typedef _BinClos<__##_Fun, _Expr, _ValArray, _Dom, _Tp> _Closure; \ + return _Expr<_Closure, _Tp>(_Closure(__e(), __v)); \ } \ \ template<class _Dom> \ inline _Expr<_BinClos<__##_Fun, _ValArray, _Expr, \ - typename _Dom::value_type,_Dom>, \ + typename _Dom::value_type, _Dom>, \ typename _Dom::value_type> \ _Fun(const valarray<typename _Dom::valarray>& __v, \ - const _Expr<_Dom,typename _Dom::value_type>& __e) \ + const _Expr<_Dom, typename _Dom::value_type>& __e) \ { \ typedef typename _Dom::value_type _Tp; \ - typedef _BinClos<__##_Fun,_ValArray,_Expr,_Tp,_Dom> _Closure; \ - return _Expr<_Closure,_Tp>(_Closure(__v, __e())); \ + typedef _BinClos<__##_Fun, _ValArray, _Expr, _Tp, _Dom> _Closure; \ + return _Expr<_Closure, _Tp>(_Closure(__v, __e())); \ } \ \ template<class _Dom> \ - inline _Expr<_BinClos<__##_Fun,_Expr,_Constant,_Dom, \ + inline _Expr<_BinClos<__##_Fun, _Expr, _Constant, _Dom, \ typename _Dom::value_type>, \ typename _Dom::value_type> \ _Fun(const _Expr<_Dom, typename _Dom::value_type>& __e, \ const typename _Dom::value_type& __t) \ { \ typedef typename _Dom::value_type _Tp; \ - typedef _BinClos<__##_Fun,_Expr,_Constant,_Dom,_Tp> _Closure; \ - return _Expr<_Closure,_Tp>(_Closure(__e(), __t)); \ + typedef _BinClos<__##_Fun, _Expr, _Constant, _Dom, _Tp> _Closure;\ + return _Expr<_Closure, _Tp>(_Closure(__e(), __t)); \ } \ \ template<class _Dom> \ - inline _Expr<_BinClos<__##_Fun,_Constant,_Expr, \ - typename _Dom::value_type,_Dom>, \ + inline _Expr<_BinClos<__##_Fun, _Constant, _Expr, \ + typename _Dom::value_type, _Dom>, \ typename _Dom::value_type> \ _Fun(const typename _Dom::value_type& __t, \ - const _Expr<_Dom,typename _Dom::value_type>& __e) \ + const _Expr<_Dom, typename _Dom::value_type>& __e) \ { \ typedef typename _Dom::value_type _Tp; \ - typedef _BinClos<__##_Fun, _Constant,_Expr,_Tp,_Dom> _Closure; \ - return _Expr<_Closure,_Tp>(_Closure(__t, __e())); \ + typedef _BinClos<__##_Fun, _Constant, _Expr, _Tp, _Dom> _Closure; \ + return _Expr<_Closure, _Tp>(_Closure(__t, __e())); \ } \ \ template<typename _Tp> \ - inline _Expr<_BinClos<__##_Fun,_ValArray,_ValArray,_Tp,_Tp>, _Tp> \ + inline _Expr<_BinClos<__##_Fun, _ValArray, _ValArray, _Tp, _Tp>, _Tp> \ _Fun(const valarray<_Tp>& __v, const valarray<_Tp>& __w) \ { \ - typedef _BinClos<__##_Fun,_ValArray,_ValArray,_Tp,_Tp> _Closure; \ - return _Expr<_Closure,_Tp>(_Closure(__v, __w)); \ + typedef _BinClos<__##_Fun, _ValArray, _ValArray, _Tp, _Tp> _Closure; \ + return _Expr<_Closure, _Tp>(_Closure(__v, __w)); \ } \ \ template<typename _Tp> \ - inline _Expr<_BinClos<__##_Fun,_ValArray,_Constant,_Tp,_Tp>,_Tp> \ + inline _Expr<_BinClos<__##_Fun, _ValArray, _Constant, _Tp, _Tp>, _Tp> \ _Fun(const valarray<_Tp>& __v, const _Tp& __t) \ { \ - typedef _BinClos<__##_Fun,_ValArray,_Constant,_Tp,_Tp> _Closure; \ - return _Expr<_Closure,_Tp>(_Closure(__v, __t)); \ + typedef _BinClos<__##_Fun, _ValArray, _Constant, _Tp, _Tp> _Closure; \ + return _Expr<_Closure, _Tp>(_Closure(__v, __t)); \ } \ \ template<typename _Tp> \ - inline _Expr<_BinClos<__##_Fun,_Constant,_ValArray,_Tp,_Tp>,_Tp> \ + inline _Expr<_BinClos<__##_Fun, _Constant, _ValArray, _Tp, _Tp>, _Tp> \ _Fun(const _Tp& __t, const valarray<_Tp>& __v) \ { \ - typedef _BinClos<__##_Fun,_Constant,_ValArray,_Tp,_Tp> _Closure; \ - return _Expr<_Closure,_Tp>(_Closure(__t, __v)); \ + typedef _BinClos<__##_Fun, _Constant, _ValArray, _Tp, _Tp> _Closure; \ + return _Expr<_Closure, _Tp>(_Closure(__t, __v)); \ } _DEFINE_EXPR_BINARY_FUNCTION(atan2) @@ -489,11 +549,6 @@ _DEFINE_EXPR_BINARY_FUNCTION(pow) #undef _DEFINE_EXPR_BINARY_FUNCTION -} // std:: - +_GLIBCXX_END_NAMESPACE #endif /* _CPP_VALARRAY_AFTER_H */ - -// Local Variables: -// mode:c++ -// End: diff --git a/contrib/libstdc++/include/bits/valarray_array.h b/contrib/libstdc++/include/bits/valarray_array.h index e18e8e8..a40c880 100644 --- a/contrib/libstdc++/include/bits/valarray_array.h +++ b/contrib/libstdc++/include/bits/valarray_array.h @@ -1,6 +1,6 @@ // The template and inlines for the -*- C++ -*- internal _Array helper class. -// Copyright (C) 1997, 1998, 1999, 2000, 2003 +// Copyright (C) 1997, 1998, 1999, 2000, 2003, 2004, 2005, 2006 // Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free @@ -16,7 +16,7 @@ // 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// 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 @@ -28,13 +28,13 @@ // invalidate any other reasons why the executable file might be covered by // the GNU General Public License. -// Written by Gabriel Dos Reis <Gabriel.Dos-Reis@DPTMaths.ENS-Cachan.Fr> - /** @file valarray_array.h * This is an internal header file, included by other library headers. * You should not attempt to use it directly. */ +// Written by Gabriel Dos Reis <Gabriel.Dos-Reis@DPTMaths.ENS-Cachan.Fr> + #ifndef _VALARRAY_ARRAY_H #define _VALARRAY_ARRAY_H 1 @@ -46,8 +46,8 @@ #include <cstring> #include <new> -namespace std -{ +_GLIBCXX_BEGIN_NAMESPACE(std) + // // Helper functions on raw pointers // @@ -58,12 +58,12 @@ namespace std { return operator new(__n); } template<typename _Tp> - inline _Tp*__restrict__ - __valarray_get_storage(size_t __n) - { - return static_cast<_Tp*__restrict__> - (std::__valarray_get_memory(__n * sizeof(_Tp))); - } + inline _Tp*__restrict__ + __valarray_get_storage(size_t __n) + { + return static_cast<_Tp*__restrict__> + (std::__valarray_get_memory(__n * sizeof(_Tp))); + } // Return memory to the system inline void @@ -73,230 +73,275 @@ namespace std // Turn a raw-memory into an array of _Tp filled with _Tp() // This is required in 'valarray<T> v(n);' template<typename _Tp, bool> - struct _Array_default_ctor - { - // Please note that this isn't exception safe. But - // valarrays aren't required to be exception safe. - inline static void - _S_do_it(_Tp* __restrict__ __b, _Tp* __restrict__ __e) - { while (__b != __e) new(__b++) _Tp(); } - }; - - template<typename _Tp> - struct _Array_default_ctor<_Tp, true> - { - // For fundamental types, it suffices to say 'memset()' - inline static void - _S_do_it(_Tp* __restrict__ __b, _Tp* __restrict__ __e) - { std::memset(__b, 0, (__e - __b)*sizeof(_Tp)); } - }; - - template<typename _Tp> - inline void - __valarray_default_construct(_Tp* __restrict__ __b, _Tp* __restrict__ __e) - { - _Array_default_ctor<_Tp, __is_fundamental<_Tp>::_M_type>:: - _S_do_it(__b, __e); - } + struct _Array_default_ctor + { + // Please note that this isn't exception safe. But + // valarrays aren't required to be exception safe. + inline static void + _S_do_it(_Tp* __restrict__ __b, _Tp* __restrict__ __e) + { + while (__b != __e) + new(__b++) _Tp(); + } + }; + + template<typename _Tp> + struct _Array_default_ctor<_Tp, true> + { + // For fundamental types, it suffices to say 'memset()' + inline static void + _S_do_it(_Tp* __restrict__ __b, _Tp* __restrict__ __e) + { std::memset(__b, 0, (__e - __b) * sizeof(_Tp)); } + }; + + template<typename _Tp> + inline void + __valarray_default_construct(_Tp* __restrict__ __b, _Tp* __restrict__ __e) + { + _Array_default_ctor<_Tp, __is_pod<_Tp>::__value>::_S_do_it(__b, __e); + } // Turn a raw-memory into an array of _Tp filled with __t // This is the required in valarray<T> v(n, t). Also // used in valarray<>::resize(). template<typename _Tp, bool> - struct _Array_init_ctor - { - // Please note that this isn't exception safe. But - // valarrays aren't required to be exception safe. - inline static void - _S_do_it(_Tp* __restrict__ __b, _Tp* __restrict__ __e, const _Tp __t) - { while (__b != __e) new(__b++) _Tp(__t); } - }; - - template<typename _Tp> - struct _Array_init_ctor<_Tp, true> - { - inline static void - _S_do_it(_Tp* __restrict__ __b, _Tp* __restrict__ __e, const _Tp __t) - { while (__b != __e) *__b++ = __t; } - }; - - template<typename _Tp> - inline void - __valarray_fill_construct(_Tp* __restrict__ __b, _Tp* __restrict__ __e, - const _Tp __t) - { - _Array_init_ctor<_Tp, __is_fundamental<_Tp>::_M_type>:: - _S_do_it(__b, __e, __t); - } + struct _Array_init_ctor + { + // Please note that this isn't exception safe. But + // valarrays aren't required to be exception safe. + inline static void + _S_do_it(_Tp* __restrict__ __b, _Tp* __restrict__ __e, const _Tp __t) + { + while (__b != __e) + new(__b++) _Tp(__t); + } + }; + + template<typename _Tp> + struct _Array_init_ctor<_Tp, true> + { + inline static void + _S_do_it(_Tp* __restrict__ __b, _Tp* __restrict__ __e, const _Tp __t) + { + while (__b != __e) + *__b++ = __t; + } + }; + + template<typename _Tp> + inline void + __valarray_fill_construct(_Tp* __restrict__ __b, _Tp* __restrict__ __e, + const _Tp __t) + { + _Array_init_ctor<_Tp, __is_pod<_Tp>::__value>::_S_do_it(__b, __e, __t); + } // // copy-construct raw array [__o, *) from plain array [__b, __e) // We can't just say 'memcpy()' // template<typename _Tp, bool> - struct _Array_copy_ctor - { - // Please note that this isn't exception safe. But - // valarrays aren't required to be exception safe. - inline static void - _S_do_it(const _Tp* __restrict__ __b, const _Tp* __restrict__ __e, - _Tp* __restrict__ __o) - { while (__b != __e) new(__o++) _Tp(*__b++); } - }; - - template<typename _Tp> - struct _Array_copy_ctor<_Tp, true> - { - inline static void - _S_do_it(const _Tp* __restrict__ __b, const _Tp* __restrict__ __e, - _Tp* __restrict__ __o) - { std::memcpy(__o, __b, (__e - __b)*sizeof(_Tp)); } - }; - - template<typename _Tp> - inline void - __valarray_copy_construct(const _Tp* __restrict__ __b, - const _Tp* __restrict__ __e, - _Tp* __restrict__ __o) - { - _Array_copy_ctor<_Tp, __is_fundamental<_Tp>::_M_type>:: - _S_do_it(__b, __e, __o); - } + struct _Array_copy_ctor + { + // Please note that this isn't exception safe. But + // valarrays aren't required to be exception safe. + inline static void + _S_do_it(const _Tp* __restrict__ __b, const _Tp* __restrict__ __e, + _Tp* __restrict__ __o) + { + while (__b != __e) + new(__o++) _Tp(*__b++); + } + }; + + template<typename _Tp> + struct _Array_copy_ctor<_Tp, true> + { + inline static void + _S_do_it(const _Tp* __restrict__ __b, const _Tp* __restrict__ __e, + _Tp* __restrict__ __o) + { std::memcpy(__o, __b, (__e - __b)*sizeof(_Tp)); } + }; + + template<typename _Tp> + inline void + __valarray_copy_construct(const _Tp* __restrict__ __b, + const _Tp* __restrict__ __e, + _Tp* __restrict__ __o) + { + _Array_copy_ctor<_Tp, __is_pod<_Tp>::__value>::_S_do_it(__b, __e, __o); + } // copy-construct raw array [__o, *) from strided array __a[<__n : __s>] template<typename _Tp> - inline void - __valarray_copy_construct (const _Tp* __restrict__ __a, size_t __n, - size_t __s, _Tp* __restrict__ __o) - { - if (__is_fundamental<_Tp>::_M_type) - while (__n--) { *__o++ = *__a; __a += __s; } - else - while (__n--) { new(__o++) _Tp(*__a); __a += __s; } - } + inline void + __valarray_copy_construct (const _Tp* __restrict__ __a, size_t __n, + size_t __s, _Tp* __restrict__ __o) + { + if (__is_pod<_Tp>::__value) + while (__n--) + { + *__o++ = *__a; + __a += __s; + } + else + while (__n--) + { + new(__o++) _Tp(*__a); + __a += __s; + } + } // copy-construct raw array [__o, *) from indexed array __a[__i[<__n>]] template<typename _Tp> - inline void - __valarray_copy_construct (const _Tp* __restrict__ __a, - const size_t* __restrict__ __i, - _Tp* __restrict__ __o, size_t __n) - { - if (__is_fundamental<_Tp>::_M_type) - while (__n--) *__o++ = __a[*__i++]; - else - while (__n--) new (__o++) _Tp(__a[*__i++]); - } + inline void + __valarray_copy_construct (const _Tp* __restrict__ __a, + const size_t* __restrict__ __i, + _Tp* __restrict__ __o, size_t __n) + { + if (__is_pod<_Tp>::__value) + while (__n--) + *__o++ = __a[*__i++]; + else + while (__n--) + new (__o++) _Tp(__a[*__i++]); + } // Do the necessary cleanup when we're done with arrays. template<typename _Tp> - inline void - __valarray_destroy_elements(_Tp* __restrict__ __b, _Tp* __restrict__ __e) - { - if (!__is_fundamental<_Tp>::_M_type) - while (__b != __e) { __b->~_Tp(); ++__b; } - } + inline void + __valarray_destroy_elements(_Tp* __restrict__ __b, _Tp* __restrict__ __e) + { + if (!__is_pod<_Tp>::__value) + while (__b != __e) + { + __b->~_Tp(); + ++__b; + } + } // Fill a plain array __a[<__n>] with __t template<typename _Tp> - inline void - __valarray_fill (_Tp* __restrict__ __a, size_t __n, const _Tp& __t) - { while (__n--) *__a++ = __t; } - + inline void + __valarray_fill(_Tp* __restrict__ __a, size_t __n, const _Tp& __t) + { + while (__n--) + *__a++ = __t; + } + // fill strided array __a[<__n-1 : __s>] with __t template<typename _Tp> - inline void - __valarray_fill (_Tp* __restrict__ __a, size_t __n, - size_t __s, const _Tp& __t) - { for (size_t __i=0; __i<__n; ++__i, __a+=__s) *__a = __t; } + inline void + __valarray_fill(_Tp* __restrict__ __a, size_t __n, + size_t __s, const _Tp& __t) + { + for (size_t __i = 0; __i < __n; ++__i, __a += __s) + *__a = __t; + } // fill indir ect array __a[__i[<__n>]] with __i template<typename _Tp> - inline void - __valarray_fill(_Tp* __restrict__ __a, const size_t* __restrict__ __i, - size_t __n, const _Tp& __t) - { for (size_t __j=0; __j<__n; ++__j, ++__i) __a[*__i] = __t; } - + inline void + __valarray_fill(_Tp* __restrict__ __a, const size_t* __restrict__ __i, + size_t __n, const _Tp& __t) + { + for (size_t __j = 0; __j < __n; ++__j, ++__i) + __a[*__i] = __t; + } + // copy plain array __a[<__n>] in __b[<__n>] // For non-fundamental types, it is wrong to say 'memcpy()' template<typename _Tp, bool> - struct _Array_copier - { - inline static void - _S_do_it(const _Tp* __restrict__ __a, size_t __n, _Tp* __restrict__ __b) - { while (__n--) *__b++ = *__a++; } - }; - - template<typename _Tp> - struct _Array_copier<_Tp, true> - { - inline static void - _S_do_it(const _Tp* __restrict__ __a, size_t __n, _Tp* __restrict__ __b) - { std::memcpy (__b, __a, __n * sizeof (_Tp)); } - }; + struct _Array_copier + { + inline static void + _S_do_it(const _Tp* __restrict__ __a, size_t __n, _Tp* __restrict__ __b) + { + while(__n--) + *__b++ = *__a++; + } + }; + + template<typename _Tp> + struct _Array_copier<_Tp, true> + { + inline static void + _S_do_it(const _Tp* __restrict__ __a, size_t __n, _Tp* __restrict__ __b) + { std::memcpy (__b, __a, __n * sizeof (_Tp)); } + }; // Copy a plain array __a[<__n>] into a play array __b[<>] template<typename _Tp> - inline void - __valarray_copy(const _Tp* __restrict__ __a, size_t __n, - _Tp* __restrict__ __b) - { - _Array_copier<_Tp, __is_fundamental<_Tp>::_M_type>:: - _S_do_it(__a, __n, __b); - } + inline void + __valarray_copy(const _Tp* __restrict__ __a, size_t __n, + _Tp* __restrict__ __b) + { + _Array_copier<_Tp, __is_pod<_Tp>::__value>::_S_do_it(__a, __n, __b); + } // Copy strided array __a[<__n : __s>] in plain __b[<__n>] template<typename _Tp> - inline void - __valarray_copy(const _Tp* __restrict__ __a, size_t __n, size_t __s, - _Tp* __restrict__ __b) - { for (size_t __i=0; __i<__n; ++__i, ++__b, __a += __s) *__b = *__a; } + inline void + __valarray_copy(const _Tp* __restrict__ __a, size_t __n, size_t __s, + _Tp* __restrict__ __b) + { + for (size_t __i = 0; __i < __n; ++__i, ++__b, __a += __s) + *__b = *__a; + } // Copy a plain array __a[<__n>] into a strided array __b[<__n : __s>] template<typename _Tp> - inline void - __valarray_copy(const _Tp* __restrict__ __a, _Tp* __restrict__ __b, - size_t __n, size_t __s) - { for (size_t __i=0; __i<__n; ++__i, ++__a, __b+=__s) *__b = *__a; } + inline void + __valarray_copy(const _Tp* __restrict__ __a, _Tp* __restrict__ __b, + size_t __n, size_t __s) + { + for (size_t __i = 0; __i < __n; ++__i, ++__a, __b += __s) + *__b = *__a; + } // Copy strided array __src[<__n : __s1>] into another // strided array __dst[< : __s2>]. Their sizes must match. template<typename _Tp> - inline void - __valarray_copy(const _Tp* __restrict__ __src, size_t __n, size_t __s1, - _Tp* __restrict__ __dst, size_t __s2) - { - for (size_t __i = 0; __i < __n; ++__i) - __dst[__i * __s2] = __src [ __i * __s1]; - } - + inline void + __valarray_copy(const _Tp* __restrict__ __src, size_t __n, size_t __s1, + _Tp* __restrict__ __dst, size_t __s2) + { + for (size_t __i = 0; __i < __n; ++__i) + __dst[__i * __s2] = __src[__i * __s1]; + } // Copy an indexed array __a[__i[<__n>]] in plain array __b[<__n>] template<typename _Tp> - inline void - __valarray_copy (const _Tp* __restrict__ __a, - const size_t* __restrict__ __i, - _Tp* __restrict__ __b, size_t __n) - { for (size_t __j=0; __j<__n; ++__j, ++__b, ++__i) *__b = __a[*__i]; } + inline void + __valarray_copy(const _Tp* __restrict__ __a, + const size_t* __restrict__ __i, + _Tp* __restrict__ __b, size_t __n) + { + for (size_t __j = 0; __j < __n; ++__j, ++__b, ++__i) + *__b = __a[*__i]; + } // Copy a plain array __a[<__n>] in an indexed array __b[__i[<__n>]] template<typename _Tp> - inline void - __valarray_copy (const _Tp* __restrict__ __a, size_t __n, - _Tp* __restrict__ __b, const size_t* __restrict__ __i) - { for (size_t __j=0; __j<__n; ++__j, ++__a, ++__i) __b[*__i] = *__a; } + inline void + __valarray_copy(const _Tp* __restrict__ __a, size_t __n, + _Tp* __restrict__ __b, const size_t* __restrict__ __i) + { + for (size_t __j = 0; __j < __n; ++__j, ++__a, ++__i) + __b[*__i] = *__a; + } // Copy the __n first elements of an indexed array __src[<__i>] into // another indexed array __dst[<__j>]. template<typename _Tp> - inline void - __valarray_copy(const _Tp* __restrict__ __src, size_t __n, - const size_t* __restrict__ __i, - _Tp* __restrict__ __dst, const size_t* __restrict__ __j) - { - for (size_t __k = 0; __k < __n; ++__k) - __dst[*__j++] = __src[*__i++]; - } + inline void + __valarray_copy(const _Tp* __restrict__ __src, size_t __n, + const size_t* __restrict__ __i, + _Tp* __restrict__ __dst, const size_t* __restrict__ __j) + { + for (size_t __k = 0; __k < __n; ++__k) + __dst[*__j++] = __src[*__i++]; + } // // Compute the sum of elements in range [__f, __l) @@ -306,57 +351,59 @@ namespace std // algorithm. // template<typename _Tp> - inline _Tp - __valarray_sum(const _Tp* __restrict__ __f, const _Tp* __restrict__ __l) - { - _Tp __r = _Tp(); - while (__f != __l) __r += *__f++; - return __r; - } + inline _Tp + __valarray_sum(const _Tp* __restrict__ __f, const _Tp* __restrict__ __l) + { + _Tp __r = _Tp(); + while (__f != __l) + __r += *__f++; + return __r; + } // Compute the product of all elements in range [__f, __l) template<typename _Tp> - inline _Tp - __valarray_product(const _Tp* __restrict__ __f, - const _Tp* __restrict__ __l) - { - _Tp __r = _Tp(1); - while (__f != __l) __r = __r * *__f++; - return __r; - } + inline _Tp + __valarray_product(const _Tp* __restrict__ __f, + const _Tp* __restrict__ __l) + { + _Tp __r = _Tp(1); + while (__f != __l) + __r = __r * *__f++; + return __r; + } // Compute the min/max of an array-expression template<typename _Ta> - inline typename _Ta::value_type - __valarray_min(const _Ta& __a) - { - size_t __s = __a.size(); - typedef typename _Ta::value_type _Value_type; - _Value_type __r = __s == 0 ? _Value_type() : __a[0]; - for (size_t __i = 1; __i < __s; ++__i) - { - _Value_type __t = __a[__i]; - if (__t < __r) - __r = __t; - } - return __r; - } + inline typename _Ta::value_type + __valarray_min(const _Ta& __a) + { + size_t __s = __a.size(); + typedef typename _Ta::value_type _Value_type; + _Value_type __r = __s == 0 ? _Value_type() : __a[0]; + for (size_t __i = 1; __i < __s; ++__i) + { + _Value_type __t = __a[__i]; + if (__t < __r) + __r = __t; + } + return __r; + } template<typename _Ta> - inline typename _Ta::value_type - __valarray_max(const _Ta& __a) - { - size_t __s = __a.size(); - typedef typename _Ta::value_type _Value_type; - _Value_type __r = __s == 0 ? _Value_type() : __a[0]; - for (size_t __i = 1; __i < __s; ++__i) - { - _Value_type __t = __a[__i]; - if (__t > __r) - __r = __t; - } - return __r; - } + inline typename _Ta::value_type + __valarray_max(const _Ta& __a) + { + size_t __s = __a.size(); + typedef typename _Ta::value_type _Value_type; + _Value_type __r = __s == 0 ? _Value_type() : __a[0]; + for (size_t __i = 1; __i < __s; ++__i) + { + _Value_type __t = __a[__i]; + if (__t > __r) + __r = __t; + } + return __r; + } // // Helper class _Array, first layer of valarray abstraction. @@ -365,244 +412,275 @@ namespace std // template<typename _Tp> - struct _Array - { - explicit _Array (size_t); - explicit _Array (_Tp* const __restrict__); - explicit _Array (const valarray<_Tp>&); - _Array (const _Tp* __restrict__, size_t); + struct _Array + { + explicit _Array(size_t); + explicit _Array(_Tp* const __restrict__); + explicit _Array(const valarray<_Tp>&); + _Array(const _Tp* __restrict__, size_t); + + _Tp* begin() const; + + _Tp* const __restrict__ _M_data; + }; - _Tp* begin () const; - _Tp* const __restrict__ _M_data; - }; + // Copy-construct plain array __b[<__n>] from indexed array __a[__i[<__n>]] + template<typename _Tp> + inline void + __valarray_copy_construct(_Array<_Tp> __a, _Array<size_t> __i, + _Array<_Tp> __b, size_t __n) + { std::__valarray_copy_construct(__a._M_data, __i._M_data, + __b._M_data, __n); } + // Copy-construct plain array __b[<__n>] from strided array __a[<__n : __s>] template<typename _Tp> - inline void - __valarray_fill (_Array<_Tp> __a, size_t __n, const _Tp& __t) - { std::__valarray_fill (__a._M_data, __n, __t); } + inline void + __valarray_copy_construct(_Array<_Tp> __a, size_t __n, size_t __s, + _Array<_Tp> __b) + { std::__valarray_copy_construct(__a._M_data, __n, __s, __b._M_data); } template<typename _Tp> - inline void - __valarray_fill (_Array<_Tp> __a, size_t __n, size_t __s, const _Tp& __t) - { std::__valarray_fill (__a._M_data, __n, __s, __t); } + inline void + __valarray_fill (_Array<_Tp> __a, size_t __n, const _Tp& __t) + { std::__valarray_fill(__a._M_data, __n, __t); } template<typename _Tp> - inline void - __valarray_fill (_Array<_Tp> __a, _Array<size_t> __i, - size_t __n, const _Tp& __t) - { std::__valarray_fill (__a._M_data, __i._M_data, __n, __t); } + inline void + __valarray_fill(_Array<_Tp> __a, size_t __n, size_t __s, const _Tp& __t) + { std::__valarray_fill(__a._M_data, __n, __s, __t); } + + template<typename _Tp> + inline void + __valarray_fill(_Array<_Tp> __a, _Array<size_t> __i, + size_t __n, const _Tp& __t) + { std::__valarray_fill(__a._M_data, __i._M_data, __n, __t); } // Copy a plain array __a[<__n>] into a play array __b[<>] template<typename _Tp> - inline void - __valarray_copy(_Array<_Tp> __a, size_t __n, _Array<_Tp> __b) - { std::__valarray_copy(__a._M_data, __n, __b._M_data); } + inline void + __valarray_copy(_Array<_Tp> __a, size_t __n, _Array<_Tp> __b) + { std::__valarray_copy(__a._M_data, __n, __b._M_data); } // Copy strided array __a[<__n : __s>] in plain __b[<__n>] template<typename _Tp> - inline void - __valarray_copy(_Array<_Tp> __a, size_t __n, size_t __s, _Array<_Tp> __b) - { std::__valarray_copy(__a._M_data, __n, __s, __b._M_data); } + inline void + __valarray_copy(_Array<_Tp> __a, size_t __n, size_t __s, _Array<_Tp> __b) + { std::__valarray_copy(__a._M_data, __n, __s, __b._M_data); } // Copy a plain array __a[<__n>] into a strided array __b[<__n : __s>] template<typename _Tp> - inline void - __valarray_copy(_Array<_Tp> __a, _Array<_Tp> __b, size_t __n, size_t __s) - { __valarray_copy(__a._M_data, __b._M_data, __n, __s); } + inline void + __valarray_copy(_Array<_Tp> __a, _Array<_Tp> __b, size_t __n, size_t __s) + { __valarray_copy(__a._M_data, __b._M_data, __n, __s); } // Copy strided array __src[<__n : __s1>] into another // strided array __dst[< : __s2>]. Their sizes must match. template<typename _Tp> - inline void - __valarray_copy(_Array<_Tp> __a, size_t __n, size_t __s1, - _Array<_Tp> __b, size_t __s2) - { std::__valarray_copy(__a._M_data, __n, __s1, __b._M_data, __s2); } - + inline void + __valarray_copy(_Array<_Tp> __a, size_t __n, size_t __s1, + _Array<_Tp> __b, size_t __s2) + { std::__valarray_copy(__a._M_data, __n, __s1, __b._M_data, __s2); } // Copy an indexed array __a[__i[<__n>]] in plain array __b[<__n>] template<typename _Tp> - inline void - __valarray_copy(_Array<_Tp> __a, _Array<size_t> __i, - _Array<_Tp> __b, size_t __n) - { std::__valarray_copy(__a._M_data, __i._M_data, __b._M_data, __n); } + inline void + __valarray_copy(_Array<_Tp> __a, _Array<size_t> __i, + _Array<_Tp> __b, size_t __n) + { std::__valarray_copy(__a._M_data, __i._M_data, __b._M_data, __n); } // Copy a plain array __a[<__n>] in an indexed array __b[__i[<__n>]] template<typename _Tp> - inline void - __valarray_copy(_Array<_Tp> __a, size_t __n, _Array<_Tp> __b, - _Array<size_t> __i) - { std::__valarray_copy(__a._M_data, __n, __b._M_data, __i._M_data); } + inline void + __valarray_copy(_Array<_Tp> __a, size_t __n, _Array<_Tp> __b, + _Array<size_t> __i) + { std::__valarray_copy(__a._M_data, __n, __b._M_data, __i._M_data); } // Copy the __n first elements of an indexed array __src[<__i>] into // another indexed array __dst[<__j>]. template<typename _Tp> - inline void - __valarray_copy(_Array<_Tp> __src, size_t __n, _Array<size_t> __i, - _Array<_Tp> __dst, _Array<size_t> __j) - { - std::__valarray_copy(__src._M_data, __n, __i._M_data, - __dst._M_data, __j._M_data); - } + inline void + __valarray_copy(_Array<_Tp> __src, size_t __n, _Array<size_t> __i, + _Array<_Tp> __dst, _Array<size_t> __j) + { + std::__valarray_copy(__src._M_data, __n, __i._M_data, + __dst._M_data, __j._M_data); + } template<typename _Tp> - inline - _Array<_Tp>::_Array (size_t __n) - : _M_data(__valarray_get_storage<_Tp>(__n)) - { std::__valarray_default_construct(_M_data, _M_data + __n); } + inline + _Array<_Tp>::_Array(size_t __n) + : _M_data(__valarray_get_storage<_Tp>(__n)) + { std::__valarray_default_construct(_M_data, _M_data + __n); } template<typename _Tp> - inline - _Array<_Tp>::_Array (_Tp* const __restrict__ __p) : _M_data (__p) {} + inline + _Array<_Tp>::_Array(_Tp* const __restrict__ __p) + : _M_data (__p) {} template<typename _Tp> - inline _Array<_Tp>::_Array (const valarray<_Tp>& __v) - : _M_data (__v._M_data) {} + inline + _Array<_Tp>::_Array(const valarray<_Tp>& __v) + : _M_data (__v._M_data) {} template<typename _Tp> - inline - _Array<_Tp>::_Array (const _Tp* __restrict__ __b, size_t __s) - : _M_data(__valarray_get_storage<_Tp>(__s)) - { std::__valarray_copy_construct(__b, __s, _M_data); } + inline + _Array<_Tp>::_Array(const _Tp* __restrict__ __b, size_t __s) + : _M_data(__valarray_get_storage<_Tp>(__s)) + { std::__valarray_copy_construct(__b, __s, _M_data); } template<typename _Tp> - inline _Tp* - _Array<_Tp>::begin () const - { return _M_data; } + inline _Tp* + _Array<_Tp>::begin () const + { return _M_data; } #define _DEFINE_ARRAY_FUNCTION(_Op, _Name) \ -template<typename _Tp> \ -inline void \ -_Array_augmented_##_Name (_Array<_Tp> __a, size_t __n, const _Tp& __t) \ -{ \ - for (_Tp* __p=__a._M_data; __p<__a._M_data+__n; ++__p) \ - *__p _Op##= __t; \ -} \ + template<typename _Tp> \ + inline void \ + _Array_augmented_##_Name(_Array<_Tp> __a, size_t __n, const _Tp& __t) \ + { \ + for (_Tp* __p = __a._M_data; __p < __a._M_data + __n; ++__p) \ + *__p _Op##= __t; \ + } \ \ -template<typename _Tp> \ -inline void \ -_Array_augmented_##_Name (_Array<_Tp> __a, size_t __n, _Array<_Tp> __b) \ -{ \ - _Tp* __p = __a._M_data; \ - for (_Tp* __q=__b._M_data; __q<__b._M_data+__n; ++__p, ++__q) \ - *__p _Op##= *__q; \ -} \ + template<typename _Tp> \ + inline void \ + _Array_augmented_##_Name(_Array<_Tp> __a, size_t __n, _Array<_Tp> __b) \ + { \ + _Tp* __p = __a._M_data; \ + for (_Tp* __q = __b._M_data; __q < __b._M_data + __n; ++__p, ++__q) \ + *__p _Op##= *__q; \ + } \ \ -template<typename _Tp, class _Dom> \ -void \ -_Array_augmented_##_Name (_Array<_Tp> __a, \ - const _Expr<_Dom,_Tp>& __e, size_t __n) \ -{ \ - _Tp* __p (__a._M_data); \ - for (size_t __i=0; __i<__n; ++__i, ++__p) *__p _Op##= __e[__i]; \ -} \ + template<typename _Tp, class _Dom> \ + void \ + _Array_augmented_##_Name(_Array<_Tp> __a, \ + const _Expr<_Dom, _Tp>& __e, size_t __n) \ + { \ + _Tp* __p(__a._M_data); \ + for (size_t __i = 0; __i < __n; ++__i, ++__p) \ + *__p _Op##= __e[__i]; \ + } \ \ -template<typename _Tp> \ -inline void \ -_Array_augmented_##_Name (_Array<_Tp> __a, size_t __n, size_t __s, \ - _Array<_Tp> __b) \ -{ \ - _Tp* __q (__b._M_data); \ - for (_Tp* __p=__a._M_data; __p<__a._M_data+__s*__n; __p+=__s, ++__q) \ - *__p _Op##= *__q; \ -} \ + template<typename _Tp> \ + inline void \ + _Array_augmented_##_Name(_Array<_Tp> __a, size_t __n, size_t __s, \ + _Array<_Tp> __b) \ + { \ + _Tp* __q(__b._M_data); \ + for (_Tp* __p = __a._M_data; __p < __a._M_data + __s * __n; \ + __p += __s, ++__q) \ + *__p _Op##= *__q; \ + } \ \ -template<typename _Tp> \ -inline void \ -_Array_augmented_##_Name (_Array<_Tp> __a, _Array<_Tp> __b, \ - size_t __n, size_t __s) \ -{ \ - _Tp* __q (__b._M_data); \ - for (_Tp* __p=__a._M_data; __p<__a._M_data+__n; ++__p, __q+=__s) \ - *__p _Op##= *__q; \ -} \ + template<typename _Tp> \ + inline void \ + _Array_augmented_##_Name(_Array<_Tp> __a, _Array<_Tp> __b, \ + size_t __n, size_t __s) \ + { \ + _Tp* __q(__b._M_data); \ + for (_Tp* __p = __a._M_data; __p < __a._M_data + __n; \ + ++__p, __q += __s) \ + *__p _Op##= *__q; \ + } \ \ -template<typename _Tp, class _Dom> \ -void \ -_Array_augmented_##_Name (_Array<_Tp> __a, size_t __s, \ - const _Expr<_Dom,_Tp>& __e, size_t __n) \ -{ \ - _Tp* __p (__a._M_data); \ - for (size_t __i=0; __i<__n; ++__i, __p+=__s) *__p _Op##= __e[__i]; \ -} \ + template<typename _Tp, class _Dom> \ + void \ + _Array_augmented_##_Name(_Array<_Tp> __a, size_t __s, \ + const _Expr<_Dom, _Tp>& __e, size_t __n) \ + { \ + _Tp* __p(__a._M_data); \ + for (size_t __i = 0; __i < __n; ++__i, __p += __s) \ + *__p _Op##= __e[__i]; \ + } \ \ -template<typename _Tp> \ -inline void \ -_Array_augmented_##_Name (_Array<_Tp> __a, _Array<size_t> __i, \ - _Array<_Tp> __b, size_t __n) \ -{ \ - _Tp* __q (__b._M_data); \ - for (size_t* __j=__i._M_data; __j<__i._M_data+__n; ++__j, ++__q) \ + template<typename _Tp> \ + inline void \ + _Array_augmented_##_Name(_Array<_Tp> __a, _Array<size_t> __i, \ + _Array<_Tp> __b, size_t __n) \ + { \ + _Tp* __q(__b._M_data); \ + for (size_t* __j = __i._M_data; __j < __i._M_data + __n; \ + ++__j, ++__q) \ __a._M_data[*__j] _Op##= *__q; \ -} \ + } \ \ -template<typename _Tp> \ -inline void \ -_Array_augmented_##_Name (_Array<_Tp> __a, size_t __n, \ - _Array<_Tp> __b, _Array<size_t> __i) \ -{ \ - _Tp* __p (__a._M_data); \ - for (size_t* __j=__i._M_data; __j<__i._M_data+__n; ++__j, ++__p) \ + template<typename _Tp> \ + inline void \ + _Array_augmented_##_Name(_Array<_Tp> __a, size_t __n, \ + _Array<_Tp> __b, _Array<size_t> __i) \ + { \ + _Tp* __p(__a._M_data); \ + for (size_t* __j = __i._M_data; __j<__i._M_data + __n; \ + ++__j, ++__p) \ *__p _Op##= __b._M_data[*__j]; \ -} \ + } \ \ -template<typename _Tp, class _Dom> \ -void \ -_Array_augmented_##_Name (_Array<_Tp> __a, _Array<size_t> __i, \ - const _Expr<_Dom, _Tp>& __e, size_t __n) \ -{ \ - size_t* __j (__i._M_data); \ - for (size_t __k=0; __k<__n; ++__k, ++__j) \ - __a._M_data[*__j] _Op##= __e[__k]; \ -} \ + template<typename _Tp, class _Dom> \ + void \ + _Array_augmented_##_Name(_Array<_Tp> __a, _Array<size_t> __i, \ + const _Expr<_Dom, _Tp>& __e, size_t __n) \ + { \ + size_t* __j(__i._M_data); \ + for (size_t __k = 0; __k<__n; ++__k, ++__j) \ + __a._M_data[*__j] _Op##= __e[__k]; \ + } \ \ -template<typename _Tp> \ -void \ -_Array_augmented_##_Name (_Array<_Tp> __a, _Array<bool> __m, \ - _Array<_Tp> __b, size_t __n) \ -{ \ - bool* ok (__m._M_data); \ - _Tp* __p (__a._M_data); \ - for (_Tp* __q=__b._M_data; __q<__b._M_data+__n; ++__q, ++ok, ++__p) { \ - while (! *ok) { \ - ++ok; \ - ++__p; \ + template<typename _Tp> \ + void \ + _Array_augmented_##_Name(_Array<_Tp> __a, _Array<bool> __m, \ + _Array<_Tp> __b, size_t __n) \ + { \ + bool* __ok(__m._M_data); \ + _Tp* __p(__a._M_data); \ + for (_Tp* __q = __b._M_data; __q < __b._M_data + __n; \ + ++__q, ++__ok, ++__p) \ + { \ + while (! *__ok) \ + { \ + ++__ok; \ + ++__p; \ + } \ + *__p _Op##= *__q; \ } \ - *__p _Op##= *__q; \ } \ -} \ \ -template<typename _Tp> \ -void \ -_Array_augmented_##_Name (_Array<_Tp> __a, size_t __n, \ - _Array<_Tp> __b, _Array<bool> __m) \ -{ \ - bool* ok (__m._M_data); \ - _Tp* __q (__b._M_data); \ - for (_Tp* __p=__a._M_data; __p<__a._M_data+__n; ++__p, ++ok, ++__q) { \ - while (! *ok) { \ - ++ok; \ - ++__q; \ + template<typename _Tp> \ + void \ + _Array_augmented_##_Name(_Array<_Tp> __a, size_t __n, \ + _Array<_Tp> __b, _Array<bool> __m) \ + { \ + bool* __ok(__m._M_data); \ + _Tp* __q(__b._M_data); \ + for (_Tp* __p = __a._M_data; __p < __a._M_data + __n; \ + ++__p, ++__ok, ++__q) \ + { \ + while (! *__ok) \ + { \ + ++__ok; \ + ++__q; \ + } \ + *__p _Op##= *__q; \ } \ - *__p _Op##= *__q; \ } \ -} \ \ -template<typename _Tp, class _Dom> \ -void \ -_Array_augmented_##_Name (_Array<_Tp> __a, _Array<bool> __m, \ - const _Expr<_Dom, _Tp>& __e, size_t __n) \ -{ \ - bool* ok(__m._M_data); \ - _Tp* __p (__a._M_data); \ - for (size_t __i=0; __i<__n; ++__i, ++ok, ++__p) { \ - while (! *ok) { \ - ++ok; \ - ++__p; \ + template<typename _Tp, class _Dom> \ + void \ + _Array_augmented_##_Name(_Array<_Tp> __a, _Array<bool> __m, \ + const _Expr<_Dom, _Tp>& __e, size_t __n) \ + { \ + bool* __ok(__m._M_data); \ + _Tp* __p(__a._M_data); \ + for (size_t __i = 0; __i < __n; ++__i, ++__ok, ++__p) \ + { \ + while (! *__ok) \ + { \ + ++__ok; \ + ++__p; \ + } \ + *__p _Op##= __e[__i]; \ } \ - *__p _Op##= __e[__i]; \ - } \ -} + } _DEFINE_ARRAY_FUNCTION(+, __plus) _DEFINE_ARRAY_FUNCTION(-, __minus) @@ -615,8 +693,9 @@ _Array_augmented_##_Name (_Array<_Tp> __a, _Array<bool> __m, \ _DEFINE_ARRAY_FUNCTION(<<, __shift_left) _DEFINE_ARRAY_FUNCTION(>>, __shift_right) -#undef _DEFINE_VALARRAY_FUNCTION -} // namespace std +#undef _DEFINE_ARRAY_FUNCTION + +_GLIBCXX_END_NAMESPACE #ifndef _GLIBCXX_EXPORT_TEMPLATE # include <bits/valarray_array.tcc> diff --git a/contrib/libstdc++/include/bits/valarray_array.tcc b/contrib/libstdc++/include/bits/valarray_array.tcc index fac5de6..f00ffb4 100644 --- a/contrib/libstdc++/include/bits/valarray_array.tcc +++ b/contrib/libstdc++/include/bits/valarray_array.tcc @@ -1,6 +1,6 @@ // The template and inlines for the -*- C++ -*- internal _Array helper class. -// Copyright (C) 1997, 1998, 1999, 2003 Free Software Foundation, Inc. +// Copyright (C) 1997, 1998, 1999, 2003, 2005 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 @@ -15,7 +15,7 @@ // 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// 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 @@ -27,13 +27,18 @@ // invalidate any other reasons why the executable file might be covered by // the GNU General Public License. +/** @file valarray_array.tcc + * This is an internal header file, included by other library headers. + * You should not attempt to use it directly. + */ + // Written by Gabriel Dos Reis <Gabriel.Dos-Reis@DPTMaths.ENS-Cachan.Fr> #ifndef _VALARRAY_ARRAY_TCC #define _VALARRAY_ARRAY_TCC 1 -namespace std -{ +_GLIBCXX_BEGIN_NAMESPACE(std) + template<typename _Tp> void __valarray_fill(_Array<_Tp> __a, size_t __n, _Array<bool> __m, @@ -235,6 +240,7 @@ namespace std new (__q) _Tp(*__p); } } -} // namespace std + +_GLIBCXX_END_NAMESPACE #endif /* _VALARRAY_ARRAY_TCC */ diff --git a/contrib/libstdc++/include/bits/valarray_before.h b/contrib/libstdc++/include/bits/valarray_before.h index 263ac2f..4e3b937 100644 --- a/contrib/libstdc++/include/bits/valarray_before.h +++ b/contrib/libstdc++/include/bits/valarray_before.h @@ -1,6 +1,7 @@ // The template and inlines for the -*- C++ -*- internal _Meta class. -// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc. +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 +// 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 @@ -15,7 +16,7 @@ // 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// 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 @@ -27,13 +28,13 @@ // invalidate any other reasons why the executable file might be covered by // the GNU General Public License. -// Written by Gabriel Dos Reis <Gabriel.Dos-Reis@cmla.ens-cachan.fr> - -/** @file valarray_meta.h +/** @file valarray_before.h * This is an internal header file, included by other library headers. * You should not attempt to use it directly. */ +// Written by Gabriel Dos Reis <Gabriel.Dos-Reis@cmla.ens-cachan.fr> + #ifndef _VALARRAY_BEFORE_H #define _VALARRAY_BEFORE_H 1 @@ -41,8 +42,8 @@ #include <bits/slice_array.h> -namespace std -{ +_GLIBCXX_BEGIN_NAMESPACE(std) + // // Implementing a loosened valarray return value is tricky. // First we need to meet 26.3.1/3: we should not add more than @@ -66,85 +67,99 @@ namespace std struct __abs { template<typename _Tp> - _Tp operator()(const _Tp& __t) const { return abs(__t); } + _Tp operator()(const _Tp& __t) const + { return abs(__t); } }; struct __cos { template<typename _Tp> - _Tp operator()(const _Tp& __t) const { return cos(__t); } + _Tp operator()(const _Tp& __t) const + { return cos(__t); } }; struct __acos { template<typename _Tp> - _Tp operator()(const _Tp& __t) const { return acos(__t); } + _Tp operator()(const _Tp& __t) const + { return acos(__t); } }; struct __cosh { template<typename _Tp> - _Tp operator()(const _Tp& __t) const { return cosh(__t); } + _Tp operator()(const _Tp& __t) const + { return cosh(__t); } }; struct __sin { template<typename _Tp> - _Tp operator()(const _Tp& __t) const { return sin(__t); } + _Tp operator()(const _Tp& __t) const + { return sin(__t); } }; struct __asin { template<typename _Tp> - _Tp operator()(const _Tp& __t) const { return asin(__t); } + _Tp operator()(const _Tp& __t) const + { return asin(__t); } }; struct __sinh { template<typename _Tp> - _Tp operator()(const _Tp& __t) const { return sinh(__t); } + _Tp operator()(const _Tp& __t) const + { return sinh(__t); } }; struct __tan { template<typename _Tp> - _Tp operator()(const _Tp& __t) const { return tan(__t); } + _Tp operator()(const _Tp& __t) const + { return tan(__t); } }; struct __atan { template<typename _Tp> - _Tp operator()(const _Tp& __t) const { return atan(__t); } + _Tp operator()(const _Tp& __t) const + { return atan(__t); } }; struct __tanh { template<typename _Tp> - _Tp operator()(const _Tp& __t) const { return tanh(__t); } + _Tp operator()(const _Tp& __t) const + { return tanh(__t); } }; struct __exp { template<typename _Tp> - _Tp operator()(const _Tp& __t) const { return exp(__t); } + _Tp operator()(const _Tp& __t) const + { return exp(__t); } }; struct __log { template<typename _Tp> - _Tp operator()(const _Tp& __t) const { return log(__t); } + _Tp operator()(const _Tp& __t) const + { return log(__t); } }; struct __log10 { template<typename _Tp> - _Tp operator()(const _Tp& __t) const { return log10(__t); } + _Tp operator()(const _Tp& __t) const + { return log10(__t); } }; struct __sqrt { template<typename _Tp> - _Tp operator()(const _Tp& __t) const { return sqrt(__t); } + _Tp operator()(const _Tp& __t) const + { return sqrt(__t); } }; // In the past, we used to tailor operator applications semantics @@ -154,19 +169,22 @@ namespace std struct __unary_plus { template<typename _Tp> - _Tp operator()(const _Tp& __t) const { return +__t; } + _Tp operator()(const _Tp& __t) const + { return +__t; } }; struct __negate { template<typename _Tp> - _Tp operator()(const _Tp& __t) const { return -__t; } + _Tp operator()(const _Tp& __t) const + { return -__t; } }; struct __bitwise_not { template<typename _Tp> - _Tp operator()(const _Tp& __t) const { return ~__t; } + _Tp operator()(const _Tp& __t) const + { return ~__t; } }; struct __plus @@ -381,9 +399,9 @@ namespace std typedef bool result_type; }; - // - // Apply function taking a value/const reference closure - // + // + // Apply function taking a value/const reference closure + // template<typename _Dom, typename _Arg> class _FunBase @@ -392,7 +410,7 @@ namespace std typedef typename _Dom::value_type value_type; _FunBase(const _Dom& __e, value_type __f(_Arg)) - : _M_expr(__e), _M_func(__f) {} + : _M_expr(__e), _M_func(__f) {} value_type operator[](size_t __i) const { return _M_func (_M_expr[__i]); } @@ -400,8 +418,8 @@ namespace std size_t size() const { return _M_expr.size ();} private: - const _Dom& _M_expr; - value_type (*_M_func)(_Arg); + const _Dom& _M_expr; + value_type (*_M_func)(_Arg); }; template<class _Dom> @@ -424,25 +442,26 @@ namespace std }; template<class _Dom> - struct _RefFunClos<_Expr,_Dom> : - _FunBase<_Dom, const typename _Dom::value_type&> + struct _RefFunClos<_Expr, _Dom> + : _FunBase<_Dom, const typename _Dom::value_type&> { typedef _FunBase<_Dom, const typename _Dom::value_type&> _Base; typedef typename _Base::value_type value_type; typedef value_type _Tp; _RefFunClos(const _Dom& __e, _Tp __f(const _Tp&)) - : _Base(__e, __f) {} + : _Base(__e, __f) {} }; template<typename _Tp> - struct _RefFunClos<_ValArray,_Tp> : _FunBase<valarray<_Tp>, const _Tp&> + struct _RefFunClos<_ValArray, _Tp> + : _FunBase<valarray<_Tp>, const _Tp&> { typedef _FunBase<valarray<_Tp>, const _Tp&> _Base; typedef _Tp value_type; _RefFunClos(const valarray<_Tp>& __v, _Tp __f(const _Tp&)) - : _Base(__v, __f) {} + : _Base(__v, __f) {} }; // @@ -462,13 +481,14 @@ namespace std { return _Oper()(_M_expr[__i]); } size_t size() const { return _M_expr.size(); } - + private: const _Arg& _M_expr; }; template<class _Oper, class _Dom> - struct _UnClos<_Oper, _Expr, _Dom> : _UnBase<_Oper, _Dom> + struct _UnClos<_Oper, _Expr, _Dom> + : _UnBase<_Oper, _Dom> { typedef _Dom _Arg; typedef _UnBase<_Oper, _Dom> _Base; @@ -478,7 +498,8 @@ namespace std }; template<class _Oper, typename _Tp> - struct _UnClos<_Oper, _ValArray, _Tp> : _UnBase<_Oper, valarray<_Tp> > + struct _UnClos<_Oper, _ValArray, _Tp> + : _UnBase<_Oper, valarray<_Tp> > { typedef valarray<_Tp> _Arg; typedef _UnBase<_Oper, valarray<_Tp> > _Base; @@ -496,11 +517,11 @@ namespace std class _BinBase { public: - typedef typename _FirstArg::value_type _Vt; - typedef typename __fun<_Oper, _Vt>::result_type value_type; + typedef typename _FirstArg::value_type _Vt; + typedef typename __fun<_Oper, _Vt>::result_type value_type; _BinBase(const _FirstArg& __e1, const _SecondArg& __e2) - : _M_expr1(__e1), _M_expr2(__e2) {} + : _M_expr1(__e1), _M_expr2(__e2) {} value_type operator[](size_t __i) const { return _Oper()(_M_expr1[__i], _M_expr2[__i]); } @@ -521,7 +542,7 @@ namespace std typedef typename __fun<_Oper, _Vt>::result_type value_type; _BinBase2(const _Clos& __e, const _Vt& __t) - : _M_expr1(__e), _M_expr2(__t) {} + : _M_expr1(__e), _M_expr2(__t) {} value_type operator[](size_t __i) const { return _Oper()(_M_expr1[__i], _M_expr2); } @@ -541,7 +562,7 @@ namespace std typedef typename __fun<_Oper, _Vt>::result_type value_type; _BinBase1(const _Vt& __t, const _Clos& __e) - : _M_expr1(__t), _M_expr2(__e) {} + : _M_expr1(__t), _M_expr2(__e) {} value_type operator[](size_t __i) const { return _Oper()(_M_expr1, _M_expr2[__i]); } @@ -555,52 +576,52 @@ namespace std template<class _Oper, class _Dom1, class _Dom2> struct _BinClos<_Oper, _Expr, _Expr, _Dom1, _Dom2> - : _BinBase<_Oper,_Dom1,_Dom2> + : _BinBase<_Oper, _Dom1, _Dom2> { - typedef _BinBase<_Oper,_Dom1,_Dom2> _Base; + typedef _BinBase<_Oper, _Dom1, _Dom2> _Base; typedef typename _Base::value_type value_type; _BinClos(const _Dom1& __e1, const _Dom2& __e2) : _Base(__e1, __e2) {} }; template<class _Oper, typename _Tp> - struct _BinClos<_Oper,_ValArray,_ValArray,_Tp,_Tp> - : _BinBase<_Oper,valarray<_Tp>,valarray<_Tp> > + struct _BinClos<_Oper,_ValArray, _ValArray, _Tp, _Tp> + : _BinBase<_Oper, valarray<_Tp>, valarray<_Tp> > { - typedef _BinBase<_Oper,valarray<_Tp>,valarray<_Tp> > _Base; - typedef _Tp value_type; + typedef _BinBase<_Oper, valarray<_Tp>, valarray<_Tp> > _Base; + typedef typename _Base::value_type value_type; _BinClos(const valarray<_Tp>& __v, const valarray<_Tp>& __w) - : _Base(__v, __w) {} + : _Base(__v, __w) {} }; template<class _Oper, class _Dom> - struct _BinClos<_Oper,_Expr,_ValArray,_Dom,typename _Dom::value_type> - : _BinBase<_Oper,_Dom,valarray<typename _Dom::value_type> > + struct _BinClos<_Oper, _Expr, _ValArray, _Dom, typename _Dom::value_type> + : _BinBase<_Oper, _Dom, valarray<typename _Dom::value_type> > { typedef typename _Dom::value_type _Tp; typedef _BinBase<_Oper,_Dom,valarray<_Tp> > _Base; typedef typename _Base::value_type value_type; _BinClos(const _Dom& __e1, const valarray<_Tp>& __e2) - : _Base(__e1, __e2) {} + : _Base(__e1, __e2) {} }; template<class _Oper, class _Dom> - struct _BinClos<_Oper,_ValArray,_Expr,typename _Dom::value_type,_Dom> - : _BinBase<_Oper,valarray<typename _Dom::value_type>,_Dom> + struct _BinClos<_Oper, _ValArray, _Expr, typename _Dom::value_type, _Dom> + : _BinBase<_Oper, valarray<typename _Dom::value_type>,_Dom> { typedef typename _Dom::value_type _Tp; - typedef _BinBase<_Oper,valarray<_Tp>,_Dom> _Base; + typedef _BinBase<_Oper, valarray<_Tp>, _Dom> _Base; typedef typename _Base::value_type value_type; _BinClos(const valarray<_Tp>& __e1, const _Dom& __e2) - : _Base(__e1, __e2) {} + : _Base(__e1, __e2) {} }; template<class _Oper, class _Dom> - struct _BinClos<_Oper,_Expr,_Constant,_Dom,typename _Dom::value_type> - : _BinBase2<_Oper,_Dom> + struct _BinClos<_Oper, _Expr, _Constant, _Dom, typename _Dom::value_type> + : _BinBase2<_Oper, _Dom> { typedef typename _Dom::value_type _Tp; typedef _BinBase2<_Oper,_Dom> _Base; @@ -610,19 +631,19 @@ namespace std }; template<class _Oper, class _Dom> - struct _BinClos<_Oper,_Constant,_Expr,typename _Dom::value_type,_Dom> - : _BinBase1<_Oper,_Dom> + struct _BinClos<_Oper, _Constant, _Expr, typename _Dom::value_type, _Dom> + : _BinBase1<_Oper, _Dom> { typedef typename _Dom::value_type _Tp; - typedef _BinBase1<_Oper,_Dom> _Base; + typedef _BinBase1<_Oper, _Dom> _Base; typedef typename _Base::value_type value_type; _BinClos(const _Tp& __e1, const _Dom& __e2) : _Base(__e1, __e2) {} }; template<class _Oper, typename _Tp> - struct _BinClos<_Oper,_ValArray,_Constant,_Tp,_Tp> - : _BinBase2<_Oper,valarray<_Tp> > + struct _BinClos<_Oper, _ValArray, _Constant, _Tp, _Tp> + : _BinBase2<_Oper, valarray<_Tp> > { typedef _BinBase2<_Oper,valarray<_Tp> > _Base; typedef typename _Base::value_type value_type; @@ -631,71 +652,84 @@ namespace std }; template<class _Oper, typename _Tp> - struct _BinClos<_Oper,_Constant,_ValArray,_Tp,_Tp> - : _BinBase1<_Oper,valarray<_Tp> > + struct _BinClos<_Oper, _Constant, _ValArray, _Tp, _Tp> + : _BinBase1<_Oper, valarray<_Tp> > { - typedef _BinBase1<_Oper,valarray<_Tp> > _Base; + typedef _BinBase1<_Oper, valarray<_Tp> > _Base; typedef typename _Base::value_type value_type; _BinClos(const _Tp& __t, const valarray<_Tp>& __v) : _Base(__t, __v) {} }; - // // slice_array closure. // - template<typename _Dom> class _SBase { + template<typename _Dom> + class _SBase + { public: - typedef typename _Dom::value_type value_type; - - _SBase (const _Dom& __e, const slice& __s) - : _M_expr (__e), _M_slice (__s) {} - value_type operator[] (size_t __i) const - { return _M_expr[_M_slice.start () + __i * _M_slice.stride ()]; } - size_t size() const { return _M_slice.size (); } + typedef typename _Dom::value_type value_type; + + _SBase (const _Dom& __e, const slice& __s) + : _M_expr (__e), _M_slice (__s) {} + + value_type + operator[] (size_t __i) const + { return _M_expr[_M_slice.start () + __i * _M_slice.stride ()]; } + + size_t + size() const + { return _M_slice.size (); } private: - const _Dom& _M_expr; - const slice& _M_slice; + const _Dom& _M_expr; + const slice& _M_slice; }; - template<typename _Tp> class _SBase<_Array<_Tp> > { + template<typename _Tp> + class _SBase<_Array<_Tp> > + { public: - typedef _Tp value_type; - - _SBase (_Array<_Tp> __a, const slice& __s) - : _M_array (__a._M_data+__s.start()), _M_size (__s.size()), - _M_stride (__s.stride()) {} - value_type operator[] (size_t __i) const - { return _M_array._M_data[__i * _M_stride]; } - size_t size() const { return _M_size; } + typedef _Tp value_type; + + _SBase (_Array<_Tp> __a, const slice& __s) + : _M_array (__a._M_data+__s.start()), _M_size (__s.size()), + _M_stride (__s.stride()) {} + + value_type + operator[] (size_t __i) const + { return _M_array._M_data[__i * _M_stride]; } + + size_t + size() const + { return _M_size; } private: - const _Array<_Tp> _M_array; - const size_t _M_size; - const size_t _M_stride; + const _Array<_Tp> _M_array; + const size_t _M_size; + const size_t _M_stride; }; - template<class _Dom> struct _SClos<_Expr,_Dom> : _SBase<_Dom> { - typedef _SBase<_Dom> _Base; - typedef typename _Base::value_type value_type; - - _SClos (const _Dom& __e, const slice& __s) : _Base (__e, __s) {} + template<class _Dom> + struct _SClos<_Expr, _Dom> + : _SBase<_Dom> + { + typedef _SBase<_Dom> _Base; + typedef typename _Base::value_type value_type; + + _SClos (const _Dom& __e, const slice& __s) : _Base (__e, __s) {} }; - template<typename _Tp> - struct _SClos<_ValArray,_Tp> : _SBase<_Array<_Tp> > { - typedef _SBase<_Array<_Tp> > _Base; - typedef _Tp value_type; - - _SClos (_Array<_Tp> __a, const slice& __s) : _Base (__a, __s) {} + template<typename _Tp> + struct _SClos<_ValArray, _Tp> + : _SBase<_Array<_Tp> > + { + typedef _SBase<_Array<_Tp> > _Base; + typedef _Tp value_type; + + _SClos (_Array<_Tp> __a, const slice& __s) : _Base (__a, __s) {} }; -} // std:: - +_GLIBCXX_END_NAMESPACE #endif /* _CPP_VALARRAY_BEFORE_H */ - -// Local Variables: -// mode:c++ -// End: diff --git a/contrib/libstdc++/include/bits/vector.tcc b/contrib/libstdc++/include/bits/vector.tcc index 786afab..f476c46 100644 --- a/contrib/libstdc++/include/bits/vector.tcc +++ b/contrib/libstdc++/include/bits/vector.tcc @@ -1,6 +1,6 @@ // Vector implementation (out of line) -*- C++ -*- -// Copyright (C) 2001, 2002, 2003, 2004 Free Software Foundation, Inc. +// Copyright (C) 2001, 2002, 2003, 2004, 2005 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 @@ -15,7 +15,7 @@ // 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// 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 @@ -61,11 +61,11 @@ #ifndef _VECTOR_TCC #define _VECTOR_TCC 1 -namespace _GLIBCXX_STD -{ +_GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD) + template<typename _Tp, typename _Alloc> void - vector<_Tp,_Alloc>:: + vector<_Tp, _Alloc>:: reserve(size_type __n) { if (__n > this->max_size()) @@ -73,12 +73,13 @@ namespace _GLIBCXX_STD if (this->capacity() < __n) { const size_type __old_size = size(); - pointer __tmp = _M_allocate_and_copy(__n, - this->_M_impl._M_start, + pointer __tmp = _M_allocate_and_copy(__n, this->_M_impl._M_start, this->_M_impl._M_finish); - std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish); + std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish, + _M_get_Tp_allocator()); _M_deallocate(this->_M_impl._M_start, - this->_M_impl._M_end_of_storage - this->_M_impl._M_start); + this->_M_impl._M_end_of_storage + - this->_M_impl._M_start); this->_M_impl._M_start = __tmp; this->_M_impl._M_finish = __tmp + __old_size; this->_M_impl._M_end_of_storage = this->_M_impl._M_start + __n; @@ -86,329 +87,410 @@ namespace _GLIBCXX_STD } template<typename _Tp, typename _Alloc> - typename vector<_Tp,_Alloc>::iterator - vector<_Tp,_Alloc>:: + typename vector<_Tp, _Alloc>::iterator + vector<_Tp, _Alloc>:: insert(iterator __position, const value_type& __x) { - size_type __n = __position - begin(); - if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage && __position == end()) - { - std::_Construct(this->_M_impl._M_finish, __x); - ++this->_M_impl._M_finish; - } + const size_type __n = __position - begin(); + if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage + && __position == end()) + { + this->_M_impl.construct(this->_M_impl._M_finish, __x); + ++this->_M_impl._M_finish; + } else _M_insert_aux(__position, __x); - return begin() + __n; + return iterator(this->_M_impl._M_start + __n); } template<typename _Tp, typename _Alloc> - typename vector<_Tp,_Alloc>::iterator - vector<_Tp,_Alloc>:: + typename vector<_Tp, _Alloc>::iterator + vector<_Tp, _Alloc>:: erase(iterator __position) { if (__position + 1 != end()) std::copy(__position + 1, end(), __position); --this->_M_impl._M_finish; - std::_Destroy(this->_M_impl._M_finish); + this->_M_impl.destroy(this->_M_impl._M_finish); return __position; } template<typename _Tp, typename _Alloc> - typename vector<_Tp,_Alloc>::iterator - vector<_Tp,_Alloc>:: + typename vector<_Tp, _Alloc>::iterator + vector<_Tp, _Alloc>:: erase(iterator __first, iterator __last) { - iterator __i(std::copy(__last, end(), __first)); - std::_Destroy(__i, end()); - this->_M_impl._M_finish = this->_M_impl._M_finish - (__last - __first); + if (__last != end()) + std::copy(__last, end(), __first); + _M_erase_at_end(__first.base() + (end() - __last)); return __first; } template<typename _Tp, typename _Alloc> - vector<_Tp,_Alloc>& - vector<_Tp,_Alloc>:: - operator=(const vector<_Tp,_Alloc>& __x) + vector<_Tp, _Alloc>& + vector<_Tp, _Alloc>:: + operator=(const vector<_Tp, _Alloc>& __x) { if (&__x != this) - { - const size_type __xlen = __x.size(); - if (__xlen > capacity()) - { - pointer __tmp = _M_allocate_and_copy(__xlen, __x.begin(), __x.end()); - std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish); - _M_deallocate(this->_M_impl._M_start, - this->_M_impl._M_end_of_storage - this->_M_impl._M_start); - this->_M_impl._M_start = __tmp; - this->_M_impl._M_end_of_storage = this->_M_impl._M_start + __xlen; - } - else if (size() >= __xlen) - { - iterator __i(std::copy(__x.begin(), __x.end(), begin())); - std::_Destroy(__i, end()); - } - else - { - std::copy(__x.begin(), __x.begin() + size(), this->_M_impl._M_start); - std::uninitialized_copy(__x.begin() + size(), __x.end(), this->_M_impl._M_finish); - } - this->_M_impl._M_finish = this->_M_impl._M_start + __xlen; - } + { + const size_type __xlen = __x.size(); + if (__xlen > capacity()) + { + pointer __tmp = _M_allocate_and_copy(__xlen, __x.begin(), + __x.end()); + std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish, + _M_get_Tp_allocator()); + _M_deallocate(this->_M_impl._M_start, + this->_M_impl._M_end_of_storage + - this->_M_impl._M_start); + this->_M_impl._M_start = __tmp; + this->_M_impl._M_end_of_storage = this->_M_impl._M_start + __xlen; + } + else if (size() >= __xlen) + { + std::_Destroy(std::copy(__x.begin(), __x.end(), begin()), + end(), _M_get_Tp_allocator()); + } + else + { + std::copy(__x._M_impl._M_start, __x._M_impl._M_start + size(), + this->_M_impl._M_start); + std::__uninitialized_copy_a(__x._M_impl._M_start + size(), + __x._M_impl._M_finish, + this->_M_impl._M_finish, + _M_get_Tp_allocator()); + } + this->_M_impl._M_finish = this->_M_impl._M_start + __xlen; + } return *this; } template<typename _Tp, typename _Alloc> void - vector<_Tp,_Alloc>:: + vector<_Tp, _Alloc>:: _M_fill_assign(size_t __n, const value_type& __val) { if (__n > capacity()) - { - vector __tmp(__n, __val, get_allocator()); - __tmp.swap(*this); - } + { + vector __tmp(__n, __val, _M_get_Tp_allocator()); + __tmp.swap(*this); + } else if (__n > size()) - { - std::fill(begin(), end(), __val); - this->_M_impl._M_finish - = std::uninitialized_fill_n(this->_M_impl._M_finish, __n - size(), __val); - } - else - erase(fill_n(begin(), __n, __val), end()); - } - - template<typename _Tp, typename _Alloc> template<typename _InputIterator> - void - vector<_Tp,_Alloc>:: - _M_assign_aux(_InputIterator __first, _InputIterator __last, input_iterator_tag) - { - iterator __cur(begin()); - for ( ; __first != __last && __cur != end(); ++__cur, ++__first) - *__cur = *__first; - if (__first == __last) - erase(__cur, end()); + { + std::fill(begin(), end(), __val); + std::__uninitialized_fill_n_a(this->_M_impl._M_finish, + __n - size(), __val, + _M_get_Tp_allocator()); + this->_M_impl._M_finish += __n - size(); + } else - insert(end(), __first, __last); + _M_erase_at_end(std::fill_n(this->_M_impl._M_start, __n, __val)); } - template<typename _Tp, typename _Alloc> template<typename _ForwardIterator> - void - vector<_Tp,_Alloc>:: - _M_assign_aux(_ForwardIterator __first, _ForwardIterator __last, - forward_iterator_tag) - { - size_type __len = std::distance(__first, __last); - - if (__len > capacity()) - { - pointer __tmp(_M_allocate_and_copy(__len, __first, __last)); - std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish); - _M_deallocate(this->_M_impl._M_start, - this->_M_impl._M_end_of_storage - this->_M_impl._M_start); - this->_M_impl._M_start = __tmp; - this->_M_impl._M_end_of_storage = this->_M_impl._M_finish = this->_M_impl._M_start + __len; - } - else if (size() >= __len) + template<typename _Tp, typename _Alloc> + template<typename _InputIterator> + void + vector<_Tp, _Alloc>:: + _M_assign_aux(_InputIterator __first, _InputIterator __last, + std::input_iterator_tag) { - iterator __new_finish(std::copy(__first, __last, this->_M_impl._M_start)); - std::_Destroy(__new_finish, end()); - this->_M_impl._M_finish = __new_finish.base(); + pointer __cur(this->_M_impl._M_start); + for (; __first != __last && __cur != this->_M_impl._M_finish; + ++__cur, ++__first) + *__cur = *__first; + if (__first == __last) + _M_erase_at_end(__cur); + else + insert(end(), __first, __last); } - else + + template<typename _Tp, typename _Alloc> + template<typename _ForwardIterator> + void + vector<_Tp, _Alloc>:: + _M_assign_aux(_ForwardIterator __first, _ForwardIterator __last, + std::forward_iterator_tag) { - _ForwardIterator __mid = __first; - std::advance(__mid, size()); - std::copy(__first, __mid, this->_M_impl._M_start); - this->_M_impl._M_finish = std::uninitialized_copy(__mid, __last, this->_M_impl._M_finish); + const size_type __len = std::distance(__first, __last); + + if (__len > capacity()) + { + pointer __tmp(_M_allocate_and_copy(__len, __first, __last)); + std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish, + _M_get_Tp_allocator()); + _M_deallocate(this->_M_impl._M_start, + this->_M_impl._M_end_of_storage + - this->_M_impl._M_start); + this->_M_impl._M_start = __tmp; + this->_M_impl._M_finish = this->_M_impl._M_start + __len; + this->_M_impl._M_end_of_storage = this->_M_impl._M_finish; + } + else if (size() >= __len) + _M_erase_at_end(std::copy(__first, __last, this->_M_impl._M_start)); + else + { + _ForwardIterator __mid = __first; + std::advance(__mid, size()); + std::copy(__first, __mid, this->_M_impl._M_start); + this->_M_impl._M_finish = + std::__uninitialized_copy_a(__mid, __last, + this->_M_impl._M_finish, + _M_get_Tp_allocator()); + } } - } template<typename _Tp, typename _Alloc> void - vector<_Tp,_Alloc>:: + vector<_Tp, _Alloc>:: _M_insert_aux(iterator __position, const _Tp& __x) { if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage) - { - std::_Construct(this->_M_impl._M_finish, *(this->_M_impl._M_finish - 1)); - ++this->_M_impl._M_finish; - _Tp __x_copy = __x; - std::copy_backward(__position, - iterator(this->_M_impl._M_finish-2), - iterator(this->_M_impl._M_finish-1)); - *__position = __x_copy; - } + { + this->_M_impl.construct(this->_M_impl._M_finish, + *(this->_M_impl._M_finish - 1)); + ++this->_M_impl._M_finish; + _Tp __x_copy = __x; + std::copy_backward(__position.base(), + this->_M_impl._M_finish - 2, + this->_M_impl._M_finish - 1); + *__position = __x_copy; + } else - { - const size_type __old_size = size(); - const size_type __len = __old_size != 0 ? 2 * __old_size : 1; - iterator __new_start(this->_M_allocate(__len)); - iterator __new_finish(__new_start); - try - { - __new_finish = std::uninitialized_copy(iterator(this->_M_impl._M_start), - __position, - __new_start); - std::_Construct(__new_finish.base(), __x); - ++__new_finish; - __new_finish = std::uninitialized_copy(__position, - iterator(this->_M_impl._M_finish), - __new_finish); - } - catch(...) - { - std::_Destroy(__new_start,__new_finish); - _M_deallocate(__new_start.base(),__len); - __throw_exception_again; - } - std::_Destroy(begin(), end()); - _M_deallocate(this->_M_impl._M_start, - this->_M_impl._M_end_of_storage - this->_M_impl._M_start); - this->_M_impl._M_start = __new_start.base(); - this->_M_impl._M_finish = __new_finish.base(); - this->_M_impl._M_end_of_storage = __new_start.base() + __len; - } + { + const size_type __old_size = size(); + if (__old_size == this->max_size()) + __throw_length_error(__N("vector::_M_insert_aux")); + + // When sizeof(value_type) == 1 and __old_size > size_type(-1)/2 + // __len overflows: if we don't notice and _M_allocate doesn't + // throw we crash badly later. + size_type __len = __old_size != 0 ? 2 * __old_size : 1; + if (__len < __old_size) + __len = this->max_size(); + + pointer __new_start(this->_M_allocate(__len)); + pointer __new_finish(__new_start); + try + { + __new_finish = + std::__uninitialized_copy_a(this->_M_impl._M_start, + __position.base(), __new_start, + _M_get_Tp_allocator()); + this->_M_impl.construct(__new_finish, __x); + ++__new_finish; + __new_finish = + std::__uninitialized_copy_a(__position.base(), + this->_M_impl._M_finish, + __new_finish, + _M_get_Tp_allocator()); + } + catch(...) + { + std::_Destroy(__new_start, __new_finish, _M_get_Tp_allocator()); + _M_deallocate(__new_start, __len); + __throw_exception_again; + } + std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish, + _M_get_Tp_allocator()); + _M_deallocate(this->_M_impl._M_start, + this->_M_impl._M_end_of_storage + - this->_M_impl._M_start); + this->_M_impl._M_start = __new_start; + this->_M_impl._M_finish = __new_finish; + this->_M_impl._M_end_of_storage = __new_start + __len; + } } template<typename _Tp, typename _Alloc> void - vector<_Tp,_Alloc>:: + vector<_Tp, _Alloc>:: _M_fill_insert(iterator __position, size_type __n, const value_type& __x) { if (__n != 0) - { - if (size_type(this->_M_impl._M_end_of_storage - this->_M_impl._M_finish) >= __n) - { - value_type __x_copy = __x; - const size_type __elems_after = end() - __position; - iterator __old_finish(this->_M_impl._M_finish); - if (__elems_after > __n) - { - std::uninitialized_copy(this->_M_impl._M_finish - __n, - this->_M_impl._M_finish, - this->_M_impl._M_finish); - this->_M_impl._M_finish += __n; - std::copy_backward(__position, __old_finish - __n, __old_finish); - std::fill(__position, __position + __n, __x_copy); - } - else - { - std::uninitialized_fill_n(this->_M_impl._M_finish, - __n - __elems_after, - __x_copy); - this->_M_impl._M_finish += __n - __elems_after; - std::uninitialized_copy(__position, __old_finish, this->_M_impl._M_finish); - this->_M_impl._M_finish += __elems_after; - std::fill(__position, __old_finish, __x_copy); - } - } - else - { - const size_type __old_size = size(); - const size_type __len = __old_size + std::max(__old_size, __n); - iterator __new_start(this->_M_allocate(__len)); - iterator __new_finish(__new_start); - try - { - __new_finish = std::uninitialized_copy(begin(), __position, - __new_start); - __new_finish = std::uninitialized_fill_n(__new_finish, __n, __x); - __new_finish = std::uninitialized_copy(__position, end(), - __new_finish); - } - catch(...) - { - std::_Destroy(__new_start,__new_finish); - _M_deallocate(__new_start.base(),__len); - __throw_exception_again; - } - std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish); - _M_deallocate(this->_M_impl._M_start, - this->_M_impl._M_end_of_storage - this->_M_impl._M_start); - this->_M_impl._M_start = __new_start.base(); - this->_M_impl._M_finish = __new_finish.base(); - this->_M_impl._M_end_of_storage = __new_start.base() + __len; - } - } + { + if (size_type(this->_M_impl._M_end_of_storage + - this->_M_impl._M_finish) >= __n) + { + value_type __x_copy = __x; + const size_type __elems_after = end() - __position; + pointer __old_finish(this->_M_impl._M_finish); + if (__elems_after > __n) + { + std::__uninitialized_copy_a(this->_M_impl._M_finish - __n, + this->_M_impl._M_finish, + this->_M_impl._M_finish, + _M_get_Tp_allocator()); + this->_M_impl._M_finish += __n; + std::copy_backward(__position.base(), __old_finish - __n, + __old_finish); + std::fill(__position.base(), __position.base() + __n, + __x_copy); + } + else + { + std::__uninitialized_fill_n_a(this->_M_impl._M_finish, + __n - __elems_after, + __x_copy, + _M_get_Tp_allocator()); + this->_M_impl._M_finish += __n - __elems_after; + std::__uninitialized_copy_a(__position.base(), __old_finish, + this->_M_impl._M_finish, + _M_get_Tp_allocator()); + this->_M_impl._M_finish += __elems_after; + std::fill(__position.base(), __old_finish, __x_copy); + } + } + else + { + const size_type __old_size = size(); + if (this->max_size() - __old_size < __n) + __throw_length_error(__N("vector::_M_fill_insert")); + + // See _M_insert_aux above. + size_type __len = __old_size + std::max(__old_size, __n); + if (__len < __old_size) + __len = this->max_size(); + + pointer __new_start(this->_M_allocate(__len)); + pointer __new_finish(__new_start); + try + { + __new_finish = + std::__uninitialized_copy_a(this->_M_impl._M_start, + __position.base(), + __new_start, + _M_get_Tp_allocator()); + std::__uninitialized_fill_n_a(__new_finish, __n, __x, + _M_get_Tp_allocator()); + __new_finish += __n; + __new_finish = + std::__uninitialized_copy_a(__position.base(), + this->_M_impl._M_finish, + __new_finish, + _M_get_Tp_allocator()); + } + catch(...) + { + std::_Destroy(__new_start, __new_finish, + _M_get_Tp_allocator()); + _M_deallocate(__new_start, __len); + __throw_exception_again; + } + std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish, + _M_get_Tp_allocator()); + _M_deallocate(this->_M_impl._M_start, + this->_M_impl._M_end_of_storage + - this->_M_impl._M_start); + this->_M_impl._M_start = __new_start; + this->_M_impl._M_finish = __new_finish; + this->_M_impl._M_end_of_storage = __new_start + __len; + } + } } template<typename _Tp, typename _Alloc> template<typename _InputIterator> void - vector<_Tp,_Alloc>:: - _M_range_insert(iterator __pos, - _InputIterator __first, _InputIterator __last, - input_iterator_tag) + vector<_Tp, _Alloc>:: + _M_range_insert(iterator __pos, _InputIterator __first, + _InputIterator __last, std::input_iterator_tag) { - for ( ; __first != __last; ++__first) - { - __pos = insert(__pos, *__first); - ++__pos; - } + for (; __first != __last; ++__first) + { + __pos = insert(__pos, *__first); + ++__pos; + } } - template<typename _Tp, typename _Alloc> template<typename _ForwardIterator> - void - vector<_Tp,_Alloc>:: - _M_range_insert(iterator __position,_ForwardIterator __first, - _ForwardIterator __last, forward_iterator_tag) - { - if (__first != __last) + template<typename _Tp, typename _Alloc> + template<typename _ForwardIterator> + void + vector<_Tp, _Alloc>:: + _M_range_insert(iterator __position, _ForwardIterator __first, + _ForwardIterator __last, std::forward_iterator_tag) { - size_type __n = std::distance(__first, __last); - if (size_type(this->_M_impl._M_end_of_storage - this->_M_impl._M_finish) >= __n) - { - const size_type __elems_after = end() - __position; - iterator __old_finish(this->_M_impl._M_finish); - if (__elems_after > __n) - { - std::uninitialized_copy(this->_M_impl._M_finish - __n, - this->_M_impl._M_finish, - this->_M_impl._M_finish); - this->_M_impl._M_finish += __n; - std::copy_backward(__position, __old_finish - __n, __old_finish); - std::copy(__first, __last, __position); - } - else - { - _ForwardIterator __mid = __first; - std::advance(__mid, __elems_after); - std::uninitialized_copy(__mid, __last, this->_M_impl._M_finish); - this->_M_impl._M_finish += __n - __elems_after; - std::uninitialized_copy(__position, __old_finish, this->_M_impl._M_finish); - this->_M_impl._M_finish += __elems_after; - std::copy(__first, __mid, __position); - } - } - else - { - const size_type __old_size = size(); - const size_type __len = __old_size + std::max(__old_size, __n); - iterator __new_start(this->_M_allocate(__len)); - iterator __new_finish(__new_start); - try - { - __new_finish = std::uninitialized_copy(iterator(this->_M_impl._M_start), - __position, __new_start); - __new_finish = std::uninitialized_copy(__first, __last, - __new_finish); - __new_finish = std::uninitialized_copy(__position, - iterator(this->_M_impl._M_finish), - __new_finish); - } - catch(...) - { - std::_Destroy(__new_start,__new_finish); - _M_deallocate(__new_start.base(), __len); - __throw_exception_again; - } - std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish); - _M_deallocate(this->_M_impl._M_start, - this->_M_impl._M_end_of_storage - this->_M_impl._M_start); - this->_M_impl._M_start = __new_start.base(); - this->_M_impl._M_finish = __new_finish.base(); - this->_M_impl._M_end_of_storage = __new_start.base() + __len; - } + if (__first != __last) + { + const size_type __n = std::distance(__first, __last); + if (size_type(this->_M_impl._M_end_of_storage + - this->_M_impl._M_finish) >= __n) + { + const size_type __elems_after = end() - __position; + pointer __old_finish(this->_M_impl._M_finish); + if (__elems_after > __n) + { + std::__uninitialized_copy_a(this->_M_impl._M_finish - __n, + this->_M_impl._M_finish, + this->_M_impl._M_finish, + _M_get_Tp_allocator()); + this->_M_impl._M_finish += __n; + std::copy_backward(__position.base(), __old_finish - __n, + __old_finish); + std::copy(__first, __last, __position); + } + else + { + _ForwardIterator __mid = __first; + std::advance(__mid, __elems_after); + std::__uninitialized_copy_a(__mid, __last, + this->_M_impl._M_finish, + _M_get_Tp_allocator()); + this->_M_impl._M_finish += __n - __elems_after; + std::__uninitialized_copy_a(__position.base(), + __old_finish, + this->_M_impl._M_finish, + _M_get_Tp_allocator()); + this->_M_impl._M_finish += __elems_after; + std::copy(__first, __mid, __position); + } + } + else + { + const size_type __old_size = size(); + if (this->max_size() - __old_size < __n) + __throw_length_error(__N("vector::_M_range_insert")); + + // See _M_insert_aux above. + size_type __len = __old_size + std::max(__old_size, __n); + if (__len < __old_size) + __len = this->max_size(); + + pointer __new_start(this->_M_allocate(__len)); + pointer __new_finish(__new_start); + try + { + __new_finish = + std::__uninitialized_copy_a(this->_M_impl._M_start, + __position.base(), + __new_start, + _M_get_Tp_allocator()); + __new_finish = + std::__uninitialized_copy_a(__first, __last, __new_finish, + _M_get_Tp_allocator()); + __new_finish = + std::__uninitialized_copy_a(__position.base(), + this->_M_impl._M_finish, + __new_finish, + _M_get_Tp_allocator()); + } + catch(...) + { + std::_Destroy(__new_start, __new_finish, + _M_get_Tp_allocator()); + _M_deallocate(__new_start, __len); + __throw_exception_again; + } + std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish, + _M_get_Tp_allocator()); + _M_deallocate(this->_M_impl._M_start, + this->_M_impl._M_end_of_storage + - this->_M_impl._M_start); + this->_M_impl._M_start = __new_start; + this->_M_impl._M_finish = __new_finish; + this->_M_impl._M_end_of_storage = __new_start + __len; + } + } } - } -} // namespace std + +_GLIBCXX_END_NESTED_NAMESPACE #endif /* _VECTOR_TCC */ |