DMRITool  v0.1.1-139-g860d86b4
Diffusion MRI Tool
utlCore11.h
Go to the documentation of this file.
1 
11 #ifndef __utlCore11_h
12 #define __utlCore11_h
13 
14 #include "utlCoreMacro.h"
15 #include "utlTypeinfo.h"
16 
20 namespace utl
21 {
22 
23 template<std::size_t>
24 struct Int_{};
25 
26 template <class Tuple, size_t Pos>
27 inline std::ostream&
28 PrintTuple(std::ostream& os, const Tuple& t, Int_<Pos> )
29 {
30  os << std::get< std::tuple_size<Tuple>::value-Pos >(t) << ", ";
31  return PrintTuple(os, t, Int_<Pos-1>());
32 }
33 
35 template <class Tuple>
36 inline std::ostream&
37 PrintTuple(std::ostream& os, const Tuple& t, Int_<1> )
38 {
39  return os << std::get<std::tuple_size<Tuple>::value-1>(t);
40 }
41 
42 
43 template <class... Args>
44 void
45 PrintTuple(const std::tuple<Args...>& t, const std::string& str="", std::ostream& os=std::cout)
46 {
47  os << (str==""?"tuple":str) << " = " << t << std::endl;
48 }
49 
51 template<typename... Args>
52 inline auto
53 GetNumberOfArgs(Args... args) -> decltype(sizeof...(args))
54 {
55  return sizeof...(args);
56 }
57 
58 // template <typename T>
59 // inline void
60 // __PrintOS(std::ostream& os, const char* seperate, const T& t)
61 // {
62 // os << t;
63 // }
64 
65 // template<typename T, typename... Args>
66 // inline void
67 // __PrintOS(std::ostream& os, const char* separate, const T& t, Args... args) // recursive variadic function
68 // {
69 // os << t << separate;
70 // __PrintOS(os, separate, args...) ;
71 // }
72 
73 
74 
76 template<typename... Args>
77 inline void
78 PrintOS(std::ostream& os, Args... args)
79 {
80  auto list = std::make_tuple(args...);
81  os << list << std::endl << std::flush;
82 }
83 
85 template<typename... Args>
86 inline void
87 Print(Args... args)
88 {
89  PrintOS(std::cout, args...);
90 }
91 
92 
93 }
94 
95 namespace std
96 {
97 
99 template <class... Args>
100 inline std::ostream&
101 operator<<(std::ostream& os, const std::tuple<Args...>& t)
102 {
103  os << std::boolalpha;
104  int nn = sizeof...(Args);
105  if (nn>1)
106  os << '(';
107  utl::PrintTuple(os, t, utl::Int_<sizeof...(Args)>());
108  if (nn>1)
109  os << ')';
110  os << std::noboolalpha << std::flush;
111  return os;
112 }
113 
114 }
115 
116 
119 #endif
Created "07-04-2016.
std::ostream & operator<<(std::ostream &os, const NDArray< T, Dim > &arr)
void Print(Args...args)
Definition: utlCore11.h:87
STL namespace.
void PrintOS(std::ostream &os, Args...args)
Definition: utlCore11.h:78
std::ostream & PrintTuple(std::ostream &os, const Tuple &t, Int_< Pos >)
Definition: utlCore11.h:28
Definition: utl.h:90
macros for utlCore
auto GetNumberOfArgs(Args...args) -> decltype(sizeof...(args))
Definition: utlCore11.h:53