LLVM  6.0.0svn
Printable.h
Go to the documentation of this file.
1 //===--- Printable.h - Print function helpers -------------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines the Printable struct.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_SUPPORT_PRINTABLE_H
15 #define LLVM_SUPPORT_PRINTABLE_H
16 
17 #include <functional>
18 
19 namespace llvm {
20 
21 class raw_ostream;
22 
23 /// Simple wrapper around std::function<void(raw_ostream&)>.
24 /// This class is useful to construct print helpers for raw_ostream.
25 ///
26 /// Example:
27 /// Printable PrintRegister(unsigned Register) {
28 /// return Printable([Register](raw_ostream &OS) {
29 /// OS << getRegisterName(Register);
30 /// }
31 /// }
32 /// ... OS << PrintRegister(Register); ...
33 ///
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
37 /// microsoft STL.
38 class Printable {
39 public:
40  std::function<void(raw_ostream &OS)> Print;
42  : Print(std::move(Print)) {}
43 };
44 
46  P.Print(OS);
47  return OS;
48 }
49 
50 }
51 
52 #endif
Printable(std::function< void(raw_ostream &OS)> Print)
Definition: Printable.h:41
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
Definition: BitVector.h:920
#define P(N)
raw_ostream & operator<<(raw_ostream &OS, const APInt &I)
Definition: APInt.h:2018
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:44
std::function< void(raw_ostream &OS)> Print
Definition: Printable.h:40
print Print MemDeps of function
Simple wrapper around std::function<void(raw_ostream&)>.
Definition: Printable.h:38