summaryrefslogtreecommitdiff
path: root/libs/multi_index/test/test_set_ops.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'libs/multi_index/test/test_set_ops.cpp')
-rw-r--r--libs/multi_index/test/test_set_ops.cpp71
1 files changed, 70 insertions, 1 deletions
diff --git a/libs/multi_index/test/test_set_ops.cpp b/libs/multi_index/test/test_set_ops.cpp
index 0057ab41c..0e9a70da8 100644
--- a/libs/multi_index/test/test_set_ops.cpp
+++ b/libs/multi_index/test/test_set_ops.cpp
@@ -1,6 +1,6 @@
/* Boost.MultiIndex test for standard set operations.
*
- * Copyright 2003-2013 Joaquin M Lopez Munoz.
+ * Copyright 2003-2014 Joaquin M Lopez Munoz.
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
@@ -19,6 +19,41 @@
using namespace boost::multi_index;
+struct type1{};
+
+struct type2
+{
+private:
+ operator type1()const{return type1();}
+};
+
+struct type3
+{
+ operator type1()const{return type1();}
+};
+
+struct less_type12
+{
+ bool operator()(type1,type1)const{return false;}
+ bool operator()(type1,type2)const{return false;}
+ bool operator()(type2,type1)const{return false;}
+};
+
+bool less_type1_f(type1,type1){return false;}
+
+struct hash_type12
+{
+ std::size_t operator()(type1)const{return 0;}
+ std::size_t operator()(type2)const{return 0;}
+};
+
+struct eq_type12
+{
+ bool operator()(type1,type1)const{return true;}
+ bool operator()(type1,type2)const{return true;}
+ bool operator()(type2,type1)const{return true;}
+};
+
void test_set_ops()
{
employee_set es;
@@ -55,4 +90,38 @@ void test_set_ops()
std::pair<employee_set_by_age::iterator,employee_set_by_age::iterator> p2=
i2.equal_range(30);
BOOST_TEST(p2.first==p2.second&&p2.first->age==31);
+
+ /* check promotion detection plays nice with private conversion */
+
+ multi_index_container<
+ type1,
+ indexed_by<
+ ordered_unique<identity<type1>,less_type12>,
+ hashed_unique<identity<type1>,hash_type12,eq_type12>
+ >
+ > c;
+ c.insert(type1());
+
+ BOOST_TEST(c.find(type2())==c.begin());
+ BOOST_TEST(c.count(type2())==1);
+ BOOST_TEST(c.lower_bound(type2())==c.begin());
+ BOOST_TEST(c.upper_bound(type2())==c.end());
+ BOOST_TEST(c.equal_range(type2())==std::make_pair(c.begin(),c.end()));
+
+ BOOST_TEST(c.get<1>().find(type2())==c.get<1>().begin());
+ BOOST_TEST(c.get<1>().count(type2())==1);
+ BOOST_TEST(c.get<1>().equal_range(type2())==
+ std::make_pair(c.get<1>().begin(),c.get<1>().end()));
+
+ /* check promotion detection does not break with functions */
+
+ multi_index_container<
+ type1,
+ indexed_by<
+ ordered_unique<identity<type1>,bool(*)(type1,type1)>
+ >
+ > c2(boost::make_tuple(boost::make_tuple(identity<type1>(),&less_type1_f)));
+ c2.insert(type1());
+
+ BOOST_TEST(c2.find(type3())==c2.begin());
}