HDIM  1.0.0
Packages for High Dimensional Linear Regression
debug.hpp
Go to the documentation of this file.
1 #ifndef FOS_DEBUG_H
2 #define FOS_DEBUG_H
3 
8 // C System-Headers
9 #include <stdio.h>
10 // C++ System headers
11 #include <sstream>
12 #include <string>
13 #include <stdexcept>
14 #include <iostream>
15 #include <type_traits>
16 #include <assert.h> //static_assert
17 #include <fstream>
18 #include <typeinfo> // typeid, typeof
19 
20 #if defined __linux__ || defined __APPLE__
21 #include <cxxabi.h>// abi::__cxa_demangle
22 #endif
23 
24 // Boost Headers
25 //
26 // Miscellaneous Headers
27 //
28 
40 #if defined __linux__ || defined __APPLE__
41 template <typename T>
42 std::string get_type_name () {
43 
44  int status;
45  char* type_name = abi::__cxa_demangle(typeid(T).name(), 0, 0, &status);
46  std::string type_str = std::string( type_name );
47 
48  free (type_name);
49 
50  return type_str;
51 }
52 #elif _WIN32
53 std::string get_type_name() {
54  return std::string( typeid(T).name() );
55 }
56 #endif
57 
59 #define TIME_IT( func, ... ) \
60  do { \
61  auto start = std::chrono::high_resolution_clock::now(); \
62  func \
63  auto end = std::chrono::high_resolution_clock::now();\
64  std::chrono::duration<double, std::milli> ms = end - start;\
65  auto time_taken = ms.count();\
66  std::cout<< "Function took " << time_taken <<" ms." << std::endl;\
67  } while (0)
68 
70 #ifdef DEBUG
71 # define DEBUG_PRINT( x, ... ) std::cout << x __VA_ARGS__ << std::endl;
72 #else
73 # define DEBUG_PRINT( x, ... )
74 #endif
75 
76 #endif // FOS_DEBUG_H