-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtraits.hpp
More file actions
96 lines (75 loc) · 2.1 KB
/
traits.hpp
File metadata and controls
96 lines (75 loc) · 2.1 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
86
87
88
89
90
91
92
93
94
95
96
/*!
* \file traits.hpp
* \author Han Luo (luohancfd AT github)
* \brief Wrapper of MPI functions
* \version 0.1
* \date 2020-12-22
* \copyright GPL-3.0
*
* @copyright Copyright (c) 2020
*
*/
#pragma once
#ifndef TRAITS_HPP
#define TRAITS_HPP
#include <sstream>
#include <string>
#include <type_traits>
template <class T>
struct dependent_false : std::false_type {};
template <class T>
struct dependent_true : std::true_type {};
template <typename T>
struct is_string : std::false_type {};
template <>
struct is_string<std::string> : std::true_type {};
template <typename>
struct is_pair : std::false_type {};
template <typename T, typename U>
struct is_pair<std::pair<T, U>> : std::true_type {};
template <typename>
struct is_tuple : std::false_type {};
template <typename... T>
struct is_tuple<std::tuple<T...>> : std::true_type {};
template <typename T>
struct is_numeric
: std::integral_constant<bool, std::is_integral<T>::value ||
std::is_floating_point<T>::value> {};
template <bool, class T = void>
struct enable_if_c {
typedef T type;
};
template <class T>
struct enable_if_c<false, T> {};
template <class Cond, class T = void>
struct enable_if : public enable_if_c<Cond::value, T> {};
template <bool, class T = void>
struct disable_if_c {
typedef T type;
};
template <class T>
struct disable_if_c<true, T> {};
template <class Cond, class T = void>
struct disable_if : public disable_if_c<Cond::value, T> {};
template <typename S, typename T>
struct is_streamable {
template <typename SS, typename TT>
static auto test(int)
-> decltype(std::declval<SS &>() << std::declval<TT>(), std::true_type());
template <typename, typename>
static auto test(...) -> std::false_type;
static const bool value = decltype(test<S, T>(0))::value;
};
template <typename Key, bool Streamable>
struct streamable_to_string {
static std::string impl(const Key &key) {
std::stringstream ss;
ss << key;
return ss.str();
}
};
template <typename Key>
struct streamable_to_string<Key, false> {
static std::string impl(const Key &) { return ""; }
};
#endif