mirror of
https://github.com/boostorg/container.git
synced 2025-08-02 05:54:28 +02:00
Add testcases for heterogeneous lookup with partial keys.
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
#include "../../intrusive/test/iterator_test.hpp"
|
||||
|
||||
#include <map>
|
||||
#include <utility>
|
||||
|
||||
|
||||
using namespace boost::container;
|
||||
@@ -557,6 +558,37 @@ bool test_heterogeneous_lookups()
|
||||
return true;
|
||||
}
|
||||
|
||||
// An ordered sequence of std:pair is also ordered by std::pair::first.
|
||||
struct with_lookup_by_first
|
||||
{
|
||||
typedef void is_transparent;
|
||||
inline bool operator()(std::pair<int, int> a, std::pair<int, int> b) const
|
||||
{
|
||||
return a < b;
|
||||
}
|
||||
inline bool operator()(std::pair<int, int> a, int first) const
|
||||
{
|
||||
return a.first < first;
|
||||
}
|
||||
inline bool operator()(int first, std::pair<int, int> b) const
|
||||
{
|
||||
return first < b.first;
|
||||
}
|
||||
};
|
||||
|
||||
bool test_heterogeneous_lookup_by_partial_key()
|
||||
{
|
||||
flat_set<std::pair<int, int>, with_lookup_by_first> const set1
|
||||
{
|
||||
{{0, 1}, 3},
|
||||
{{0, 2}, 3},
|
||||
};
|
||||
|
||||
auto const first_0_range = uut.equal_range(0);
|
||||
|
||||
return 2 == first_0_range.second - first_0_range.first;
|
||||
}
|
||||
|
||||
}}} //namespace boost::container::test
|
||||
|
||||
int main()
|
||||
@@ -617,6 +649,9 @@ int main()
|
||||
if (!test_heterogeneous_lookups())
|
||||
return 1;
|
||||
|
||||
if (!test_heterogeneous_lookup_by_partial_key())
|
||||
return 1;
|
||||
|
||||
////////////////////////////////////
|
||||
// Testing allocator implementations
|
||||
////////////////////////////////////
|
||||
|
@@ -11,6 +11,7 @@
|
||||
#include <boost/container/detail/config_begin.hpp>
|
||||
|
||||
#include <set>
|
||||
#include <utility>
|
||||
|
||||
#include <boost/container/flat_set.hpp>
|
||||
#include <boost/container/detail/container_or_allocator_rebind.hpp>
|
||||
@@ -574,6 +575,37 @@ bool test_heterogeneous_lookups()
|
||||
return true;
|
||||
}
|
||||
|
||||
// An ordered sequence of std:pair is also ordered by std::pair::first.
|
||||
struct with_lookup_by_first
|
||||
{
|
||||
typedef void is_transparent;
|
||||
inline bool operator()(std::pair<int, int> a, std::pair<int, int> b) const
|
||||
{
|
||||
return a < b;
|
||||
}
|
||||
inline bool operator()(std::pair<int, int> a, int first) const
|
||||
{
|
||||
return a.first < first;
|
||||
}
|
||||
inline bool operator()(int first, std::pair<int, int> b) const
|
||||
{
|
||||
return first < b.first;
|
||||
}
|
||||
};
|
||||
|
||||
bool test_heterogeneous_lookup_by_partial_key()
|
||||
{
|
||||
flat_set<std::pair<int, int>, with_lookup_by_first> const set1
|
||||
{
|
||||
{0, 1},
|
||||
{0, 2},
|
||||
};
|
||||
|
||||
auto const first_0_range = uut.equal_range(0);
|
||||
|
||||
return 2 == first_0_range.second - first_0_range.first;
|
||||
}
|
||||
|
||||
}}}
|
||||
|
||||
template<class VoidAllocatorOrContainer>
|
||||
@@ -715,6 +747,10 @@ int main()
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(!test_heterogeneous_lookup_by_partial_key()){
|
||||
return 1;
|
||||
}
|
||||
|
||||
////////////////////////////////////
|
||||
// Testing allocator implementations
|
||||
////////////////////////////////////
|
||||
|
Reference in New Issue
Block a user