From 670031666cf4dea0d122a0df2ec1d18822c225e4 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Tue, 30 Jun 2009 01:28:08 +0000 Subject: [PATCH] Define an operator<< for APInt to be used with std::ostream. This will allow it to be used in unittests that use gtest's EXPECT_EQ. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@74494 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/ADT/APInt.h | 2 ++ lib/Support/APInt.cpp | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/include/llvm/ADT/APInt.h b/include/llvm/ADT/APInt.h index 63bf4f6d9ba..56cd3ccf84e 100644 --- a/include/llvm/ADT/APInt.h +++ b/include/llvm/ADT/APInt.h @@ -1426,6 +1426,8 @@ inline raw_ostream &operator<<(raw_ostream &OS, const APInt &I) { return OS; } +std::ostream &operator<<(std::ostream &o, const APInt &I); + namespace APIntOps { /// @brief Determine the smaller of two APInts considered to be signed. diff --git a/lib/Support/APInt.cpp b/lib/Support/APInt.cpp index 73bf774b171..25e23e0ac00 100644 --- a/lib/Support/APInt.cpp +++ b/lib/Support/APInt.cpp @@ -2178,6 +2178,12 @@ void APInt::print(raw_ostream &OS, bool isSigned) const { OS << S.c_str(); } +std::ostream &operator<<(std::ostream &o, const APInt &I) { + raw_os_ostream OS(o); + OS << I; + return o; +} + // This implements a variety of operations on a representation of // arbitrary precision, two's-complement, bignum integer values.