PR libstdc++/23578 (DR 464 [Ready])
* include/bits/stl_map.h (class map): Add at(const key_type&)
member functions.
* include/bits/stl_vector.h (class vector): Add data() member
functions.
* include/debug/map.h (class map): Adjust consistently.
* include/debug/vector (class vector): Likewise.
* testsuite/23_containers/map/element_access/1.cc: New.
* testsuite/23_containers/vector/data_access/1.cc: Likewise.
* docs/html/ext/howto.html: Add an entry for DR 464.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@103609
138bc75d-0d04-0410-961f-
82ee72b054a4
+2005-08-29 Paolo Carlini <pcarlini@suse.de>
+
+ PR libstdc++/23578 (DR 464 [Ready])
+ * include/bits/stl_map.h (class map): Add at(const key_type&)
+ member functions.
+ * include/bits/stl_vector.h (class vector): Add data() member
+ functions.
+ * include/debug/map.h (class map): Adjust consistently.
+ * include/debug/vector (class vector): Likewise.
+ * testsuite/23_containers/map/element_access/1.cc: New.
+ * testsuite/23_containers/vector/data_access/1.cc: Likewise.
+ * docs/html/ext/howto.html: Add an entry for DR 464.
+
2005-08-26 Benjamin Kosnik <bkoz@redhat.com>
PR libstdc++/20534 (contd)
</dt>
<dd>Don't fail if the next pointer is null and newoff is zero.
</dd>
+
+ <dt><a href="lwg-active.html#464">464</a>:
+ <em>Suggestion for new member functions in standard containers</em>
+ </dt>
+ <dd>Add <code>data()</code> to <code>std::vector</code> and
+ <code>at(const key_type&)</code> to <code>std::map</code>.
+ </dd>
<!--
<dt><a href="lwg-defects.html#"></a>:
<em></em>
#ifndef _MAP_H
#define _MAP_H 1
+#include <bits/functexcept.h>
#include <bits/concept_check.h>
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 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.
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
/**
* @brief Add data to the end of the %vector.
// 23.3.1.2 element access:
using _Base::operator[];
+ // _GLIBCXX_RESOLVE_LIB_DEFECTS
+ // DR 464. Suggestion for new member functions in standard containers.
+ using _Base::at;
+
// modifiers:
std::pair<iterator, bool>
insert(const value_type& __x)
return _Base::back();
}
+ // _GLIBCXX_RESOLVE_LIB_DEFECTS
+ // DR 464. Suggestion for new member functions in standard containers.
+ using _Base::data;
+
// 23.2.4.3 modifiers:
void
push_back(const _Tp& __x)
--- /dev/null
+// 2005-08-29 Paolo Carlini <pcarlini@suse.de>
+//
+// Copyright (C) 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
+// 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 <map>
+#include <stdexcept>
+#include <testsuite_hooks.h>
+
+// libstdc++/23578
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+ typedef std::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;
+}
--- /dev/null
+// 2005-08-29 Paolo Carlini <pcarlini@suse.de>
+//
+// Copyright (C) 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
+// 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 <vector>
+#include <testsuite_hooks.h>
+
+// libstdc++/23578
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+ typedef std::vector<int> vector_type;
+
+ {
+ const int A[] = { 0, 1, 2, 3, 4 };
+ vector_type v(A, A + 5);
+ VERIFY( v.data() == &v.front() );
+ int* pi = v.data();
+ VERIFY( *pi == 0 );
+ }
+
+ {
+ const int A[] = { 4, 3, 2, 1, 0 };
+ const vector_type cv(A, A + 5);
+ VERIFY( cv.data() == &cv.front() );
+ const int* pci = cv.data();
+ VERIFY( *pci == 4 );
+ }
+}
+
+int main()
+{
+ test01();
+ return 0;
+}