Spicy
hilti.h
1 // Copyright (c) 2020-2021 by the Zeek Project. See LICENSE for details.
2 
8 #pragma once
9 
10 #include <iostream>
11 #include <type_traits>
12 
13 #include <hilti/rt/configuration.h>
14 #include <hilti/rt/exception.h>
15 #include <hilti/rt/extension-points.h>
16 #include <hilti/rt/util.h>
17 
18 namespace hilti::rt {
19 
21 template<typename T>
22 void print(const T& t, bool newline = true) {
23  if ( ! configuration::get().cout )
24  return;
25 
26  auto& cout = configuration::get().cout->get();
27 
29 
30  if ( newline )
31  cout << std::endl;
32  else
33  cout.flush();
34 }
35 
37 template<typename T, typename std::enable_if_t<is_tuple<T>::value>* = nullptr>
38 void printValues(const T& t, bool newline = true) {
39  if ( ! configuration::get().cout )
40  return;
41 
42  auto& cout = configuration::get().cout->get();
43 
44  cout << join_tuple_for_print(t);
45 
46  if ( newline )
47  cout << std::endl;
48  else
49  cout.flush();
50 }
51 
52 // Just for testing: Declaring a function that's not implemented.
53 extern void __does_not_exist();
54 
55 }; // namespace hilti::rt
std::string to_string_for_print(const T &x)
Definition: extension-points.h:45
Definition: any.h:7
auto join_tuple_for_print(T &&tup)
Definition: util.h:492
void printValues(const T &t, bool newline=true)
Definition: hilti.h:38
void print(const T &t, bool newline=true)
Definition: hilti.h:22