|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r48950 - in branches/initializer-list: boost/unordered libs/unordered/test/unordered
From: daniel_james_at_[hidden]
Date: 2008-09-24 15:06:41
Author: danieljames
Date: 2008-09-24 15:06:40 EDT (Wed, 24 Sep 2008)
New Revision: 48950
URL: http://svn.boost.org/trac/boost/changeset/48950
Log:
Add initializer list support to unordered containers, still needs documentation and more tests.
Text files modified:
branches/initializer-list/boost/unordered/unordered_map.hpp | 36 ++++++++++++++++++++++++++++++++++++
branches/initializer-list/boost/unordered/unordered_set.hpp | 36 ++++++++++++++++++++++++++++++++++++
branches/initializer-list/libs/unordered/test/unordered/assign_tests.cpp | 16 ++++++++++++++++
branches/initializer-list/libs/unordered/test/unordered/constructor_tests.cpp | 11 +++++++++++
4 files changed, 99 insertions(+), 0 deletions(-)
Modified: branches/initializer-list/boost/unordered/unordered_map.hpp
==============================================================================
--- branches/initializer-list/boost/unordered/unordered_map.hpp (original)
+++ branches/initializer-list/boost/unordered/unordered_map.hpp 2008-09-24 15:06:40 EDT (Wed, 24 Sep 2008)
@@ -126,6 +126,24 @@
#endif
#endif
+#if !defined(BOOST_NO_INITIALIZER_LISTS)
+ unordered_map(std::initializer_list<value_type> list,
+ size_type n = boost::unordered_detail::default_initial_bucket_count,
+ const hasher &hf = hasher(),
+ const key_equal &eql = key_equal(),
+ const allocator_type &a = allocator_type())
+ : base(list.begin(), list.end(), n, hf, eql, a)
+ {
+ }
+
+ unordered_map& operator=(std::initializer_list<value_type> list)
+ {
+ base.data_.clear();
+ base.insert_range(list.begin(), list.end());
+ return *this;
+ }
+#endif
+
private:
BOOST_DEDUCED_TYPENAME implementation::iterator_base const&
@@ -514,6 +532,24 @@
#endif
#endif
+#if !defined(BOOST_NO_INITIALIZER_LISTS)
+ unordered_multimap(std::initializer_list<value_type> list,
+ size_type n = boost::unordered_detail::default_initial_bucket_count,
+ const hasher &hf = hasher(),
+ const key_equal &eql = key_equal(),
+ const allocator_type &a = allocator_type())
+ : base(list.begin(), list.end(), n, hf, eql, a)
+ {
+ }
+
+ unordered_multimap& operator=(std::initializer_list<value_type> list)
+ {
+ base.data_.clear();
+ base.insert_range(list.begin(), list.end());
+ return *this;
+ }
+#endif
+
private:
Modified: branches/initializer-list/boost/unordered/unordered_set.hpp
==============================================================================
--- branches/initializer-list/boost/unordered/unordered_set.hpp (original)
+++ branches/initializer-list/boost/unordered/unordered_set.hpp 2008-09-24 15:06:40 EDT (Wed, 24 Sep 2008)
@@ -124,6 +124,24 @@
#endif
#endif
+#if !defined(BOOST_NO_INITIALIZER_LISTS)
+ unordered_set(std::initializer_list<value_type> list,
+ size_type n = boost::unordered_detail::default_initial_bucket_count,
+ const hasher &hf = hasher(),
+ const key_equal &eql = key_equal(),
+ const allocator_type &a = allocator_type())
+ : base(list.begin(), list.end(), n, hf, eql, a)
+ {
+ }
+
+ unordered_set& operator=(std::initializer_list<value_type> list)
+ {
+ base.data_.clear();
+ base.insert_range(list.begin(), list.end());
+ return *this;
+ }
+#endif
+
private:
BOOST_DEDUCED_TYPENAME implementation::iterator_base const&
@@ -484,6 +502,24 @@
#endif
#endif
+#if !defined(BOOST_NO_INITIALIZER_LISTS)
+ unordered_multiset(std::initializer_list<value_type> list,
+ size_type n = boost::unordered_detail::default_initial_bucket_count,
+ const hasher &hf = hasher(),
+ const key_equal &eql = key_equal(),
+ const allocator_type &a = allocator_type())
+ : base(list.begin(), list.end(), n, hf, eql, a)
+ {
+ }
+
+ unordered_multiset& operator=(std::initializer_list<value_type> list)
+ {
+ base.data_.clear();
+ base.insert_range(list.begin(), list.end());
+ return *this;
+ }
+#endif
+
private:
BOOST_DEDUCED_TYPENAME implementation::iterator_base const&
Modified: branches/initializer-list/libs/unordered/test/unordered/assign_tests.cpp
==============================================================================
--- branches/initializer-list/libs/unordered/test/unordered/assign_tests.cpp (original)
+++ branches/initializer-list/libs/unordered/test/unordered/assign_tests.cpp 2008-09-24 15:06:40 EDT (Wed, 24 Sep 2008)
@@ -103,6 +103,22 @@
((default_generator)(generate_collisions))
)
+#if !defined(BOOST_NO_INITIALIZER_LISTS)
+
+UNORDERED_AUTO_TEST(assign_initializer_list)
+{
+ std::cerr<<"Initializer List Tests\n";
+
+ boost::unordered_set<int> x;
+ x.insert(10);
+ x.insert(20);
+ x = { 1, 2, -10 };
+ BOOST_CHECK(x.find(10) == x.end());
+ BOOST_CHECK(x.find(-10) != x.end());
+}
+
+#endif
+
}
RUN_TESTS()
Modified: branches/initializer-list/libs/unordered/test/unordered/constructor_tests.cpp
==============================================================================
--- branches/initializer-list/libs/unordered/test/unordered/constructor_tests.cpp (original)
+++ branches/initializer-list/libs/unordered/test/unordered/constructor_tests.cpp 2008-09-24 15:06:40 EDT (Wed, 24 Sep 2008)
@@ -288,6 +288,17 @@
((test_map)(test_multimap))
)
+#if !defined(BOOST_NO_INITIALIZER_LISTS)
+
+UNORDERED_AUTO_TEST(test_initializer_list) {
+ std::cerr<<"Initializer List Tests\n";
+ boost::unordered_set<int> x1 = { 2, 10, 45, -5 };
+ BOOST_CHECK(x1.find(10) != x1.end());
+ BOOST_CHECK(x1.find(46) == x1.end());
+}
+
+#endif
+
}
RUN_TESTS()
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk