Subversion Repositories QNX 8.QNX8 LLVM/Clang compiler suite

Rev

Blame | Last modification | View Log | Download | RSS feed

  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(SS.str());
  34.   }
  35.   llvm::sort(Lines);
  36.   Lines.insert(Lines.begin(), "{");
  37.   Lines.insert(Lines.end(), "}");
  38.  
  39.   return OS << llvm::formatv("{0:$[\n]}",
  40.                              make_range(Lines.begin(), Lines.end()))
  41.                    .str();
  42. }
  43.  
  44. } // namespace llvm
  45.  
  46. #endif
  47.