diff --git a/libcxx/test/std/containers/unord/unord.map/hash_function.pass.cpp b/libcxx/test/std/containers/unord/unord.map/hash_function.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/hash_function.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_map + +// hasher hash_function() const; + +#include +#include +#include + +int main(int, char**) { + typedef std::unordered_map map_type; + map_type m; + + std::pair p = m.insert(map_type::value_type(1, "abc")); + + const map_type& cm = m; + assert(cm.hash_function()(p.first->first) == cm.hash_function()(1)); + assert(cm.hash_function()(1) == cm.hash_function()(p.first->first)); + + return 0; +} diff --git a/libcxx/test/std/containers/unord/unord.map/key_eq.pass.cpp b/libcxx/test/std/containers/unord/unord.map/key_eq.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/key_eq.pass.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_map + +// hasher key_eq() const; + +#include +#include +#include + +int main(int, char**) { + typedef std::unordered_map map_type; + + map_type m; + std::pair p1 = m.insert(map_type::value_type(1, "abc")); + std::pair p2 = m.insert(map_type::value_type(2, "abc")); + + const map_type& cm = m; + + assert(cm.key_eq()(p1.first->first, p1.first->first)); + assert(cm.key_eq()(p2.first->first, p2.first->first)); + assert(!cm.key_eq()(p1.first->first, p2.first->first)); + assert(!cm.key_eq()(p2.first->first, p1.first->first)); + + return 0; +} diff --git a/libcxx/test/std/containers/unord/unord.multimap/hash_function.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/hash_function.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multimap/hash_function.pass.cpp @@ -0,0 +1,33 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_multimap + +// hasher hash_function() const; + +#include +#include +#include + +int main(int, char**) { + typedef std::unordered_multimap map_type; + map_type m; + + map_type::iterator i1 = m.insert(map_type::value_type(1, "abc")); + map_type::iterator i2 = m.insert(map_type::value_type(1, "bcd")); + + const map_type& cm = m; + assert(cm.hash_function()(i1->first) == cm.hash_function()(i2->first)); + assert(cm.hash_function()(i2->first) == cm.hash_function()(i1->first)); + + return 0; +} diff --git a/libcxx/test/std/containers/unord/unord.multimap/key_eq.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/key_eq.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multimap/key_eq.pass.cpp @@ -0,0 +1,47 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_multimap + +// hasher key_eq() const; + +#include +#include +#include + +#include "test_macros.h" + +int main(int, char**) { + typedef std::unordered_multimap map_type; + + map_type m; + map_type::iterator i1 = m.insert(map_type::value_type(1, "abc")); + map_type::iterator i2 = m.insert(map_type::value_type(1, "bcd")); + map_type::iterator i3 = m.insert(map_type::value_type(2, "abc")); + + const map_type& cm = m; + + assert(cm.key_eq()(i1->first, i1->first)); + assert(cm.key_eq()(i2->first, i2->first)); + assert(cm.key_eq()(i3->first, i3->first)); + + assert(cm.key_eq()(i1->first, i2->first)); + assert(cm.key_eq()(i2->first, i1->first)); + + assert(!cm.key_eq()(i1->first, i3->first)); + assert(!cm.key_eq()(i3->first, i1->first)); + + assert(!cm.key_eq()(i2->first, i3->first)); + assert(!cm.key_eq()(i3->first, i2->first)); + + return 0; +} diff --git a/libcxx/test/std/containers/unord/unord.multiset/hash_function.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/hash_function.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multiset/hash_function.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_multiset + +// hasher hash_function() const; + +#include +#include + +int main(int, char**) { + typedef std::unordered_multiset set_type; + set_type s; + + set_type::iterator i1 = s.insert(1); + set_type::iterator i2 = s.insert(1); + + const set_type& cs = s; + assert(cs.hash_function()(*i1) == cs.hash_function()(*i2)); + assert(cs.hash_function()(*i2) == cs.hash_function()(*i1)); + + return 0; +} diff --git a/libcxx/test/std/containers/unord/unord.multiset/key_eq.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/key_eq.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multiset/key_eq.pass.cpp @@ -0,0 +1,44 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_multiset + +// key_equal key_eq() const; + +#include +#include + +int main(int, char**) { + typedef std::unordered_multiset set_type; + set_type s; + + set_type::iterator i1 = s.insert(1); + set_type::iterator i2 = s.insert(1); + set_type::iterator i3 = s.insert(2); + + const set_type& cs = s; + + assert(cs.key_eq()(*i1, *i1)); + assert(cs.key_eq()(*i2, *i2)); + assert(cs.key_eq()(*i3, *i3)); + + assert(cs.key_eq()(*i1, *i2)); + assert(cs.key_eq()(*i2, *i1)); + + assert(!cs.key_eq()(*i1, *i3)); + assert(!cs.key_eq()(*i3, *i1)); + + assert(!cs.key_eq()(*i2, *i3)); + assert(!cs.key_eq()(*i3, *i2)); + + return 0; +} diff --git a/libcxx/test/std/containers/unord/unord.set/hash_function.pass.cpp b/libcxx/test/std/containers/unord/unord.set/hash_function.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/hash_function.pass.cpp @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_set + +// hasher hash_function() const; + +#include +#include + +int main(int, char**) { + typedef std::unordered_set set_type; + set_type s; + + std::pair p = s.insert(1); + + const set_type& cs = s; + assert(cs.hash_function()(*p.first) == cs.hash_function()(1)); + assert(cs.hash_function()(1) == cs.hash_function()(*p.first)); + + return 0; +} diff --git a/libcxx/test/std/containers/unord/unord.set/key_eq.pass.cpp b/libcxx/test/std/containers/unord/unord.set/key_eq.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/key_eq.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_set + +// key_equal key_eq() const; + +#include +#include + +int main(int, char**) { + typedef std::unordered_set set_type; + + set_type s; + + std::pair p1 = s.insert(1); + std::pair p2 = s.insert(2); + + const set_type& cs = s; + + assert(cs.key_eq()(*p1.first, *p1.first)); + assert(cs.key_eq()(*p2.first, *p2.first)); + + assert(!cs.key_eq()(*p1.first, *p2.first)); + assert(!cs.key_eq()(*p2.first, *p1.first)); + + return 0; +}