47 lines · c
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-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef CHECK_CONSECUTIVE_H10#define CHECK_CONSECUTIVE_H11 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 iterator20template <typename Iter>21void CheckConsecutiveValues(Iter pos, Iter end, typename Iter::value_type value, std::size_t count) {22 for (std::size_t i = 0; i < count; ++i) {23 assert(pos != end);24 assert(*pos == value);25 ++pos;26 }27 assert(pos == end || *pos != value);28}29 30// Check consecutive equal keys in an unordered_multimap iterator31template <typename Iter>32void CheckConsecutiveKeys(Iter pos,33 Iter end,34 typename Iter::value_type::first_type key,35 std::multiset<typename Iter::value_type::second_type>& values) {36 while (!values.empty()) {37 assert(pos != end);38 assert(pos->first == key);39 assert(values.find(pos->second) != values.end());40 values.erase(values.find(pos->second));41 ++pos;42 }43 assert(pos == end || pos->first != key);44}45 46#endif47