diff --git a/doc/changes.qbk b/doc/changes.qbk index 2677caa4..204b427b 100644 --- a/doc/changes.qbk +++ b/doc/changes.qbk @@ -59,5 +59,7 @@ First official release. the allocator's `construct` method - once for the pointers and once for the value. It now constructs the node with a single call to construct and then constructs the value using in place construction. +* Add support for C++0x initializer lists where they're available (currently + only g++ 4.4 in C++0x mode). [endsect] diff --git a/include/boost/unordered/unordered_map.hpp b/include/boost/unordered/unordered_map.hpp index edbee93a..69e5522e 100644 --- a/include/boost/unordered/unordered_map.hpp +++ b/include/boost/unordered/unordered_map.hpp @@ -135,6 +135,24 @@ namespace boost #endif #endif +#if !defined(BOOST_NO_INITIALIZER_LISTS) + unordered_map(std::initializer_list 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 list) + { + base.data_.clear(); + base.insert_range(list.begin(), list.end()); + return *this; + } +#endif + private: BOOST_DEDUCED_TYPENAME implementation::iterator_base const& @@ -523,6 +541,24 @@ namespace boost #endif #endif +#if !defined(BOOST_NO_INITIALIZER_LISTS) + unordered_multimap(std::initializer_list 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 list) + { + base.data_.clear(); + base.insert_range(list.begin(), list.end()); + return *this; + } +#endif + private: diff --git a/include/boost/unordered/unordered_set.hpp b/include/boost/unordered/unordered_set.hpp index c8d0d1e1..8f39c87e 100644 --- a/include/boost/unordered/unordered_set.hpp +++ b/include/boost/unordered/unordered_set.hpp @@ -133,6 +133,24 @@ namespace boost #endif #endif +#if !defined(BOOST_NO_INITIALIZER_LISTS) + unordered_set(std::initializer_list 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 list) + { + base.data_.clear(); + base.insert_range(list.begin(), list.end()); + return *this; + } +#endif + private: BOOST_DEDUCED_TYPENAME implementation::iterator_base const& @@ -493,6 +511,24 @@ namespace boost #endif #endif +#if !defined(BOOST_NO_INITIALIZER_LISTS) + unordered_multiset(std::initializer_list 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 list) + { + base.data_.clear(); + base.insert_range(list.begin(), list.end()); + return *this; + } +#endif + private: BOOST_DEDUCED_TYPENAME implementation::iterator_base const& diff --git a/test/unordered/assign_tests.cpp b/test/unordered/assign_tests.cpp index bb8daff8..76d81ec5 100644 --- a/test/unordered/assign_tests.cpp +++ b/test/unordered/assign_tests.cpp @@ -103,6 +103,22 @@ UNORDERED_TEST(assign_tests2, ((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 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() diff --git a/test/unordered/constructor_tests.cpp b/test/unordered/constructor_tests.cpp index bdf5cd10..a56f7905 100644 --- a/test/unordered/constructor_tests.cpp +++ b/test/unordered/constructor_tests.cpp @@ -288,6 +288,17 @@ UNORDERED_TEST(map_constructor_test, ((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 x1 = { 2, 10, 45, -5 }; + BOOST_CHECK(x1.find(10) != x1.end()); + BOOST_CHECK(x1.find(46) == x1.end()); +} + +#endif + } RUN_TESTS()