CBMC
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
container_utils.h
Go to the documentation of this file.
1/*******************************************************************\
2
3Module: Container utilities
4
5Author: Diffblue Ltd.
6
7\*******************************************************************/
8
9#ifndef CPROVER_UTIL_CONTAINER_UTILS_H
10#define CPROVER_UTIL_CONTAINER_UTILS_H
11
12#include <set>
13
27template <class T, class Compare, class Alloc>
29 std::set<T, Compare, Alloc> &target,
30 const std::set<T, Compare, Alloc> &source)
31{
32 bool changed = false;
33 typename std::set<T, Compare, Alloc>::iterator it = target.begin();
34
35 for(const auto &s : source)
36 {
37 while(it != target.end() && Compare()(*it, s))
38 {
39 ++it;
40 }
41
42 if(it == target.end() || Compare()(s, *it))
43 {
44 // Insertion hint should point at element that will follow the new element
45 target.insert(it, s);
46 changed = true;
47 }
48 else if(it != target.end())
49 {
50 ++it;
51 }
52 }
53
54 return changed;
55}
56
57#endif // CPROVER_UTIL_CONTAINER_UTILS_H
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition ai.h:562
bool util_inplace_set_union(std::set< T, Compare, Alloc > &target, const std::set< T, Compare, Alloc > &source)
Compute union of two sets.