|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r86419 - in trunk: boost/unordered libs/unordered/test/unordered
From: dnljms_at_[hidden]
Date: 2013-10-24 14:11:35
Author: danieljames
Date: 2013-10-24 14:11:35 EDT (Thu, 24 Oct 2013)
New Revision: 86419
URL: http://svn.boost.org/trac/boost/changeset/86419
Log:
Attempt to work around Visual C++ initializer list overload bug.
I'm hoping that these templated initializer lists will be considered a better
overload than the others. I have no idea if it will actually work, this is a
real shot in the dark.
The enable_if checks should probably be for implicit conversion, there might
be a chance this could override a valid call when there's an explicit
conversion.
Text files modified:
trunk/boost/unordered/unordered_map.hpp | 24 ++++++++++++++++++++++++
trunk/boost/unordered/unordered_set.hpp | 24 ++++++++++++++++++++++++
trunk/libs/unordered/test/unordered/insert_tests.cpp | 39 +++++++++++++++++++++++++++++++++++++++
3 files changed, 87 insertions(+), 0 deletions(-)
Modified: trunk/boost/unordered/unordered_map.hpp
==============================================================================
--- trunk/boost/unordered/unordered_map.hpp Thu Oct 24 13:19:47 2013 (r86418)
+++ trunk/boost/unordered/unordered_map.hpp 2013-10-24 14:11:35 EDT (Thu, 24 Oct 2013) (r86419)
@@ -22,6 +22,10 @@
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
#include <initializer_list>
+
+#if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1800))
+#include <boost/type_traits/is_convertible.hpp>
+#endif
#endif
#if defined(BOOST_MSVC)
@@ -403,6 +407,16 @@
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
void insert(std::initializer_list<value_type>);
+
+#if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1800))
+ template <typename T>
+ typename boost::enable_if_c<
+ boost::is_convertible<T, value_type>::value,
+ void>::type insert(std::initializer_list<T> list)
+ {
+ table_.insert_range(list.begin(), list.end());
+ }
+#endif
#endif
iterator erase(const_iterator);
@@ -887,6 +901,16 @@
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
void insert(std::initializer_list<value_type>);
+
+#if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1800))
+ template <typename T>
+ typename boost::enable_if_c<
+ boost::is_convertible<T, value_type>::value,
+ void>::type insert(std::initializer_list<T> list)
+ {
+ table_.insert_range(list.begin(), list.end());
+ }
+#endif
#endif
iterator erase(const_iterator);
Modified: trunk/boost/unordered/unordered_set.hpp
==============================================================================
--- trunk/boost/unordered/unordered_set.hpp Thu Oct 24 13:19:47 2013 (r86418)
+++ trunk/boost/unordered/unordered_set.hpp 2013-10-24 14:11:35 EDT (Thu, 24 Oct 2013) (r86419)
@@ -22,6 +22,10 @@
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
#include <initializer_list>
+
+#if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1800))
+#include <boost/type_traits/is_convertible.hpp>
+#endif
#endif
#if defined(BOOST_MSVC)
@@ -402,6 +406,16 @@
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
void insert(std::initializer_list<value_type>);
+
+#if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1800))
+ template <typename T>
+ typename boost::enable_if_c<
+ boost::is_convertible<T, value_type>::value,
+ void>::type insert(std::initializer_list<T> list)
+ {
+ table_.insert_range(list.begin(), list.end());
+ }
+#endif
#endif
iterator erase(const_iterator);
@@ -872,6 +886,16 @@
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
void insert(std::initializer_list<value_type>);
+
+#if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1800))
+ template <typename T>
+ typename boost::enable_if_c<
+ boost::is_convertible<T, value_type>::value,
+ void>::type insert(std::initializer_list<T> list)
+ {
+ table_.insert_range(list.begin(), list.end());
+ }
+#endif
#endif
iterator erase(const_iterator);
Modified: trunk/libs/unordered/test/unordered/insert_tests.cpp
==============================================================================
--- trunk/libs/unordered/test/unordered/insert_tests.cpp Thu Oct 24 13:19:47 2013 (r86418)
+++ trunk/libs/unordered/test/unordered/insert_tests.cpp 2013-10-24 14:11:35 EDT (Thu, 24 Oct 2013) (r86419)
@@ -576,6 +576,21 @@
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
+struct initialize_from_two_ints
+{
+ int a, b;
+
+ friend std::size_t hash_value(initialize_from_two_ints const& x)
+ {
+ return a + b;
+ }
+
+ bool operator==(initialize_from_two_ints const& x)
+ {
+ return a == x.a && b == x.b;
+ }
+};
+
UNORDERED_AUTO_TEST(insert_initializer_list_set)
{
boost::unordered_set<int> set;
@@ -583,6 +598,30 @@
BOOST_TEST_EQ(set.size(), 3u);
BOOST_TEST(set.find(1) != set.end());
BOOST_TEST(set.find(4) == set.end());
+
+ boost::unordered_set<initialize_from_two_ints> set2;
+
+ set2.insert({1, 2});
+ BOOST_TEST(set2.size() == 1);
+ BOOST_TEST(set2.find({1,2}) != set2.end());
+ BOOST_TEST(set2.find({2,1}) != set2.end());
+
+ set2.insert({{3,4},{5,6},{7,8}});
+ BOOST_TEST(set2.size() == 4);
+ BOOST_TEST(set2.find({1,2}) != set2.end());
+ BOOST_TEST(set2.find({3,4}) != set2.end());
+ BOOST_TEST(set2.find({5,6}) != set2.end());
+ BOOST_TEST(set2.find({7,8}) != set2.end());
+ BOOST_TEST(set2.find({8,7}) != set2.end());
+
+ set2.insert({{2, 1}, {3,4}});
+ BOOST_TEST(set2.size() == 5);
+ BOOST_TEST(set2.find({1,2}) != set2.end());
+ BOOST_TEST(set2.find({2,1}) != set2.end());
+ BOOST_TEST(set2.find({3,4}) != set2.end());
+ BOOST_TEST(set2.find({5,6}) != set2.end());
+ BOOST_TEST(set2.find({7,8}) != set2.end());
+ BOOST_TEST(set2.find({8,7}) != set2.end());
}
UNORDERED_AUTO_TEST(insert_initializer_list_multiset)
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