Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:44:37

0001 //===- llvm/Testing/ADT/StringMap.h ---------------------------------------===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLVM_TESTING_ADT_STRINGMAP_H_
0010 #define LLVM_TESTING_ADT_STRINGMAP_H_
0011 
0012 #include "llvm/ADT/STLExtras.h"
0013 #include "llvm/ADT/StringMap.h"
0014 #include "llvm/Support/FormatVariadic.h"
0015 #include "llvm/Testing/ADT/StringMapEntry.h"
0016 #include <ostream>
0017 #include <sstream>
0018 
0019 namespace llvm {
0020 
0021 /// Support for printing to std::ostream, for use with e.g. producing more
0022 /// useful error messages with Google Test.
0023 template <typename T>
0024 std::ostream &operator<<(std::ostream &OS, const StringMap<T> &M) {
0025   if (M.empty()) {
0026     return OS << "{ }";
0027   }
0028 
0029   std::vector<std::string> Lines;
0030   for (const auto &E : M) {
0031     std::ostringstream SS;
0032     SS << E << ",";
0033     Lines.push_back(SS.str());
0034   }
0035   llvm::sort(Lines);
0036   Lines.insert(Lines.begin(), "{");
0037   Lines.insert(Lines.end(), "}");
0038 
0039   return OS << llvm::formatv("{0:$[\n]}",
0040                              make_range(Lines.begin(), Lines.end()))
0041                    .str();
0042 }
0043 
0044 } // namespace llvm
0045 
0046 #endif