1 //===--- Printable.h - Print function helpers -------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the Printable struct.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_SUPPORT_PRINTABLE_H
15 #define LLVM_SUPPORT_PRINTABLE_H
23 /// Simple wrapper around std::function<void(raw_ostream&)>.
24 /// This class is usefull to construct print helpers for raw_ostream.
27 /// Printable PrintRegister(unsigned Register) {
28 /// return Printable([Register](raw_ostream &OS) {
29 /// OS << getRegisterName(Register);
32 /// ... OS << PrintRegister(Register); ...
34 /// Implementation note: Ideally this would just be a typedef, but doing so
35 /// leads to operator << being ambiguous as function has matching constructors
36 /// in some STL versions. I have seen the problem on gcc 4.6 libstdc++ and
40 std::function<void(raw_ostream &OS)> Print;
41 Printable(const std::function<void(raw_ostream &OS)> Print)
45 static inline raw_ostream &operator<<(raw_ostream &OS, const Printable &P) {