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_
20 //----------------------------------------------------------------------
21 // C string less than compare function object
22 //----------------------------------------------------------------------
23 struct CStringCompareFunctionObject {
24 bool operator()(const char *s1, const char *s2) const {
25 return strcmp(s1, s2) < 0;
29 //----------------------------------------------------------------------
30 // C string equality function object (binary predicate).
31 //----------------------------------------------------------------------
32 struct CStringEqualBinaryPredicate {
33 bool operator()(const char *s1, const char *s2) const {
34 return strcmp(s1, s2) == 0;
38 //----------------------------------------------------------------------
39 // Templated type for finding an entry in a std::map<F,S> whose value is equal
41 //----------------------------------------------------------------------
42 template <class F, class S> class ValueEquals {
44 ValueEquals(const S &val) : second_value(val) {}
46 // Compare the second item
47 bool operator()(std::pair<const F, S> elem) {
48 return elem.second == second_value;
56 inline void PrintAllCollectionElements(std::ostream &s, const T &coll,
57 const char *header_cstr = nullptr,
58 const char *separator_cstr = " ") {
59 typename T::const_iterator pos;
63 for (pos = coll.begin(); pos != coll.end(); ++pos) {
64 s << *pos << separator_cstr;
69 // The function object below can be used to delete a STL container that
70 // contains C++ object pointers.
72 // Usage: std::for_each(vector.begin(), vector.end(), for_each_delete());
74 struct for_each_cplusplus_delete {
75 template <typename T> void operator()(T *ptr) { delete ptr; }
78 typedef std::vector<std::string> STLStringArray;
79 typedef std::vector<const char *> CStringArray;
81 #endif // liblldb_STLUtils_h_