functional (hash): New function object.

* include/tr1/functional (hash): New function object.
        * include/tr1/hashtable: New file.
        * include/tr1/unordered_set: New file.
        * include/tr1/unordered_map: New file.
        * include/Makefile.am: Add three new TR1 headers.
        * include/Makefile.in: Likewise.
        * testsuite/tr1/6_containers/unordered/insert/array_syntax.cc: New test.
        * testsuite/tr1/6_containers/unordered/insert/map_single.cc: New test.
        * testsuite/tr1/6_containers/unordered/insert/multimap_single.cc: New test.
        * testsuite/tr1/6_containers/unordered/insert/multiset_single.cc: New test.
        * testsuite/tr1/6_containers/unordered/insert/set_single.cc: New test.
        * testsuite/tr1/6_containers/unordered/instantiate/hash.cc: New test.
        * testsuite/tr1/6_containers/unordered/instantiate/map.cc: New test.
        * testsuite/tr1/6_containers/unordered/instantiate/multimap.cc: New test.
        * testsuite/tr1/6_containers/unordered/instantiate/multiset.cc: New test.
        * testsuite/tr1/6_containers/unordered/instantiate/set.cc: New test.

From-SVN: r95219
This commit is contained in:
Matt Austern 2005-02-18 07:50:08 +00:00 committed by Matt Austern
parent 82214ae9cc
commit 180ecd6aa2
17 changed files with 2369 additions and 5 deletions

View File

@ -1,3 +1,22 @@
2005-02-17 Matt Austern <austern@apple.com>
* include/tr1/functional (hash): New function object.
* include/tr1/hashtable: New file.
* include/tr1/unordered_set: New file.
* include/tr1/unordered_map: New file.
* include/Makefile.am: Add three new TR1 headers.
* include/Makefile.in: Likewise.
* testsuite/tr1/6_containers/unordered/insert/array_syntax.cc: New test.
* testsuite/tr1/6_containers/unordered/insert/map_single.cc: New test.
* testsuite/tr1/6_containers/unordered/insert/multimap_single.cc: New test.
* testsuite/tr1/6_containers/unordered/insert/multiset_single.cc: New test.
* testsuite/tr1/6_containers/unordered/insert/set_single.cc: New test.
* testsuite/tr1/6_containers/unordered/instantiate/hash.cc: New test.
* testsuite/tr1/6_containers/unordered/instantiate/map.cc: New test.
* testsuite/tr1/6_containers/unordered/instantiate/multimap.cc: New test.
* testsuite/tr1/6_containers/unordered/instantiate/multiset.cc: New test.
* testsuite/tr1/6_containers/unordered/instantiate/set.cc: New test.
2005-02-16 Paolo Carlini <pcarlini@suse.de>
* testsuite/23_containers/set/modifiers/16728.cc:

View File

@ -232,7 +232,10 @@ tr1_headers = \
${tr1_srcdir}/tuple \
${tr1_srcdir}/utility \
${tr1_srcdir}/type_traits \
${tr1_srcdir}/type_traits_fwd.h
${tr1_srcdir}/type_traits_fwd.h \
${tr1_srcdir}/hashtable \
${tr1_srcdir}/unordered_set \
${tr1_srcdir}/unordered_map
# This is the common subset of files that all three "C" header models use.

View File

@ -448,8 +448,10 @@ tr1_headers = \
${tr1_srcdir}/tuple \
${tr1_srcdir}/utility \
${tr1_srcdir}/type_traits \
${tr1_srcdir}/type_traits_fwd.h
${tr1_srcdir}/type_traits_fwd.h \
${tr1_srcdir}/hashtable \
${tr1_srcdir}/unordered_set \
${tr1_srcdir}/unordered_map
# This is the common subset of files that all three "C" header models use.
c_base_srcdir = $(C_INCLUDE_DIR)

View File

