1 //===-- STLUtils.h ----------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_STLUtils_h_
11 #define liblldb_STLUtils_h_
21 // Other libraries and framework includes
24 //----------------------------------------------------------------------
25 // C string less than compare function object
26 //----------------------------------------------------------------------
27 struct CStringCompareFunctionObject {
28 bool operator()(const char *s1, const char *s2) const {
29 return strcmp(s1, s2) < 0;
33 //----------------------------------------------------------------------
34 // C string equality function object (binary predicate).
35 //----------------------------------------------------------------------
36 struct CStringEqualBinaryPredicate {
37 bool operator()(const char *s1, const char *s2) const {
38 return strcmp(s1, s2) == 0;
42 //----------------------------------------------------------------------
43 // Templated type for finding an entry in a std::map<F,S> whose value
44 // is equal to something
45 //----------------------------------------------------------------------
46 template <class F, class S> class ValueEquals {
48 ValueEquals(const S &val) : second_value(val) {}
50 // Compare the second item
51 bool operator()(std::pair<const F, S> elem) {
52 return elem.second == second_value;
60 inline void PrintAllCollectionElements(std::ostream &s, const T &coll,
61 const char *header_cstr = nullptr,
62 const char *separator_cstr = " ") {
63 typename T::const_iterator pos;
67 for (pos = coll.begin(); pos != coll.end(); ++pos) {
68 s << *pos << separator_cstr;
73 // The function object below can be used to delete a STL container that
74 // contains C++ object pointers.
76 // Usage: std::for_each(vector.begin(), vector.end(), for_each_delete());
78 struct for_each_cplusplus_delete {
79 template <typename T> void operator()(T *ptr) { delete ptr; }
82 typedef std::vector<std::string> STLStringArray;
83 typedef std::vector<const char *> CStringArray;
85 #endif // liblldb_STLUtils_h_