From 1aa15ead3513bd72deaac26d79240abe6ab62686 Mon Sep 17 00:00:00 2001 From: Jan Eisenhauer <44572464+JanEisenhauer@users.noreply.github.com> Date: Tue, 11 Jun 2019 10:23:13 +0200 Subject: [PATCH] Add testcases for heterogeneous lookup with partial keys. --- test/flat_map_test.cpp | 35 +++++++++++++++++++++++++++++++++++ test/flat_set_test.cpp | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) diff --git a/test/flat_map_test.cpp b/test/flat_map_test.cpp index 9497ee2..ca4ce1a 100644 --- a/test/flat_map_test.cpp +++ b/test/flat_map_test.cpp @@ -22,6 +22,7 @@ #include "../../intrusive/test/iterator_test.hpp" #include +#include 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 a, std::pair b) const + { + return a < b; + } + inline bool operator()(std::pair a, int first) const + { + return a.first < first; + } + inline bool operator()(int first, std::pair b) const + { + return first < b.first; + } +}; + +bool test_heterogeneous_lookup_by_partial_key() +{ + flat_set, 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 //////////////////////////////////// diff --git a/test/flat_set_test.cpp b/test/flat_set_test.cpp index 7e561f7..0215a69 100644 --- a/test/flat_set_test.cpp +++ b/test/flat_set_test.cpp @@ -11,6 +11,7 @@ #include #include +#include #include #include @@ -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 a, std::pair b) const + { + return a < b; + } + inline bool operator()(std::pair a, int first) const + { + return a.first < first; + } + inline bool operator()(int first, std::pair b) const + { + return first < b.first; + } +}; + +bool test_heterogeneous_lookup_by_partial_key() +{ + flat_set, 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 @@ -715,6 +747,10 @@ int main() return 1; } + if(!test_heterogeneous_lookup_by_partial_key()){ + return 1; + } + //////////////////////////////////// // Testing allocator implementations ////////////////////////////////////