-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbasic.hpp
More file actions
85 lines (64 loc) · 1.63 KB
/
basic.hpp
File metadata and controls
85 lines (64 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#ifndef BASIC_HPP
#define BASIC_HPP
#include <iostream>
//__GNUG__ g++
#if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__)
#define force_inline __attribute__((always_inline)) inline
#elif defined(_MSC_VER)
#define force_inline __forceinline
#endif
template<class A>
std::string str(const A& input){
return std::to_string(input);
}
std::string str(std::string input){
return input;
}
std::string str(bool input){
if(input){
return "true";
}
return "false";
}
std::string str(const char* input){
return input;
}
void print(){
std::cout << "\n";
}
template<class A,class... Args>
void print(const A& first,Args const&... args){
std::cout << str(first) << " ";
print(args...);
}
#include <typeinfo>
///*********************begin***********
//parts of following code for types is from
//https://stackoverflow.com/questions/281818/unmangling-the-result-of-stdtype-infoname/4541470
std::string demangle(const char* name);
#ifdef __GNUG__
#include <cstdlib>
#include <memory>
#include <cxxabi.h>
std::string demangle(const char* name) {
int status = -4; // some arbitrary value to eliminate the compiler warning
// enable c++11 by passing the flag -std=c++11 to g++
std::unique_ptr<char, void(*)(void*)> res {
abi::__cxa_demangle(name, NULL, NULL, &status),
std::free
};
return (status==0) ? res.get() : name ;
}
#else
// does nothing if not g++
std::string demangle(const char* name) {
return name;
}
#endif
///*********************end***********
/**
* @param type variable
* @return std::string
*/
#define type( t ) demangle(typeid(t).name())
#endif