NASA Logo
Ocean Color Science Software

ocssw V2022
PrintDebug.hpp
Go to the documentation of this file.
1 #ifndef PRINT_DEBUG_HPP
2 #define PRINT_DEBUG_HPP
3 #include <iostream>
4 template <typename, typename = void>
5 constexpr bool is_iterable{};
6 
7 template <typename T>
8 constexpr bool is_iterable<T, std::void_t<decltype(std::declval<T>().begin()),
9  decltype(std::declval<T>().end())>> =
10  true;
11 
12 template <typename T, typename U>
13 std::ostream& operator<<(std::ostream& os,
14  const std::pair<T, U>& data) noexcept {
15  os << data.first << " : " << data.second;
16  return os;
17 }
18 template <typename T, std::enable_if_t<is_iterable<T>, bool> = true>
19 std::ostream& operator<<(std::ostream& os, const T& data) noexcept {
20  for (auto it = data.begin(); it != data.end(); it++) {
21  os << *it << " ";
22  }
23 
24  return os;
25 }
26 
27 // An iterator trait those value_type is the value_type of the iterated
28 // container, supports even back_insert_iterator (where value_type is void)
29 
30 template <typename T, typename = void>
31 struct iterator_trait : std::iterator_traits<T> {};
32 
33 template <typename T>
34 struct iterator_trait<T, std::void_t<typename T::container_type>>
35  : std::iterator_traits<typename T::container_type::iterator> {};
36 
37 
38 inline void print(std::ostream& stream, const char* format) { stream << format; }
39 
40 template <typename T, typename... Targs>
41 void print(std::ostream& stream, const char* format, T&& value,
42  Targs&&... fargs) {
43  for (; *format != '\0'; format++) {
44  if (*format == '%') {
45  stream << value;
46  print(stream, format + 1, fargs...);
47  return;
48  }
49  stream << *format;
50  }
51 }
52 
53 inline void print(const char* format) { std::cout << format; }
54 
55 template <typename T, typename... Targs>
56 void print(const char* format, T&& value, Targs&&... fargs) {
57  print(std::cout, format, value, fargs...);
58 }
59 
60 #endif
int32 value
Definition: Granule.c:1235
constexpr bool is_iterable
Definition: PrintDebug.hpp:5
subroutine os(tamoy, trmoy, pizmoy, tamoyp, trmoyp, palt, phirad, nt, mu, np, rm, gb, rp, xl)
Definition: 6sm1.f:5484
void print(std::ostream &stream, const char *format)
Definition: PrintDebug.hpp:38
no change in intended resolving MODur00064 Corrected handling of bad ephemeris attitude data
Definition: HISTORY.txt:356
std::ostream & operator<<(std::ostream &os, const std::pair< T, U > &data) noexcept
Definition: PrintDebug.hpp:13