Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r56560 - in trunk: boost/unordered libs/unordered/test/unordered
From: daniel_james_at_[hidden]
Date: 2009-10-03 12:41:33


Author: danieljames
Date: 2009-10-03 12:41:32 EDT (Sat, 03 Oct 2009)
New Revision: 56560
URL: http://svn.boost.org/trac/boost/changeset/56560

Log:
Insert using initializer lists.
Text files modified:
   trunk/boost/unordered/unordered_map.hpp | 14 +++++++++++
   trunk/boost/unordered/unordered_set.hpp | 14 +++++++++++
   trunk/libs/unordered/test/unordered/insert_tests.cpp | 48 ++++++++++++++++++++++++++++++++++++++++
   3 files changed, 76 insertions(+), 0 deletions(-)

Modified: trunk/boost/unordered/unordered_map.hpp
==============================================================================
--- trunk/boost/unordered/unordered_map.hpp (original)
+++ trunk/boost/unordered/unordered_map.hpp 2009-10-03 12:41:32 EDT (Sat, 03 Oct 2009)
@@ -343,6 +343,13 @@
             table_.insert_range(first, last);
         }
 
+#if !defined(BOOST_NO_0X_HDR_INITIALIZER_LIST)
+ void insert(std::initializer_list<value_type> list)
+ {
+ table_.insert_range(list.begin(), list.end());
+ }
+#endif
+
         iterator erase(const_iterator position)
         {
             return iterator(table_.erase(get(position)));
@@ -837,6 +844,13 @@
             table_.insert_range(first, last);
         }
 
+#if !defined(BOOST_NO_0X_HDR_INITIALIZER_LIST)
+ void insert(std::initializer_list<value_type> list)
+ {
+ table_.insert_range(list.begin(), list.end());
+ }
+#endif
+
         iterator erase(const_iterator position)
         {
             return iterator(table_.erase(get(position)));

Modified: trunk/boost/unordered/unordered_set.hpp
==============================================================================
--- trunk/boost/unordered/unordered_set.hpp (original)
+++ trunk/boost/unordered/unordered_set.hpp 2009-10-03 12:41:32 EDT (Sat, 03 Oct 2009)
@@ -337,6 +337,13 @@
             table_.insert_range(first, last);
         }
 
+#if !defined(BOOST_NO_0X_HDR_INITIALIZER_LIST)
+ void insert(std::initializer_list<value_type> list)
+ {
+ table_.insert_range(list.begin(), list.end());
+ }
+#endif
+
         iterator erase(const_iterator position)
         {
             return iterator(table_.erase(get(position)));
@@ -793,6 +800,13 @@
             table_.insert_range(first, last);
         }
 
+#if !defined(BOOST_NO_0X_HDR_INITIALIZER_LIST)
+ void insert(std::initializer_list<value_type> list)
+ {
+ table_.insert_range(list.begin(), list.end());
+ }
+#endif
+
         iterator erase(const_iterator position)
         {
             return iterator(table_.erase(get(position)));

Modified: trunk/libs/unordered/test/unordered/insert_tests.cpp
==============================================================================
--- trunk/libs/unordered/test/unordered/insert_tests.cpp (original)
+++ trunk/libs/unordered/test/unordered/insert_tests.cpp 2009-10-03 12:41:32 EDT (Sat, 03 Oct 2009)
@@ -372,6 +372,54 @@
     ((default_generator)(generate_collisions))
 )
 
+#if !defined(BOOST_NO_0X_HDR_INITIALIZER_LIST)
+
+UNORDERED_AUTO_TEST(insert_initializer_list_set)
+{
+ boost::unordered_set<int> set;
+ set.insert({1,2,3,1});
+ BOOST_TEST_EQ(set.size(), 3u);
+ BOOST_TEST(set.find(1) != set.end());
+ BOOST_TEST(set.find(4) == set.end());
+}
+
+UNORDERED_AUTO_TEST(insert_initializer_list_multiset)
+{
+ boost::unordered_multiset<std::string> multiset;
+ multiset.insert({});
+ BOOST_TEST(multiset.empty());
+ multiset.insert({"a"});
+ BOOST_TEST_EQ(multiset.size(), 1u);
+ BOOST_TEST(multiset.find("a") != multiset.end());
+ BOOST_TEST(multiset.find("b") == multiset.end());
+ multiset.insert({"a","b"});
+ BOOST_TEST(multiset.size() == 3);
+ BOOST_TEST_EQ(multiset.count("a"), 2u);
+ BOOST_TEST_EQ(multiset.count("b"), 1u);
+ BOOST_TEST_EQ(multiset.count("c"), 0u);
+}
+
+UNORDERED_AUTO_TEST(insert_initializer_list_map)
+{
+ boost::unordered_map<std::string, std::string> map;
+ map.insert({});
+ BOOST_TEST(map.empty());
+ map.insert({{"a", "b"},{"a", "b"},{"d", ""}});
+ BOOST_TEST_EQ(map.size(), 2u);
+}
+
+UNORDERED_AUTO_TEST(insert_initializer_list_multimap)
+{
+ boost::unordered_multimap<std::string, std::string> multimap;
+ multimap.insert({});
+ BOOST_TEST(multimap.empty());
+ multimap.insert({{"a", "b"},{"a", "b"},{"d", ""}});
+ BOOST_TEST_EQ(multimap.size(), 3u);
+ BOOST_TEST_EQ(multimap.count("a"), 2u);
+}
+
+#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