@ -1,6 +1,6 @@
// TR1 functional header -*- C++ -*-
// Copyright (C) 2004 Free Software Foundation, Inc.
// 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
@ -26,6 +26,7 @@
#define _TR1_FUNCTIONAL 1
#include "../functional"
#include <string> // for std::tr1::hash
namespace std
{
@ -78,8 +79,75 @@ namespace tr1
template<typename _Tp>
reference_wrapper<const _Tp> cref(reference_wrapper<_Tp> __t)
{ return cref(__t.get()); }
// Definition of default hash function std::tr1::hash<>. The types for
// which std::tr1::hash<T> is defined is in clause 6.3.3. of the PDTR.
template <typename T> struct hash;
#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);
tr1_hashtable_define_trivial_hash(char);
tr1_hashtable_define_trivial_hash(signed char);
tr1_hashtable_define_trivial_hash(unsigned char);
tr1_hashtable_define_trivial_hash(wchar_t);
tr1_hashtable_define_trivial_hash(short);
tr1_hashtable_define_trivial_hash(int);
tr1_hashtable_define_trivial_hash(long);
tr1_hashtable_define_trivial_hash(unsigned short);
tr1_hashtable_define_trivial_hash(unsigned int);
tr1_hashtable_define_trivial_hash(unsigned long);
tr1_hashtable_define_trivial_hash(float);
tr1_hashtable_define_trivial_hash(double);
tr1_hashtable_define_trivial_hash(long double);
#undef tr1_hashtable_define_trivial_hash
template <typename T>
struct hash<T*> {
std::size_t operator()(T* p) const {
return reinterpret_cast<std::size_t>(p);
}
};
// ??? We can probably find a better hash function than this (i.e. one
// that vectorizes better and that produces a more uniform distribution).
// XXX String hash probably shouldn't be an inline member function,
// since it's nontrivial. Once we have the framework for TR1 .cc
// files, this should go in one.
template <>
struct hash<std::string>
{
std::size_t operator()(const std::string& s) const
{
std::size_t result = 0;
for (std::string::const_iterator i = s.begin(); i != s.end(); ++i)
result = (result * 131) + *i;
return result;
}
};
template <>
struct hash<std::wstring>
{
std::size_t operator()(const std::wstring& s) const
{
std::size_t result = 0;
for (std::wstring::const_iterator i = s.begin(); i != s.end(); ++i)
result = (result * 131) + *i;
return result;
}
};
}
}
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,157 @@
// TR1 unordered_map -*- C++ -*-
// 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.
/** @file
* This is a TR1 C++ Library header.
*/
#ifndef GNU_LIBSTDCXX_TR1_UNORDERED_MAP_
#define GNU_LIBSTDCXX_TR1_UNORDERED_MAP_
#include <tr1/hashtable>
#include <tr1/functional>
#include <tr1/functional>
#include <utility>
#include <memory>
namespace std { namespace tr1 {
// XXX When we get typedef templates these class definitions will be unnecessary.
template <class Key, class T,
class Hash = hash<Key>,
class Pred = std::equal_to<Key>,
class Alloc = std::allocator<std::pair<const Key, T> >,
bool cache_hash_code = false>
class unordered_map
: public hashtable <Key, std::pair<const Key, T>,
Alloc,
Internal::extract1st<std::pair<const Key, T> >, Pred,
Hash, Internal::mod_range_hashing, Internal::default_ranged_hash,
Internal::prime_rehash_policy,
cache_hash_code, true, true>
{
typedef hashtable <Key, std::pair<const Key, T>,
Alloc,
Internal::extract1st<std::pair<const Key, T> >, Pred,
Hash, Internal::mod_range_hashing, Internal::default_ranged_hash,
Internal::prime_rehash_policy,
cache_hash_code, true, true>
Base;
public:
typedef typename Base::size_type size_type;
typedef typename Base::hasher hasher;
typedef typename Base::key_equal key_equal;
typedef typename Base::allocator_type allocator_type;
explicit unordered_map(size_type n = 10,
const hasher& hf = hasher(),
const key_equal& eql = key_equal(),
const allocator_type& a = allocator_type())
: Base (n,
hf, Internal::mod_range_hashing(), Internal::default_ranged_hash(),
eql, Internal::extract1st<std::pair<const Key, T> >(),
a)
{ }
template <typename InputIterator>
unordered_map(InputIterator f, InputIterator l,
size_type n = 10,
const hasher& hf = hasher(),
const key_equal& eql = key_equal(),
const allocator_type& a = allocator_type())
: Base (f, l,
n,
hf, Internal::mod_range_hashing(), Internal::default_ranged_hash(),
eql, Internal::extract1st<std::pair<const Key, T> >(),
a)
{ }
};
template <class Key, class T,
class Hash = hash<Key>,
class Pred = std::equal_to<Key>,
class Alloc = std::allocator<std::pair<const Key, T> >,
bool cache_hash_code = false>
class unordered_multimap
: public hashtable <Key, std::pair<const Key, T>,
Alloc,
Internal::extract1st<std::pair<const Key, T> >, Pred,
Hash, Internal::mod_range_hashing, Internal::default_ranged_hash,
Internal::prime_rehash_policy,
cache_hash_code, true, false>
{
typedef hashtable <Key, std::pair<const Key, T>,
Alloc,
Internal::extract1st<std::pair<const Key, T> >, Pred,
Hash, Internal::mod_range_hashing, Internal::default_ranged_hash,
Internal::prime_rehash_policy,
cache_hash_code, true, false>
Base;
public:
typedef typename Base::size_type size_type;
typedef typename Base::hasher hasher;
typedef typename Base::key_equal key_equal;
typedef typename Base::allocator_type allocator_type;
explicit unordered_multimap(size_type n = 10,
const hasher& hf = hasher(),
const key_equal& eql = key_equal(),
const allocator_type& a = allocator_type())
: Base (n,
hf, Internal::mod_range_hashing(), Internal::default_ranged_hash(),
eql, Internal::extract1st<std::pair<const Key, T> >(),
a)
{ }
template <typename InputIterator>
unordered_multimap(InputIterator f, InputIterator l,
typename Base::size_type n = 0,
const hasher& hf = hasher(),
const key_equal& eql = key_equal(),
const allocator_type& a = allocator_type())
: Base (f, l,
n,
hf, Internal::mod_range_hashing(), Internal::default_ranged_hash(),
eql, Internal::extract1st<std::pair<const Key, T> >(),
a)
{ }
};
template <class Key, class T, class Hash, class Pred, class Alloc, bool cache_hash_code>
inline void swap (unordered_map<Key, T, Hash, Pred, Alloc, cache_hash_code>& x,
unordered_map<Key, T, Hash, Pred, Alloc, cache_hash_code>& y)
{
x.swap(y);
}
template <class Key, class T, class Hash, class Pred, class Alloc, bool cache_hash_code>
inline void swap (unordered_multimap<Key, T, Hash, Pred, Alloc, cache_hash_code>& x,
unordered_multimap<Key, T, Hash, Pred, Alloc, cache_hash_code>& y)
{
x.swap(y);
}
} }
#endif /* GNU_LIBSTDCXX_TR1_UNORDERED_MAP_ */

