This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[committed] New tests and fixes for TR1 unordered associative containers


Four new test cases that check find(), count(), and equal_range(), and
fixes to stupid bugs that they revealed.  Mostly the bugs are just
embarrassing const correctness problems and the like; nothing worth
discussing in any detail.

                    --Matt

Index: libstdc++-v3/ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/ChangeLog,v
retrieving revision 1.2903
diff -p -r1.2903 ChangeLog
*** libstdc++-v3/ChangeLog	19 Feb 2005 15:33:57 -0000	1.2903
--- libstdc++-v3/ChangeLog	19 Feb 2005 23:40:16 -0000
***************
*** 1,3 ****
--- 1,17 ----
+ 2005-02-19  Matt Austern  <austern@gmail.com>
+ 
+ 	* include/tr1/functional (tr1_hashtable_define_trivial_hash): Make
+ 	hash<T>::operator() a const member function for T a fundamental type
+ 	* include/tr1/hashtable (extract1st::operator()): Declare const.
+ 	(hash_code_base): Declare all member functions const
+ 	(hashtable::find): fix call to this->bucket_count()
+ 	(hashtable::count): Likewise.
+ 	(hashtable::equal_range): m_incr_bucket applies to iterator, not node.
+ 	* testsuite/tr1/6_containers/unordered/find/set1.cc: New test.
+ 	* testsuite/tr1/6_containers/unordered/find/map1.cc: New test.
+ 	* testsuite/tr1/6_containers/unordered/find/multimap1.cc: New test.
+ 	* testsuite/tr1/6_containers/unordered/find/multiset1.cc: New test.
+ 	
  2005-02-19  Hans-Peter Nilsson  <hp@axis.com>
  
  	PR libstdc++/20071
Index: libstdc++-v3/include/tr1/functional
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/tr1/functional,v
retrieving revision 1.3
diff -p -r1.3 functional
*** libstdc++-v3/include/tr1/functional	19 Feb 2005 15:33:59 -0000	1.3
--- libstdc++-v3/include/tr1/functional	19 Feb 2005 23:40:16 -0000
*************** namespace tr1
*** 88,94 ****
  
    #define tr1_hashtable_define_trivial_hash(T) 				    \
      template <> struct hash<T> {						    \
!       std::size_t operator()(T val) { return
static_cast<std::size_t>(val); } \
      }									    \
  
    tr1_hashtable_define_trivial_hash(bool);
--- 88,94 ----
  
    #define tr1_hashtable_define_trivial_hash(T) 				    \
      template <> struct hash<T> {						    \
!       std::size_t operator()(T val) const { return
static_cast<std::size_t>(val); } \
      }									    \
  
    tr1_hashtable_define_trivial_hash(bool);
