forked from boostorg/container
* Implemented C++20 contains() for associative containers as specified in P0458R2.
* Fixed serious bug in heterogeneous lookup functions (is_transparent was broken).
This commit is contained in:
+12
-1
@@ -454,6 +454,8 @@ struct get_real_stored_allocator<flat_multimap<Key, T, Compare, Allocator> >
|
||||
|
||||
bool test_heterogeneous_lookups()
|
||||
{
|
||||
BOOST_STATIC_ASSERT((dtl::is_transparent<less_transparent>::value));
|
||||
BOOST_STATIC_ASSERT(!(dtl::is_transparent<std::less<int> >::value));
|
||||
typedef flat_map<int, char, less_transparent> map_t;
|
||||
typedef flat_multimap<int, char, less_transparent> mmap_t;
|
||||
typedef map_t::value_type value_type;
|
||||
@@ -498,6 +500,16 @@ bool test_heterogeneous_lookups()
|
||||
if(cmmap1.count(find_me) != 2)
|
||||
return false;
|
||||
|
||||
//contains
|
||||
if(!map1.contains(find_me))
|
||||
return false;
|
||||
if(!cmap1.contains(find_me))
|
||||
return false;
|
||||
if(!mmap1.contains(find_me))
|
||||
return false;
|
||||
if(!cmmap1.contains(find_me))
|
||||
return false;
|
||||
|
||||
//lower_bound
|
||||
if(map1.lower_bound(find_me)->second != 'd')
|
||||
return false;
|
||||
@@ -709,4 +721,3 @@ int main()
|
||||
}
|
||||
|
||||
#include <boost/container/detail/config_end.hpp>
|
||||
|
||||
|
||||
@@ -495,6 +495,16 @@ bool test_heterogeneous_lookups()
|
||||
if(cmset1.count(find_me) != 2)
|
||||
return false;
|
||||
|
||||
//contains
|
||||
if(!set1.contains(find_me))
|
||||
return false;
|
||||
if(!cset1.contains(find_me))
|
||||
return false;
|
||||
if(!mset1.contains(find_me))
|
||||
return false;
|
||||
if(!cmset1.contains(find_me))
|
||||
return false;
|
||||
|
||||
//lower_bound
|
||||
if(*set1.lower_bound(find_me) != 2)
|
||||
return false;
|
||||
|
||||
@@ -366,6 +366,16 @@ bool test_heterogeneous_lookups()
|
||||
if(cmmap1.count(find_me) != 2)
|
||||
return false;
|
||||
|
||||
//contains
|
||||
if(!map1.contains(find_me))
|
||||
return false;
|
||||
if(!cmap1.contains(find_me))
|
||||
return false;
|
||||
if(!mmap1.contains(find_me))
|
||||
return false;
|
||||
if(!cmmap1.contains(find_me))
|
||||
return false;
|
||||
|
||||
//lower_bound
|
||||
if(map1.lower_bound(find_me)->second != 'd')
|
||||
return false;
|
||||
|
||||
+9
-1
@@ -628,16 +628,24 @@ int map_test()
|
||||
}
|
||||
}
|
||||
|
||||
//Compare count with std containers
|
||||
//Compare count/contains with std containers
|
||||
for(int i = 0; i < MaxElem; ++i){
|
||||
IntType k(i);
|
||||
if(boostmap.count(k) != stdmap.count(i)){
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(boostmap.contains(k) != (stdmap.find(i) != stdmap.end())){
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(boostmultimap.count(k) != stdmultimap.count(i)){
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(boostmultimap.contains(k) != (stdmultimap.find(i) != stdmultimap.end())){
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
//Now do count exercise
|
||||
|
||||
@@ -363,6 +363,16 @@ bool test_heterogeneous_lookups()
|
||||
if(cmset1.count(find_me) != 2)
|
||||
return false;
|
||||
|
||||
//contains
|
||||
if(!set1.contains(find_me))
|
||||
return false;
|
||||
if(!cset1.contains(find_me))
|
||||
return false;
|
||||
if(!mset1.contains(find_me))
|
||||
return false;
|
||||
if(!cmset1.contains(find_me))
|
||||
return false;
|
||||
|
||||
//lower_bound
|
||||
if(*set1.lower_bound(find_me) != 2)
|
||||
return false;
|
||||
|
||||
+12
-3
@@ -580,11 +580,20 @@ int set_test ()
|
||||
|
||||
//Compare count with std containers
|
||||
for(int i = 0; i < MaxElem; ++i){
|
||||
IntType count_me(i);
|
||||
if(boostset.count(count_me) != stdset.count(i)){
|
||||
IntType k(i);
|
||||
if(boostset.count(k) != stdset.count(i)){
|
||||
return -1;
|
||||
}
|
||||
if(boostmultiset.count(count_me) != stdmultiset.count(i)){
|
||||
|
||||
if(boostset.contains(k) != (stdset.find(i) != stdset.end())){
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(boostmultiset.count(k) != stdmultiset.count(i)){
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(boostmultiset.contains(k) != (stdmultiset.find(i) != stdmultiset.end())){
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user