View File

@ -0,0 +1,151 @@
// TR1 unordered_set -*- C++ -*-
// 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.
/** @file
* This is a TR1 C++ Library header.
*/
#ifndef GNU_LIBSTDCXX_TR1_UNORDERED_SET_
#define GNU_LIBSTDCXX_TR1_UNORDERED_SET_
#include <tr1/hashtable>
#include <tr1/functional>
#include <memory>
namespace std { namespace tr1 {
// XXX When we get typedef templates these class definitions will be unnecessary.
template <class Value,
class Hash = hash<Value>,
class Pred = std::equal_to<Value>,
class Alloc = std::allocator<Value>,
bool cache_hash_code = false>
class unordered_set
: public hashtable <Value, Value, Alloc,
Internal::identity<Value>, Pred,
Hash, Internal::mod_range_hashing, Internal::default_ranged_hash,
Internal::prime_rehash_policy,
cache_hash_code, false, true>
{
typedef hashtable <Value, Value, Alloc,
Internal::identity<Value>, Pred,
Hash, Internal::mod_range_hashing, Internal::default_ranged_hash,
Internal::prime_rehash_policy,
cache_hash_code, false, true>
Base;
public:
typedef typename Base::size_type size_type;
typedef typename Base::hasher hasher;
typedef typename Base::key_equal key_equal;
typedef typename Base::allocator_type allocator_type;
explicit unordered_set(size_type n = 10,
const hasher& hf = hasher(),
const key_equal& eql = key_equal(),
const allocator_type& a = allocator_type())
: Base (n,
hf, Internal::mod_range_hashing(), Internal::default_ranged_hash(),
eql, Internal::identity<Value>(),
a)
{ }
template <typename InputIterator>
unordered_set(InputIterator f, InputIterator l,
size_type n = 10,
const hasher& hf = hasher(),
const key_equal& eql = key_equal(),
const allocator_type& a = allocator_type())
: Base (f, l,
n,
hf, Internal::mod_range_hashing(), Internal::default_ranged_hash(),
eql, Internal::identity<Value>(),
a)
{ }
};
template <class Value,
class Hash = hash<Value>,
class Pred = std::equal_to<Value>,
class Alloc = std::allocator<Value>,
bool cache_hash_code = false>
class unordered_multiset
: public hashtable <Value, Value, Alloc,
Internal::identity<Value>, Pred,
Hash, Internal::mod_range_hashing, Internal::default_ranged_hash,
Internal::prime_rehash_policy,
cache_hash_code, false, false>
{
typedef hashtable <Value, Value, Alloc,
Internal::identity<Value>, Pred,
Hash, Internal::mod_range_hashing, Internal::default_ranged_hash,
Internal::prime_rehash_policy,
cache_hash_code, false, false>
Base;
public:
typedef typename Base::size_type size_type;
typedef typename Base::hasher hasher;
typedef typename Base::key_equal key_equal;
typedef typename Base::allocator_type allocator_type;
explicit unordered_multiset(size_type n = 10,
const hasher& hf = hasher(),
const key_equal& eql = key_equal(),
const allocator_type& a = allocator_type())
: Base (n,
hf, Internal::mod_range_hashing(), Internal::default_ranged_hash(),
eql, Internal::identity<Value>(),
a)
{ }
template <typename InputIterator>
unordered_multiset(InputIterator f, InputIterator l,
typename Base::size_type n = 0,
const hasher& hf = hasher(),
const key_equal& eql = key_equal(),
const allocator_type& a = allocator_type())
: Base (f, l,
n,
hf, Internal::mod_range_hashing(), Internal::default_ranged_hash(),
eql, Internal::identity<Value>(),
a)
{ }
};
template <class Value, class Hash, class Pred, class Alloc, bool cache_hash_code>
inline void swap (unordered_set<Value, Hash, Pred, Alloc, cache_hash_code>& x,
unordered_set<Value, Hash, Pred, Alloc, cache_hash_code>& y)
{
x.swap(y);
}
template <class Value, class Hash, class Pred, class Alloc, bool cache_hash_code>
inline void swap (unordered_multiset<Value, Hash, Pred, Alloc, cache_hash_code>& x,
unordered_multiset<Value, Hash, Pred, Alloc, cache_hash_code>& y)
{
x.swap(y);
}
} }
#endif /* GNU_LIBSTDCXX_TR1_UNORDERED_SET_ */

View File

@ -0,0 +1,61 @@
// { dg-do run }
// 2005-2-17 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
// Array version of insert
#include <string>
#include <iterator>
#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());
m["red"] = 17;
VERIFY(m.size() == 1);
VERIFY(m.begin()->first == "red");
VERIFY(m.begin()->second == 17);
VERIFY(m["red"] == 17);
m["blue"] == 9;
VERIFY(m.size() == 2);
VERIFY(m["blue"] == 9);
m["red"] = 5;
VERIFY(m.size() == 2);
VERIFY(m["red"] == 5);
VERIFY(m["blue"] == 9);
}
int main()
{
test01();
return 0;
}

View File

@ -0,0 +1,74 @@
// { dg-do run }
// 2005-2-17 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
// Single-element insert
#include <string>
#include <iterator>
#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> p = m.insert(Pair("abcde", 3));
VERIFY(p.second);
VERIFY(m.size() == 1);
VERIFY(std::distance(m.begin(), m.end()) == 1);
VERIFY(p.first == m.begin());
VERIFY(p.first->first == "abcde");
VERIFY(p.first->second == 3);
}
void test02()
{
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> p1 = m.insert(Pair("abcde", 3));
std::pair<Map::iterator, bool> p2 = m.insert(Pair("abcde", 7));
VERIFY(p1.second);
VERIFY(!p2.second);
VERIFY(m.size() == 1);
VERIFY(p1.first == p2.first);
VERIFY(p1.first->first == "abcde");
VERIFY(p2.first->second == 3);
}
int main()
{
test01();
test02();
return 0;
}

View File

@ -0,0 +1,78 @@
// { dg-do run }
// 2005-2-17 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
// Single-element insert
#include <string>
#include <iterator>
#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());
Map::iterator i = m.insert(Pair("abcde", 3));
VERIFY(m.size() == 1);
VERIFY(std::distance(m.begin(), m.end()) == 1);
VERIFY(i == m.begin());
VERIFY(i->first == "abcde");
VERIFY(i->second == 3);
}
void test02()
{
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("abcde", 3));
m.insert(Pair("abcde", 7));
VERIFY(m.size() == 2);
VERIFY(std::distance(m.begin(), m.end()) == 2);
Map::iterator i1 = m.begin();
Map::iterator i2 = i1;
++i2;
VERIFY(i1->first == "abcde");
VERIFY(i2->first == "abcde");
VERIFY((i1->second == 3 && i2->second == 7) ||
(i1->second == 7 && i2->second == 3));
}
int main()
{
test01();
test02();
return 0;
}

