diff --git a/btree_container.h b/btree_container.h index c9c62c3..fb617ab 100644 --- a/btree_container.h +++ b/btree_container.h @@ -261,8 +261,7 @@ class btree_map_container : public btree_unique_container { btree_map_container(InputIterator b, InputIterator e, const key_compare &comp = key_compare(), const allocator_type &alloc = allocator_type()) - : super_type(comp, alloc) { - insert(b, e); + : super_type(b, e, comp, alloc) { } // Insertion routines. @@ -303,7 +302,7 @@ class btree_multi_container : public btree_container { btree_multi_container(InputIterator b, InputIterator e, const key_compare &comp = key_compare(), const allocator_type &alloc = allocator_type()) - : super_type(b, e, comp, alloc) { + : super_type(comp, alloc) { insert(b, e); } diff --git a/btree_map.h b/btree_map.h index 07b799e..b83489f 100644 --- a/btree_map.h +++ b/btree_map.h @@ -33,7 +33,7 @@ namespace btree { -// The btree_map class is needed mainly for it's constructors. +// The btree_map class is needed mainly for its constructors. template , typename Alloc = std::allocator >, @@ -68,7 +68,7 @@ class btree_map : public btree_map_container< btree_map(InputIterator b, InputIterator e, const key_compare &comp = key_compare(), const allocator_type &alloc = allocator_type()) - : super_type(comp, alloc) { + : super_type(b, e, comp, alloc) { } }; @@ -78,7 +78,7 @@ inline void swap(btree_map &x, x.swap(y); } -// The btree_multimap class is needed mainly for it's constructors. +// The btree_multimap class is needed mainly for its constructors. template , typename Alloc = std::allocator >, diff --git a/btree_set.h b/btree_set.h index 2bc9e58..f9b2e75 100644 --- a/btree_set.h +++ b/btree_set.h @@ -29,7 +29,7 @@ namespace btree { -// The btree_set class is needed mainly for it's constructors. +// The btree_set class is needed mainly for its constructors. template , typename Alloc = std::allocator, @@ -72,7 +72,7 @@ inline void swap(btree_set &x, btree_set &y) { x.swap(y); } -// The btree_multiset class is needed mainly for it's constructors. +// The btree_multiset class is needed mainly for its constructors. template , typename Alloc = std::allocator, diff --git a/btree_test.cc b/btree_test.cc index 56a787b..52bd219 100644 --- a/btree_test.cc +++ b/btree_test.cc @@ -244,5 +244,24 @@ TEST(Btree, Comparison) { EXPECT_TRUE(my_map != my_map_copy); } +TEST(Btree, RangeCtorSanity) { + typedef btree_set, allocator, 256> test_set; + typedef btree_map, allocator, 256> test_map; + typedef btree_multiset, allocator, 256> test_mset; + typedef btree_multimap, allocator, 256> test_mmap; + vector ivec; + ivec.push_back(1); + map imap; + imap.insert(make_pair(1, 2)); + test_mset tmset(ivec.begin(), ivec.end()); + test_mmap tmmap(imap.begin(), imap.end()); + test_set tset(ivec.begin(), ivec.end()); + test_map tmap(imap.begin(), imap.end()); + EXPECT_EQ(1, tmset.size()); + EXPECT_EQ(1, tmmap.size()); + EXPECT_EQ(1, tset.size()); + EXPECT_EQ(1, tmap.size()); +} + } // namespace } // namespace btree diff --git a/btree_test.h b/btree_test.h index 0ac26ef..413dc3c 100644 --- a/btree_test.h +++ b/btree_test.h @@ -147,6 +147,13 @@ class base_checker { const_tree_(tree_), checker_(x.checker_) { } + // Range constructor. + template + base_checker(InputIterator b, InputIterator e) + : tree_(b, e), + const_tree_(tree_), + checker_(b, e) { + } // Iterator routines. iterator begin() { return tree_.begin(); } @@ -398,8 +405,8 @@ class unique_checker : public base_checker { } // Range constructor. template - unique_checker(InputIterator b, InputIterator e) { - insert(b, e); + unique_checker(InputIterator b, InputIterator e) + : super_type(b, e) { } // Insertion routines. @@ -455,8 +462,8 @@ class multi_checker : public base_checker { } // Range constructor. template - multi_checker(InputIterator b, InputIterator e) { - insert(b, e); + multi_checker(InputIterator b, InputIterator e) + : super_type(b, e) { } // Insertion routines. @@ -587,6 +594,7 @@ void DoTest(const char *name, T *b, const std::vector &values) { mutable_b.insert(values[i]); mutable_b.value_check(values[i]); } + assert(mutable_b.size() == values.size()); const_b.verify(); printf(" %s fullness=%0.2f overhead=%0.2f bytes-per-value=%0.2f\n",