mirror of
https://github.com/boostorg/unordered.git
synced 2025-07-29 10:57:16 +02:00
Add support for initializer lists to config and the unordered containers.
[SVN r50118]
This commit is contained in:
@ -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]
|
||||
|
@ -135,6 +135,24 @@ namespace boost
|
||||
#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&
|
||||
@ -523,6 +541,24 @@ namespace boost
|
||||
#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:
|
||||
|
||||
|
@ -133,6 +133,24 @@ namespace boost
|
||||
#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&
|
||||
@ -493,6 +511,24 @@ namespace boost
|
||||
#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&
|
||||
|
@ -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<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()
|
||||
|
@ -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<int> x1 = { 2, 10, 45, -5 };
|
||||
BOOST_CHECK(x1.find(10) != x1.end());
|
||||
BOOST_CHECK(x1.find(46) == x1.end());
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
RUN_TESTS()
|
||||
|
Reference in New Issue
Block a user