View File

@ -0,0 +1,69 @@
// { dg-do run }
// 2005-2-17 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_multiset
// Single-element insert
#include <string>
#include <iterator>
#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());
Set::iterator i = s.insert("abcde");
VERIFY(s.size() == 1);
VERIFY(std::distance(s.begin(), s.end()) == 1);
VERIFY(i == s.begin());
VERIFY(*i == "abcde");
}
void test02()
{
typedef std::tr1::unordered_multiset<std::string> Set;
Set s;
VERIFY(s.empty());
s.insert("abcde");
Set::iterator i = s.insert("abcde");
VERIFY(s.size() == 2);
VERIFY(std::distance(s.begin(), s.end()) == 2);
VERIFY(*i == "abcde");
Set::iterator i2 = s.begin();
++i2;
VERIFY(i == s.begin() || i == i2);
VERIFY(*(s.begin()) == "abcde" && *i2 == "abcde");
}
int main()
{
test01();
test02();
return 0;
}

View File

@ -0,0 +1,67 @@
// { dg-do run }
// 2005-2-17 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
// Single-element insert
#include <string>
#include <iterator>
#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> p = s.insert("abcde");
VERIFY(p.second);
VERIFY(s.size() == 1);
VERIFY(std::distance(s.begin(), s.end()) == 1);
VERIFY(p.first == s.begin());
VERIFY(*p.first == "abcde");
}
void test02()
{
typedef std::tr1::unordered_set<std::string> Set;
Set s;
VERIFY(s.empty());
std::pair<Set::iterator, bool> p1 = s.insert("abcde");
std::pair<Set::iterator, bool> p2 = s.insert("abcde");
VERIFY(p1.second);
VERIFY(!p2.second);
VERIFY(s.size() == 1);
VERIFY(p1.first == p2.first);
VERIFY(*p1.first == "abcde");
}
int main()
{
test01();
test02();
return 0;
}

View File

@ -0,0 +1,51 @@
// { dg-do compile }
// 2005-2-17 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.3 class template hash
#include <string>
#include <tr1/functional>
int main()
{
using namespace std::tr1;
// Verify that we can instantiate hash for every required type.
hash<bool> hb;
hash<char> hc;
hash<signed char> hsc;
hash<unsigned char> huc;
hash<wchar_t> hw;
hash<short> hs;
hash<int> hi;
hash<long> hl;
hash<unsigned short> hus;
hash<unsigned int> hui;
hash<unsigned long> hul;
hash<float> hf;
hash<double> hd;
hash<long double> hld;
hash<void*> hp;
hash<std::string> hstr;
hash<std::wstring> hwstr;
}

View File

@ -0,0 +1,37 @@
// { dg-do compile }
// 2005-2-17 Matt Austern <austern@apple.com>
//
// Copyright (C) 2004 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
#include <string>
#include <tr1/unordered_map>
int main()
{
using namespace std;
using namespace std::tr1;
unordered_map<string, float> m1;
unordered_map<string, float,
hash<string>, equal_to<string>,
allocator<pair<const string, float> >, true> s2;
}

View File

@ -0,0 +1,37 @@
// { dg-do compile }
// 2005-2-17 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
#include <string>
#include <tr1/unordered_map>
int main()
{
using namespace std;
using namespace std::tr1;
unordered_multimap<string, float> m1;
unordered_multimap<string, float,
hash<string>, equal_to<string>,
allocator<pair<const string, float> >, true> s2;
}

View File

@ -0,0 +1,34 @@
// { dg-do compile }
// 2005-2-17 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_multiset
#include <tr1/unordered_set>
int main()
{
using namespace std;
using namespace std::tr1;
unordered_multiset<int> s1;
unordered_multiset<int, hash<int>, equal_to<int>, allocator<int>, true> s2;
}

View File

@ -0,0 +1,34 @@
// { dg-do compile }
// 2005-2-17 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
#include <tr1/unordered_set>
int main()
{
using namespace std;
using namespace std::tr1;
unordered_set<int> s1;
unordered_set<int, hash<int>, equal_to<int>, allocator<int>, true> s2;
}