diff --git a/flow/IndexedSet.cpp b/flow/IndexedSet.cpp index 38eb24a5ec..71f01918c4 100644 --- a/flow/IndexedSet.cpp +++ b/flow/IndexedSet.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include "flow/TreeBenchmark.h" #include "flow/UnitTest.h" template @@ -204,17 +205,24 @@ TEST_CASE("/flow/IndexedSet/strings") { template struct IndexedSetHarness { using map = IndexedSet; + using const_result = typename map::const_iterator; using result = typename map::iterator; using key_type = K; map s; void insert(K const& k) { s.insert(K(k), 1); } + const_result find(K const& k) const { return s.find(k); } result find(K const& k) { return s.find(k); } + const_result not_found() const { return s.end(); } result not_found() { return s.end(); } + const_result begin() const { return s.begin(); } result begin() { return s.begin(); } + const_result end() const { return s.end(); } result end() { return s.end(); } + const_result lower_bound(K const& k) const { return s.lower_bound(k); } result lower_bound(K const& k) { return s.lower_bound(k); } + result upper_bound(K const& k) const { return s.upper_bound(k); } result upper_bound(K const& k) { return s.upper_bound(k); } void erase(K const& k) { s.erase(k); } }; @@ -494,4 +502,49 @@ TEST_CASE("/flow/IndexedSet/all numbers") { return Void(); } +TEST_CASE("/flow/IndexedSet/const_iterator") { + struct Key { + int key; + explicit Key(int key) : key(key) {} + }; + struct Metric { + int metric; + explicit Metric(int metric) : metric(metric) {} + }; + IndexedSet is; + for (int i = 0; i < 10; ++i) is.insert(i, 1); + static_assert(!std::is_const_v); + static_assert(!std::is_const_v); + static_assert(!std::is_const_v); + static_assert(!std::is_const_v); + static_assert(!std::is_const_v); + static_assert(!std::is_const_v); + static_assert(!std::is_const_v); + static_assert(!std::is_const_v); + static_assert(!std::is_const_v); + + const IndexedSet& cis = is; + static_assert(std::is_const_v>); + static_assert(std::is_const_v>); + static_assert(std::is_const_v>); + static_assert(std::is_const_v>); + static_assert(std::is_const_v>); + static_assert(std::is_const_v>); + static_assert(std::is_const_v>); + static_assert(std::is_const_v>); + static_assert(std::is_const_v>); + + for (auto& val : is) { + static_assert(!std::is_const_v>); + } + for (const auto& val : is) { + static_assert(std::is_const_v>); + } + for (auto& val : cis) { + static_assert(std::is_const_v>); + } + + return Void(); +} + void forceLinkIndexedSetTests() {}