Index: libstdc++-v3/include/tr1/hashtable
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/tr1/hashtable,v
retrieving revision 1.1
diff -p -r1.1 hashtable
*** libstdc++-v3/include/tr1/hashtable	18 Feb 2005 07:50:08 -0000	1.1
--- libstdc++-v3/include/tr1/hashtable	19 Feb 2005 23:40:16 -0000
*************** struct identity {
*** 251,257 ****
  
  template <typename Pair>
  struct extract1st {
!   typename Pair::first_type operator()(const Pair& p) { return p.first; }
  };
  
  // Default range hashing function: use division to fold a large number
--- 251,257 ----
  
  template <typename Pair>
  struct extract1st {
!   typename Pair::first_type operator()(const Pair& p) const { return
p.first; }
  };
  
  // Default range hashing function: use division to fold a large number
*************** protected:
*** 519,535 ****
      : m_extract(ex), m_eq(eq), m_ranged_hash(h) { }
  
    typedef void* hash_code_t;
!   hash_code_t m_hash_code (const Key& k) { return 0; }
    std::size_t bucket_index (const Key& k, hash_code_t, std::size_t N) const
      { return m_ranged_hash (k, N); }
!   std::size_t bucket_index (const hash_node<Value, false>* p, std::size_t N) {
      return m_ranged_hash (m_extract (p->m_v), N); 
    }
    
!   bool compare (const Key& k, hash_code_t, hash_node<Value, false>* n)
      { return m_eq (k, m_extract(n->m_v)); }
  
!   void copy_code (hash_node<Value, false>*, const hash_node<Value,
false>*) { }
  
    void m_swap(hash_code_base& x) {
      m_extract.m_swap(x);
--- 519,535 ----
      : m_extract(ex), m_eq(eq), m_ranged_hash(h) { }
  
    typedef void* hash_code_t;
!   hash_code_t m_hash_code (const Key& k) const { return 0; }
    std::size_t bucket_index (const Key& k, hash_code_t, std::size_t N) const
      { return m_ranged_hash (k, N); }
!   std::size_t bucket_index (const hash_node<Value, false>* p,
std::size_t N) const {
      return m_ranged_hash (m_extract (p->m_v), N); 
    }
    
!   bool compare (const Key& k, hash_code_t, hash_node<Value, false>* n) const
      { return m_eq (k, m_extract(n->m_v)); }
  
!   void copy_code (hash_node<Value, false>*, const hash_node<Value,
false>*) const { }
  
    void m_swap(hash_code_base& x) {
      m_extract.m_swap(x);
*************** protected:
*** 576,592 ****
      : m_extract(ex), m_eq(eq), m_h1(h1), m_h2(h2) { }
  
    typedef std::size_t hash_code_t;
!   hash_code_t m_hash_code (const Key& k) { return m_h1(k); }
    std::size_t bucket_index (const Key&, hash_code_t c, std::size_t N) const
      { return m_h2 (c, N); }
!   std::size_t bucket_index (const hash_node<Value, false>* p, std::size_t N) {
      return m_h2 (m_h1 (m_extract (p->m_v)), N);
    }
  
!   bool compare (const Key& k, hash_code_t,  hash_node<Value, false>* n)
      { return m_eq (k, m_extract(n->m_v)); }
  
!   void copy_code (hash_node<Value, false>*, const hash_node<Value,
false>*) { }
  
    void m_swap(hash_code_base& x) {
      m_extract.m_swap(x);
--- 576,592 ----
      : m_extract(ex), m_eq(eq), m_h1(h1), m_h2(h2) { }
  
    typedef std::size_t hash_code_t;
!   hash_code_t m_hash_code (const Key& k) const { return m_h1(k); }
    std::size_t bucket_index (const Key&, hash_code_t c, std::size_t N) const
      { return m_h2 (c, N); }
!   std::size_t bucket_index (const hash_node<Value, false>* p,
std::size_t N) const {
      return m_h2 (m_h1 (m_extract (p->m_v)), N);
    }
  
!   bool compare (const Key& k, hash_code_t,  hash_node<Value, false>* n) const
      { return m_eq (k, m_extract(n->m_v)); }
  
!   void copy_code (hash_node<Value, false>*, const hash_node<Value,
false>*) const { }
  
    void m_swap(hash_code_base& x) {
      m_extract.m_swap(x);
*************** protected:
*** 619,636 ****
      : m_extract(ex), m_eq(eq), m_h1(h1), m_h2(h2) { }
  
    typedef std::size_t hash_code_t;
!   hash_code_t m_hash_code (const Key& k) { return m_h1(k); }
    std::size_t bucket_index (const Key&, hash_code_t c, std::size_t N) const
      { return m_h2 (c, N); }
  
!   std::size_t bucket_index (const hash_node<Value, true>* p, std::size_t N) {
      return m_h2 (p->hash_code, N);
    }
  
!   bool compare (const Key& k, hash_code_t c,  hash_node<Value, true>* n)
      { return c == n->hash_code && m_eq (k, m_extract(n->m_v)); }
  
!   void copy_code (hash_node<Value, true>* to, const hash_node<Value,
true>* from)
      { to->hash_code = from->hash_code; }
  
    void m_swap(hash_code_base& x) {
--- 619,636 ----
      : m_extract(ex), m_eq(eq), m_h1(h1), m_h2(h2) { }
  
    typedef std::size_t hash_code_t;
!   hash_code_t m_hash_code (const Key& k) const { return m_h1(k); }
    std::size_t bucket_index (const Key&, hash_code_t c, std::size_t N) const
      { return m_h2 (c, N); }
  
!   std::size_t bucket_index (const hash_node<Value, true>* p,
std::size_t N) const {
      return m_h2 (p->hash_code, N);
    }
  
!   bool compare (const Key& k, hash_code_t c,  hash_node<Value, true>* n) const
      { return c == n->hash_code && m_eq (k, m_extract(n->m_v)); }
  
!   void copy_code (hash_node<Value, true>* to, const hash_node<Value,
true>* from) const
      { to->hash_code = from->hash_code; }
  
    void m_swap(hash_code_base& x) {
*************** typename hashtable<K,V,A,Ex,Eq,H1,H2,H,R
*** 1109,1115 ****
  hashtable<K,V,A,Ex,Eq,H1,H2,H,RP,c,m,u>::find (const key_type& k)
  {
    typename hashtable::hash_code_t code = this->m_hash_code (k);
!   std::size_t n = this->bucket_index (k, code, this->bucket_count);
    node* p = find_node (m_buckets[n], k, code);
    return p ? iterator(p, m_buckets + n) : this->end();
  }
--- 1109,1115 ----
  hashtable<K,V,A,Ex,Eq,H1,H2,H,RP,c,m,u>::find (const key_type& k)
  {
    typename hashtable::hash_code_t code = this->m_hash_code (k);
!   std::size_t n = this->bucket_index (k, code, this->bucket_count());
    node* p = find_node (m_buckets[n], k, code);
    return p ? iterator(p, m_buckets + n) : this->end();
  }
*************** typename hashtable<K,V,A,Ex,Eq,H1,H2,H,R
*** 1122,1128 ****
  hashtable<K,V,A,Ex,Eq,H1,H2,H,RP,c,m,u>::find (const key_type& k) const
  {
    typename hashtable::hash_code_t code = this->m_hash_code (k);
!   std::size_t n = this->bucket_index (k, code, this->bucket_count);
    node* p = find_node (m_buckets[n], k, code);
    return p ? const_iterator(p, m_buckets + n) : this->end();
  }
--- 1122,1128 ----
  hashtable<K,V,A,Ex,Eq,H1,H2,H,RP,c,m,u>::find (const key_type& k) const
  {
    typename hashtable::hash_code_t code = this->m_hash_code (k);
!   std::size_t n = this->bucket_index (k, code, this->bucket_count());
    node* p = find_node (m_buckets[n], k, code);
    return p ? const_iterator(p, m_buckets + n) : this->end();
  }
*************** typename hashtable<K,V,A,Ex,Eq,H1,H2,H,R
*** 1135,1141 ****
  hashtable<K,V,A,Ex,Eq,H1,H2,H,RP,c,m,u>::count (const key_type& k) const
  {
    typename hashtable::hash_code_t code = this->m_hash_code (k);
!   std::size_t n = this->bucket_index (k, code, this->bucket_count);
    size_t result = 0;
    for (node* p = m_buckets[n]; p ; p = p->m_next)
      if (this->compare (k, code, p))
--- 1135,1141 ----
  hashtable<K,V,A,Ex,Eq,H1,H2,H,RP,c,m,u>::count (const key_type& k) const
  {
    typename hashtable::hash_code_t code = this->m_hash_code (k);
!   std::size_t n = this->bucket_index (k, code, this->bucket_count());
    size_t result = 0;
    for (node* p = m_buckets[n]; p ; p = p->m_next)
      if (this->compare (k, code, p))
*************** std::pair<typename hashtable<K,V,A,Ex,Eq
*** 1152,1158 ****
  hashtable<K,V,A,Ex,Eq,H1,H2,H,RP,c,m,u>::equal_range (const key_type& k)
  {
    typename hashtable::hash_code_t code = this->m_hash_code (k);
!   std::size_t n = this->bucket_index (k, code, this->bucket_count);
    node** head = m_buckets + n;
    node* p = find_node (*head, k, code);
  
--- 1152,1158 ----
  hashtable<K,V,A,Ex,Eq,H1,H2,H,RP,c,m,u>::equal_range (const key_type& k)
  {
    typename hashtable::hash_code_t code = this->m_hash_code (k);
!   std::size_t n = this->bucket_index (k, code, this->bucket_count());
    node** head = m_buckets + n;
    node* p = find_node (*head, k, code);
  
*************** hashtable<K,V,A,Ex,Eq,H1,H2,H,RP,c,m,u>:
*** 1164,1170 ****
      iterator first(p, head);
      iterator last(p1, head);
      if (!p1)
!       p1->m_incr_bucket();
      return std::make_pair(first, last);
    }
    else
--- 1164,1170 ----
      iterator first(p, head);
      iterator last(p1, head);
      if (!p1)
!       last.m_incr_bucket();
      return std::make_pair(first, last);
    }
    else
*************** std::pair<typename hashtable<K,V,A,Ex,Eq
*** 1180,1186 ****
  hashtable<K,V,A,Ex,Eq,H1,H2,H,RP,c,m,u>::equal_range (const key_type& k) const
  {
    typename hashtable::hash_code_t code = this->m_hash_code (k);
!   std::size_t n = this->bucket_index (k, code, this->bucket_count);
    node** head = m_buckets + n;
    node* p = find_node (*head, k, code);
  
--- 1180,1186 ----
  hashtable<K,V,A,Ex,Eq,H1,H2,H,RP,c,m,u>::equal_range (const key_type& k) const
  {
    typename hashtable::hash_code_t code = this->m_hash_code (k);
!   std::size_t n = this->bucket_index (k, code, this->bucket_count());
    node** head = m_buckets + n;
    node* p = find_node (*head, k, code);
  
*************** hashtable<K,V,A,Ex,Eq,H1,H2,H,RP,c,m,u>:
*** 1192,1198 ****
      const_iterator first(p, head);
      const_iterator last(p1, head);
      if (!p1)
!       p1->m_incr_bucket();
      return std::make_pair(first, last);
    }
    else
--- 1192,1198 ----
      const_iterator first(p, head);
      const_iterator last(p1, head);
      if (!p1)
!       last.m_incr_bucket();
      return std::make_pair(first, last);
    }
    else
Index: libstdc++-v3/testsuite/tr1/6_containers/unordered/find/map1.cc
===================================================================
RCS file: libstdc++-v3/testsuite/tr1/6_containers/unordered/find/map1.cc
diff -N libstdc++-v3/testsuite/tr1/6_containers/unordered/find/map1.cc
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- libstdc++-v3/testsuite/tr1/6_containers/unordered/find/map1.cc	19
Feb 2005 23:40:18 -0000
***************
*** 0 ****
--- 1,71 ----
+ // { dg-do run }
+ 
+ // 2005-2-18  Matt Austern  <austern@apple.com>
+ //
+ // 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+ // USA.
+ 
+ // 6.3.4.4 unordered_map
+ // find, equal_range, count
+ 
+ #include <string>
+ #include <iterator>
+ #include <algorithm>
+ #include <utility>
+ #include <tr1/unordered_map>
+ #include "testsuite_hooks.h"
+ 
+ bool test __attribute__((unused)) = true;
+ 
+ void test01()
+ {
+   typedef std::tr1::unordered_map<std::string, int> Map;
+   typedef std::pair<const std::string, int> Pair;
+ 
+   Map m;
+   VERIFY(m.empty());
+ 
+   std::pair<Map::iterator, bool> tmp = m.insert(Pair("grape", 3));
+   Map::iterator i = tmp.first;
+   VERIFY(tmp.second);
+ 
+   Map::iterator i2 = m.find("grape");
+   VERIFY(i2 != m.end());
+   VERIFY(i2 == i);
+   VERIFY(i2->first == "grape");
+   VERIFY(i2->second == 3);
+ 
+   Map::iterator i3 = m.find("lime");
+   VERIFY(i3 == m.end());
+ 
+   std::pair<Map::iterator, Map::iterator> p = m.equal_range("grape");
+   VERIFY(std::distance(p.first, p.second) == 1);
+   VERIFY(p.first == i2);
+ 
+   std::pair<Map::iterator, Map::iterator> p2 = m.equal_range("lime");
+   VERIFY(p2.first == p2.second);
+ 
+   VERIFY(m.count("grape") == 1);
+   VERIFY(m.count("lime") == 0);
+ }
+ 
+ int main()
+ {
+   test01();
+   return 0;
+ }
Index: libstdc++-v3/testsuite/tr1/6_containers/unordered/find/multimap1.cc
===================================================================
RCS file: libstdc++-v3/testsuite/tr1/6_containers/unordered/find/multimap1.cc
diff -N libstdc++-v3/testsuite/tr1/6_containers/unordered/find/multimap1.cc
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- libstdc++-v3/testsuite/tr1/6_containers/unordered/find/multimap1.cc	19
Feb 2005 23:40:18 -0000
***************
*** 0 ****
--- 1,85 ----
+ // { dg-do run }
+ 
+ // 2005-2-18  Matt Austern  <austern@apple.com>
+ //
+ // 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+ // USA.
+ 
+ // 6.3.4.6 unordered_multimap
+ // find, equal_range, count
+ 
+ #include <string>
+ #include <iterator>
+ #include <algorithm>
+ #include <utility>
+ #include <tr1/unordered_map>
+ #include "testsuite_hooks.h"
+ 
+ bool test __attribute__((unused)) = true;
+ 
+ void test01()
+ {
+   typedef std::tr1::unordered_multimap<std::string, int> Map;
+   typedef std::pair<const std::string, int> Pair;
+ 
+   Map m;
+   VERIFY(m.empty());
+ 
+   m.insert(Pair("grape", 3));
+   m.insert(Pair("durian", 8));
+   m.insert(Pair("grape", 7));
+ 
+   Map::iterator i1 = m.find("grape");
+   Map::iterator i2 = m.find("durian");
+   Map::iterator i3 = m.find("kiwi");
+ 
+   VERIFY(i1 != m.end());
+   VERIFY(i1->first == "grape");
+   VERIFY(i1->second == 3 || i2->second == 7);
+   VERIFY(i2 != m.end());
+   VERIFY(i2->first == "durian");
+   VERIFY(i2->second == 8);
+   VERIFY(i3 == m.end());
+ 
+   std::pair<Map::iterator, Map::iterator> p1 = m.equal_range("grape");
+   VERIFY(std::distance(p1.first, p1.second) == 2);
+   Map::iterator tmp = p1.first;
+   ++tmp;
+   VERIFY(p1.first->first == "grape");
+   VERIFY(tmp->first == "grape");
+   VERIFY((p1.first->second == 3 && tmp->second == 7) ||
+ 	 (p1.first->second == 7 && tmp->second == 3));
+ 
+   std::pair<Map::iterator, Map::iterator> p2 = m.equal_range("durian");
+   VERIFY(std::distance(p2.first, p2.second) == 1);
+   VERIFY(p2.first->first == "durian");
+   VERIFY(p2.first->second == 8);
+ 
+   std::pair<Map::iterator, Map::iterator> p3 = m.equal_range("kiwi");
+   VERIFY(p3.first == p3.second);
+ 
+   VERIFY(m.count("grape") == 2);
+   VERIFY(m.count("durian") == 1);
+   VERIFY(m.count("kiwi") == 0);
+ }
+ 
+ int main()
+ {
+   test01();
+   return 0;
+ }
Index: libstdc++-v3/testsuite/tr1/6_containers/unordered/find/multiset1.cc
===================================================================
RCS file: libstdc++-v3/testsuite/tr1/6_containers/unordered/find/multiset1.cc
diff -N libstdc++-v3/testsuite/tr1/6_containers/unordered/find/multiset1.cc
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- libstdc++-v3/testsuite/tr1/6_containers/unordered/find/multiset1.cc	19
Feb 2005 23:40:18 -0000
***************
*** 0 ****
--- 1,67 ----
+ // { dg-do run }
+ 
+ // 2005-2-18  Matt Austern  <austern@apple.com>
+ //
+ // 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+ // USA.
+ 
+ // 6.3.4.5 unordered_set
+ // find, equal_range, count
+ 
+ #include <string>
+ #include <iterator>
+ #include <algorithm>
+ #include <tr1/unordered_set>
+ #include "testsuite_hooks.h"
+ 
+ bool test __attribute__((unused)) = true;
+ 
+ void test01()
+ {
+   typedef std::tr1::unordered_multiset<std::string> Set;
+   Set s;
+   VERIFY(s.empty());
+ 
+   s.insert("grape");
+   s.insert("banana");
+   s.insert("grape");
+ 
+   Set::iterator i2 = s.find("banana");
+   VERIFY(i2 != s.end());
+   VERIFY(*i2 == "banana");
+   
+   std::pair<Set::iterator, Set::iterator> p = s.equal_range("grape");
+   VERIFY(std::distance(p.first, p.second) == 2);
+   Set::iterator i3 = p.first;
+   ++i3;
+   VERIFY(*p.first == "grape");
+   VERIFY(*i3 == "grape");
+ 
+   Set::iterator i4 = s.find("lime");
+   VERIFY(i4 == s.end());  
+ 
+   VERIFY(s.count("grape") == 2);
+   VERIFY(s.count("banana") == 1);
+   VERIFY(s.count("lime") == 0);
+ }
+ 
+ int main()
+ {
+   test01();
+   return 0;
+ }
Index: libstdc++-v3/testsuite/tr1/6_containers/unordered/find/set1.cc
===================================================================
RCS file: libstdc++-v3/testsuite/tr1/6_containers/unordered/find/set1.cc
diff -N libstdc++-v3/testsuite/tr1/6_containers/unordered/find/set1.cc
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- libstdc++-v3/testsuite/tr1/6_containers/unordered/find/set1.cc	19
Feb 2005 23:40:18 -0000
***************
*** 0 ****
--- 1,66 ----
+ // { dg-do run }
+ 
+ // 2005-2-18  Matt Austern  <austern@apple.com>
+ //
+ // 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+ // USA.
+ 
+ // 6.3.4.3 unordered_set
+ // find, equal_range, count
+ 
+ #include <string>
+ #include <iterator>
+ #include <algorithm>
+ #include <tr1/unordered_set>
+ #include "testsuite_hooks.h"
+ 
+ bool test __attribute__((unused)) = true;
+ 
+ void test01()
+ {
+   typedef std::tr1::unordered_set<std::string> Set;
+   Set s;
+   VERIFY(s.empty());
+ 
+   std::pair<Set::iterator, bool> tmp = s.insert("grape");
+   Set::iterator i = tmp.first;
+ 
+   Set::iterator i2 = s.find("grape");
+   VERIFY(i2 != s.end());
+   VERIFY(i2 == i);
+   VERIFY(*i2 == "grape");
+ 
+   std::pair<Set::iterator, Set::iterator> p = s.equal_range("grape");
+   VERIFY(p.first == i2);
+   VERIFY(std::distance(p.first, p.second) == 1);
+ 
+   Set::iterator i3 = s.find("lime");
+   VERIFY(i3 == s.end());  
+ 
+   std::pair<Set::iterator, Set::iterator> p2 = s.equal_range("lime");
+   VERIFY(p2.first == p2.second);
+ 
+   VERIFY(s.count("grape") == 1);
+   VERIFY(s.count("lime") == 0);
+ }
+ 
+ int main()
+ {
+   test01();
+   return 0;
+ }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]