17
17
#include < cppt_ag.hpp>
18
18
#include < cppt_tools.hpp>
19
19
20
+ #include " llvm/Support/raw_ostream.h"
21
+ #include < llvm/ADT/StringRef.h>
22
+
20
23
#include < algorithm>
21
24
#include < iostream>
22
25
#include < string>
@@ -37,6 +40,7 @@ int main(int argc, const char** argv) {
37
40
const char * hello_c_c = " Hello World!" ;
38
41
std::string hello_cpp (hello_c);
39
42
std::string_view hello_sv (hello_cpp);
43
+ llvm::StringRef hello_sr (hello_cpp);
40
44
41
45
// -------------------------------------------------------------------------
42
46
// 2. PRINT THE STRINGS
@@ -45,6 +49,11 @@ int main(int argc, const char** argv) {
45
49
std::cout << " C-string (const char*): " << hello_c_c << std::endl;
46
50
std::cout << " C++ string: " << hello_cpp << std::endl;
47
51
std::cout << " C++ string_view: " << hello_sv << std::endl;
52
+ // As std::cout _does not_ understand llvm::StringRef, you need to grab the
53
+ // underlying string for printing.
54
+ std::cout << " C++ StringRef (via std::cout): " << hello_sr.str () << std::endl;
55
+ // However, llvm::outs() _does_ understand llvm:StringRef.
56
+ llvm::outs () << " C++ StringRef (via llvm::outs): " << hello_sr << " \n " ;
48
57
std::cout << std::endl;
49
58
50
59
// -------------------------------------------------------------------------
@@ -54,6 +63,7 @@ int main(int argc, const char** argv) {
54
63
std::cout << " Size of hello_c_c: " << sizeof (hello_c_c) << std::endl;
55
64
std::cout << " Size of hello_cpp: " << sizeof (hello_cpp) << std::endl;
56
65
std::cout << " Size of hello_sv: " << sizeof (hello_sv) << std::endl;
66
+ std::cout << " Size of hello_sr: " << sizeof (hello_sr) << std::endl;
57
67
std::cout << std::endl;
58
68
59
69
// -------------------------------------------------------------------------
0 commit comments