StringMap.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- llvm/Testing/ADT/StringMap.h ---------------------------------------===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_TESTING_ADT_STRINGMAP_H_
  14. #define LLVM_TESTING_ADT_STRINGMAP_H_
  15. #include "llvm/ADT/STLExtras.h"
  16. #include "llvm/ADT/StringMap.h"
  17. #include "llvm/Support/FormatVariadic.h"
  18. #include "llvm/Testing/ADT/StringMapEntry.h"
  19. #include <ostream>
  20. #include <sstream>
  21. namespace llvm {
  22. /// Support for printing to std::ostream, for use with e.g. producing more
  23. /// useful error messages with Google Test.
  24. template <typename T>
  25. std::ostream &operator<<(std::ostream &OS, const StringMap<T> &M) {
  26. if (M.empty()) {
  27. return OS << "{ }";
  28. }
  29. std::vector<std::string> Lines;
  30. for (const auto &E : M) {
  31. std::ostringstream SS;
  32. SS << E << ",";
  33. Lines.push_back(SS.str());
  34. }
  35. llvm::sort(Lines);
  36. Lines.insert(Lines.begin(), "{");
  37. Lines.insert(Lines.end(), "}");
  38. return OS << llvm::formatv("{0:$[\n]}",
  39. make_range(Lines.begin(), Lines.end()))
  40. .str();
  41. }
  42. } // namespace llvm
  43. #endif
  44. #ifdef __GNUC__
  45. #pragma GCC diagnostic pop
  46. #endif