1 //===-- STLUtils.h ----------------------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef liblldb_STLUtils_h_
10 #define liblldb_STLUtils_h_
19 // C string less than compare function object
20 struct CStringCompareFunctionObject {
21 bool operator()(const char *s1, const char *s2) const {
22 return strcmp(s1, s2) < 0;
26 // C string equality function object (binary predicate).
27 struct CStringEqualBinaryPredicate {
28 bool operator()(const char *s1, const char *s2) const {
29 return strcmp(s1, s2) == 0;
33 // Templated type for finding an entry in a std::map<F,S> whose value is equal
35 template <class F, class S> class ValueEquals {
37 ValueEquals(const S &val) : second_value(val) {}
39 // Compare the second item
40 bool operator()(std::pair<const F, S> elem) {
41 return elem.second == second_value;
49 inline void PrintAllCollectionElements(std::ostream &s, const T &coll,
50 const char *header_cstr = nullptr,
51 const char *separator_cstr = " ") {
52 typename T::const_iterator pos;
56 for (pos = coll.begin(); pos != coll.end(); ++pos) {
57 s << *pos << separator_cstr;
62 // The function object below can be used to delete a STL container that
63 // contains C++ object pointers.
65 // Usage: std::for_each(vector.begin(), vector.end(), for_each_delete());
67 struct for_each_cplusplus_delete {
68 template <typename T> void operator()(T *ptr) { delete ptr; }
71 typedef std::vector<std::string> STLStringArray;
72 typedef std::vector<const char *> CStringArray;
74 #endif // liblldb_STLUtils_h_