1 | //===- llvm/Testing/ADT/StringMap.h ---------------------------------------===// |
---|---|
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-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | #ifndef LLVM_TESTING_ADT_STRINGMAP_H_ |
10 | #define LLVM_TESTING_ADT_STRINGMAP_H_ |
11 | |
12 | #include "llvm/ADT/STLExtras.h" |
13 | #include "llvm/ADT/StringMap.h" |
14 | #include "llvm/Support/FormatVariadic.h" |
15 | #include "llvm/Testing/ADT/StringMapEntry.h" |
16 | #include <ostream> |
17 | #include <sstream> |
18 | |
19 | namespace llvm { |
20 | |
21 | /// Support for printing to std::ostream, for use with e.g. producing more |
22 | /// useful error messages with Google Test. |
23 | template <typename T> |
24 | std::ostream &operator<<(std::ostream &OS, const StringMap<T> &M) { |
25 | if (M.empty()) { |
26 | return OS << "{ }"; |
27 | } |
28 | |
29 | std::vector<std::string> Lines; |
30 | for (const auto &E : M) { |
31 | std::ostringstream SS; |
32 | SS << E << ","; |
33 | Lines.push_back(x: SS.str()); |
34 | } |
35 | llvm::sort(C&: Lines); |
36 | Lines.insert(position: Lines.begin(), x: "{"); |
37 | Lines.insert(position: Lines.end(), x: "}"); |
38 | |
39 | return OS << llvm::formatv(Fmt: "{0:$[\n]}", |
40 | Vals: make_range(x: Lines.begin(), y: Lines.end())) |
41 | .str(); |
42 | } |
43 | |
44 | } // namespace llvm |
45 | |
46 | #endif |
47 |