From 15a326c525023bc9170dc2f68c2d156386a48190 Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Mon, 16 Nov 2015 22:18:36 +0000 Subject: [PATCH] More tests for LWG#2156 git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@253257 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../containers/unord/unord.map/reserve.pass.cpp | 16 ++++++++++++++++ .../unord/unord.multimap/reserve.pass.cpp | 16 ++++++++++++++++ .../unord/unord.multiset/reserve.pass.cpp | 16 ++++++++++++++++ .../containers/unord/unord.set/reserve.pass.cpp | 16 ++++++++++++++++ 4 files changed, 64 insertions(+) diff --git a/test/std/containers/unord/unord.map/reserve.pass.cpp b/test/std/containers/unord/unord.map/reserve.pass.cpp index 48667cdc..bef237f9 100644 --- a/test/std/containers/unord/unord.map/reserve.pass.cpp +++ b/test/std/containers/unord/unord.map/reserve.pass.cpp @@ -31,6 +31,21 @@ void test(const C& c) assert(c.at(4) == "four"); } +void reserve_invariant(size_t n) // LWG #2156 +{ + for (size_t i = 0; i < n; ++i) + { + std::unordered_map c; + c.reserve(n); + size_t buckets = c.bucket_count(); + for (size_t j = 0; j < i; ++j) + { + c[i] = i; + assert(buckets == c.bucket_count()); + } + } +} + int main() { { @@ -88,4 +103,5 @@ int main() test(c); } #endif + reserve_invariant(20); } diff --git a/test/std/containers/unord/unord.multimap/reserve.pass.cpp b/test/std/containers/unord/unord.multimap/reserve.pass.cpp index 801c7445..5e7daf22 100644 --- a/test/std/containers/unord/unord.multimap/reserve.pass.cpp +++ b/test/std/containers/unord/unord.multimap/reserve.pass.cpp @@ -33,6 +33,21 @@ void test(const C& c) assert(c.find(4)->second == "four"); } +void reserve_invariant(size_t n) // LWG #2156 +{ + for (size_t i = 0; i < n; ++i) + { + std::unordered_multimap c; + c.reserve(n); + size_t buckets = c.bucket_count(); + for (size_t j = 0; j < i; ++j) + { + c[i] = i; + assert(buckets == c.bucket_count()); + } + } +} + int main() { { @@ -90,4 +105,5 @@ int main() test(c); } #endif + reserve_invariant(20); } diff --git a/test/std/containers/unord/unord.multiset/reserve.pass.cpp b/test/std/containers/unord/unord.multiset/reserve.pass.cpp index 0c17583d..1d393a09 100644 --- a/test/std/containers/unord/unord.multiset/reserve.pass.cpp +++ b/test/std/containers/unord/unord.multiset/reserve.pass.cpp @@ -30,6 +30,21 @@ void test(const C& c) assert(c.count(4) == 1); } +void reserve_invariant(size_t n) // LWG #2156 +{ + for (size_t i = 0; i < n; ++i) + { + std::unordered_multiset c; + c.reserve(n); + size_t buckets = c.bucket_count(); + for (size_t j = 0; j < i; ++j) + { + c.insert(i); + assert(buckets == c.bucket_count()); + } + } +} + int main() { { @@ -87,4 +102,5 @@ int main() test(c); } #endif + reserve_invariant(20); } diff --git a/test/std/containers/unord/unord.set/reserve.pass.cpp b/test/std/containers/unord/unord.set/reserve.pass.cpp index 7d6656a1..078b886b 100644 --- a/test/std/containers/unord/unord.set/reserve.pass.cpp +++ b/test/std/containers/unord/unord.set/reserve.pass.cpp @@ -30,6 +30,21 @@ void test(const C& c) assert(c.count(4) == 1); } +void reserve_invariant(size_t n) // LWG #2156 +{ + for (size_t i = 0; i < n; ++i) + { + std::unordered_set c; + c.reserve(n); + size_t buckets = c.bucket_count(); + for (size_t j = 0; j < i; ++j) + { + c.insert(i); + assert(buckets == c.bucket_count()); + } + } +} + int main() { { @@ -87,4 +102,5 @@ int main() test(c); } #endif + reserve_invariant(20); }