-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlimits.hpp
50 lines (42 loc) · 1.4 KB
/
limits.hpp
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
/**
* @file limits.hpp
* @brief Infinity constants for competitive programming purposes
*/
#ifndef LIMITS_HPP
#define LIMITS_HPP
#include <limits>
#include <utility>
template <class T> struct cp_limits {
static constexpr T infinity() {
return std::numeric_limits<T>::has_infinity
? std::numeric_limits<T>::infinity()
: std::numeric_limits<T>::max() / 2;
}
static constexpr T negative_infinity() {
return std::numeric_limits<T>::has_infinity
? -std::numeric_limits<T>::infinity()
: std::numeric_limits<T>::min() / 2;
}
};
template <> struct cp_limits<int> {
static constexpr int infinity() { return 0x3f3f3f3f; }
static constexpr int negative_infinity() { return -infinity(); }
};
template <> struct cp_limits<long long> {
static constexpr long long infinity() { return 0x3f3f3f3f3f3f3f3fLL; }
static constexpr long long negative_infinity() { return -infinity(); }
};
template <> struct cp_limits<char> {
static constexpr char infinity() { return 127; }
static constexpr char negative_infinity() { return 0; }
};
template <class T1, class T2> struct cp_limits<std::pair<T1, T2>> {
static constexpr std::pair<T1, T2> infinity() {
return {cp_limits<T1>::infinity(), cp_limits<T2>::infinity()};
}
static constexpr std::pair<T1, T2> negative_infinity() {
return {cp_limits<T1>::negative_infinity(),
cp_limits<T2>::negative_infinity()};
}
};
#endif