diff --git a/include/tinystl/hash_base.h b/include/tinystl/hash_base.h index 9d70ef0..73b5c9e 100644 --- a/include/tinystl/hash_base.h +++ b/include/tinystl/hash_base.h @@ -84,6 +84,9 @@ namespace tinystl { const Key first; unordered_hash_node* next; unordered_hash_node* prev; + + private: + unordered_hash_node& operator=(const unordered_hash_node&); }; template diff --git a/include/tinystl/unordered_set.h b/include/tinystl/unordered_set.h index a4caddd..976a412 100644 --- a/include/tinystl/unordered_set.h +++ b/include/tinystl/unordered_set.h @@ -81,12 +81,12 @@ namespace tinystl { { const size_t nbuckets = (size_t)(other.m_buckets.last - other.m_buckets.first); buffer_init(&m_buckets); - buffer_resize(&m_buckets, 9, 0); + buffer_resize(&m_buckets, nbuckets, 0); - for (pointer* it = *other.m_buckets.first; it; it = it->next) { + for (pointer it = *other.m_buckets.first; it; it = it->next) { unordered_hash_node* newnode = new(placeholder(), Alloc::static_allocate(sizeof(unordered_hash_node))) unordered_hash_node(*it); newnode->next = newnode->prev = 0; - unordered_hash_node_insert(newnode, hash(*it), m_buckets.first, nbuckets - 1); + unordered_hash_node_insert(newnode, hash(it->first), m_buckets.first, nbuckets - 1); } } diff --git a/tests/unordered_set_copyctor.cpp b/tests/unordered_set_copyctor.cpp new file mode 100644 index 0000000..621df02 --- /dev/null +++ b/tests/unordered_set_copyctor.cpp @@ -0,0 +1,43 @@ +/*- +* Copyright 2012-2015 Matthew Endsley +* All rights reserved +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted providing that the following conditions +* are met: +* 1. Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* 2. Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the distribution. +* +* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY +* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +* POSSIBILITY OF SUCH DAMAGE. +*/ + +#include "test.h" + +#include +#include +#include + +TEST(uoset_copyctor) { + + // verify this compiles + typedef tinystl::unordered_set set; + set s; + s.insert(32); + set other = s; + CHECK(other.find(32) != other.end()); + other.clear(); + CHECK(other.empty()); +} diff --git a/tests/unordered_set_pod.cpp b/tests/unordered_set_pod.cpp new file mode 100644 index 0000000..ed40840 --- /dev/null +++ b/tests/unordered_set_pod.cpp @@ -0,0 +1,39 @@ +/*- +* Copyright 2012-2015 Matthew Endsley +* All rights reserved +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted providing that the following conditions +* are met: +* 1. Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* 2. Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the distribution. +* +* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY +* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +* POSSIBILITY OF SUCH DAMAGE. +*/ + +#include "test.h" + +#include +#include +#include + +TEST(uoset_pod_compiles) { + + // verify this compiles + tinystl::unordered_set s; + s.insert(32); + s.clear(); +}