diff options
author | paolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4> | 2008-05-23 01:39:17 +0000 |
---|---|---|
committer | paolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4> | 2008-05-23 01:39:17 +0000 |
commit | d64890c04581af07969401c844d47f37332327d2 (patch) | |
tree | 2c9a67492ce868bbbcbe2bf4aaa4bd2eba02688d | |
parent | 945e498ce8c441de3526643197e89fcba36b5d16 (diff) | |
download | gcc-d64890c04581af07969401c844d47f37332327d2.tar.gz |
2008-05-22 Paolo Carlini <paolo.carlini@oracle.com>
* include/tr1_impl/hashtable_policy.h (_Map_base<,,
std::_Select1st<_Pair>, true,>::at): Add per DR 761.
* testsuite/23_containers/unordered_map/dr761.cc: New.
* doc/xml/manual/intro.xml: Add an entry for DR 761.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@135787 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r-- | libstdc++-v3/ChangeLog | 7 | ||||
-rw-r--r-- | libstdc++-v3/doc/xml/manual/intro.xml | 6 | ||||
-rw-r--r-- | libstdc++-v3/include/tr1_impl/hashtable_policy.h | 52 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/23_containers/unordered_map/dr761.cc | 80 |
4 files changed, 143 insertions, 2 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index ee010df7714..dac9a8ac794 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,12 @@ 2008-05-22 Paolo Carlini <paolo.carlini@oracle.com> + * include/tr1_impl/hashtable_policy.h (_Map_base<,, + std::_Select1st<_Pair>, true,>::at): Add per DR 761. + * testsuite/23_containers/unordered_map/dr761.cc: New. + * doc/xml/manual/intro.xml: Add an entry for DR 761. + +2008-05-22 Paolo Carlini <paolo.carlini@oracle.com> + * testsuite/26_numerics/complex/dr781.cc: Add test variable. 2008-05-22 Paolo Carlini <paolo.carlini@oracle.com> diff --git a/libstdc++-v3/doc/xml/manual/intro.xml b/libstdc++-v3/doc/xml/manual/intro.xml index 578d303a396..3e84b554795 100644 --- a/libstdc++-v3/doc/xml/manual/intro.xml +++ b/libstdc++-v3/doc/xml/manual/intro.xml @@ -629,6 +629,12 @@ <listitem><para>Make the member functions table and classic_table public. </para></listitem></varlistentry> + <varlistentry><term><ulink url="lwg-active.html#761">761</ulink>: + <emphasis>unordered_map needs an at() member function</emphasis> + </term> + <listitem><para>In C++0x mode, add at() and at() const. + </para></listitem></varlistentry> + <varlistentry><term><ulink url="lwg-active.html#778">778</ulink>: <emphasis>std::bitset does not have any constructor taking a string literal</emphasis> </term> diff --git a/libstdc++-v3/include/tr1_impl/hashtable_policy.h b/libstdc++-v3/include/tr1_impl/hashtable_policy.h index f23f8c6f51d..6677a72d8d2 100644 --- a/libstdc++-v3/include/tr1_impl/hashtable_policy.h +++ b/libstdc++-v3/include/tr1_impl/hashtable_policy.h @@ -1,6 +1,6 @@ // Internal policy header for TR1 unordered_set and unordered_map -*- C++ -*- -// Copyright (C) 2007 Free Software Foundation, Inc. +// Copyright (C) 2007, 2008 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the @@ -530,12 +530,22 @@ namespace __detail }; template<typename _Key, typename _Pair, typename _Hashtable> - struct _Map_base<_Key, _Pair, std::_Select1st<_Pair>, true, _Hashtable> + struct _Map_base<_Key, _Pair, std::_Select1st<_Pair>, true, _Hashtable> { typedef typename _Pair::second_type mapped_type; mapped_type& operator[](const _Key& __k); + +#ifdef _GLIBCXX_INCLUDE_AS_CXX0X + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // DR 761. unordered_map needs an at() member function. + mapped_type& + at(const _Key& __k); + + const mapped_type& + at(const _Key& __k) const; +#endif }; template<typename _Key, typename _Pair, typename _Hashtable> @@ -557,6 +567,44 @@ namespace __detail return (__p->_M_v).second; } +#ifdef _GLIBCXX_INCLUDE_AS_CXX0X + template<typename _Key, typename _Pair, typename _Hashtable> + typename _Map_base<_Key, _Pair, std::_Select1st<_Pair>, + true, _Hashtable>::mapped_type& + _Map_base<_Key, _Pair, std::_Select1st<_Pair>, true, _Hashtable>:: + at(const _Key& __k) + { + _Hashtable* __h = static_cast<_Hashtable*>(this); + typename _Hashtable::_Hash_code_type __code = __h->_M_hash_code(__k); + std::size_t __n = __h->_M_bucket_index(__k, __code, + __h->_M_bucket_count); + + typename _Hashtable::_Node* __p = + __h->_M_find_node(__h->_M_buckets[__n], __k, __code); + if (!__p) + __throw_out_of_range(__N("_Map_base::at")); + return (__p->_M_v).second; + } + + template<typename _Key, typename _Pair, typename _Hashtable> + const typename _Map_base<_Key, _Pair, std::_Select1st<_Pair>, + true, _Hashtable>::mapped_type& + _Map_base<_Key, _Pair, std::_Select1st<_Pair>, true, _Hashtable>:: + at(const _Key& __k) const + { + const _Hashtable* __h = static_cast<const _Hashtable*>(this); + typename _Hashtable::_Hash_code_type __code = __h->_M_hash_code(__k); + std::size_t __n = __h->_M_bucket_index(__k, __code, + __h->_M_bucket_count); + + typename _Hashtable::_Node* __p = + __h->_M_find_node(__h->_M_buckets[__n], __k, __code); + if (!__p) + __throw_out_of_range(__N("_Map_base::at")); + return (__p->_M_v).second; + } +#endif + // class template _Rehash_base. Give hashtable the max_load_factor // functions iff the rehash policy is _Prime_rehash_policy. template<typename _RehashPolicy, typename _Hashtable> diff --git a/libstdc++-v3/testsuite/23_containers/unordered_map/dr761.cc b/libstdc++-v3/testsuite/23_containers/unordered_map/dr761.cc new file mode 100644 index 00000000000..a582bc4f6ea --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_map/dr761.cc @@ -0,0 +1,80 @@ +// { dg-options "-std=gnu++0x" } +// 2008-05-22 Paolo Carlini <paolo.carlini@oracle.com> +// +// Copyright (C) 2008 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +#include <unordered_map> +#include <stdexcept> +#include <testsuite_hooks.h> + +// DR 761. unordered_map needs an at() member function. +void test01() +{ + bool test __attribute__((unused)) = true; + typedef std::unordered_map<int, double> map_type; + + { + map_type m; + m[0] = 1.5; + + double& rd = m.at(0); + VERIFY( rd == 1.5 ); + try + { + m.at(1); + } + catch(std::out_of_range& obj) + { + // Expected. + } + catch(...) + { + // Failed. + throw; + } + } + + { + map_type m; + m[1] = 2.5; + const map_type cm(m); + + const double& crd = cm.at(1); + VERIFY( crd == 2.5 ); + try + { + cm.at(0); + } + catch(std::out_of_range& obj) + { + // Expected. + } + catch(...) + { + // Failed. + throw; + } + } +} + +int main() +{ + test01(); + return 0; +} |