1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef CHECK_CONSECUTIVE_H
10 #define CHECK_CONSECUTIVE_H
11
12 // <unordered_multiset>
13 // <unordered_multimap>
14
15 #include <cassert>
16 #include <set>
17 #include <stddef.h>
18
19 // Check consecutive equal values in an unordered_multiset iterator
20 template <typename Iter>
CheckConsecutiveValues(Iter pos,Iter end,typename Iter::value_type value,std::size_t count)21 void CheckConsecutiveValues(Iter pos, Iter end, typename Iter::value_type value, std::size_t count)
22 {
23 for ( std::size_t i = 0; i < count; ++i )
24 {
25 assert(pos != end);
26 assert(*pos == value);
27 ++pos;
28 }
29 assert(pos == end || *pos != value);
30 }
31
32 // Check consecutive equal keys in an unordered_multimap iterator
33 template <typename Iter>
CheckConsecutiveKeys(Iter pos,Iter end,typename Iter::value_type::first_type key,std::multiset<typename Iter::value_type::second_type> & values)34 void CheckConsecutiveKeys(Iter pos, Iter end, typename Iter::value_type::first_type key, std::multiset<typename Iter::value_type::second_type>& values)
35 {
36 while (!values.empty())
37 {
38 assert(pos != end);
39 assert(pos->first == key);
40 assert(values.find(pos->second) != values.end());
41 values.erase(values.find(pos->second));
42 ++pos;
43 }
44 assert(pos == end || pos->first != key);
45 }
46
47 #endif
48