62 { |
64 { |
63 one = one ^ other; |
65 one = one ^ other; |
64 return one; |
66 return one; |
65 } |
67 } |
66 |
68 |
67 template<typename T, std::size_t N> |
|
68 constexpr std::size_t countof(T(&)[N]) |
|
69 { |
|
70 return N; |
|
71 } |
|
72 |
|
73 static constexpr long double pi = M_PIl; |
69 static constexpr long double pi = M_PIl; |
74 |
|
75 // http://stackoverflow.com/a/18204188/3629665 |
|
76 template<typename T> |
|
77 inline auto rotl10(T x) |
|
78 -> std::enable_if_t<std::is_arithmetic_v<T>, T> |
|
79 { |
|
80 return (x << 10) | ((x >> 22) & 0x000000ff); |
|
81 } |
|
82 |
|
83 template<typename T> |
|
84 inline auto rotl20(T x) |
|
85 -> std::enable_if_t<std::is_arithmetic_v<T>, T> |
|
86 { |
|
87 return (x << 20) | ((x >> 12) & 0x000000ff); |
|
88 } |
|
89 |
|
90 template<typename T, typename... Rest> |
|
91 QString format(const QString& format_string, T&& arg, Rest&&... rest) |
|
92 { |
|
93 return format(format_string.arg(arg), std::forward<Rest>(rest)...); |
|
94 } |
|
95 |
|
96 template<typename T> |
|
97 QString format(const QString& format_string, T&& arg) |
|
98 { |
|
99 return format_string.arg(arg); |
|
100 } |
|
101 |
|
102 inline QString quoted(QString string) |
|
103 { |
|
104 if (string.contains("'")) |
|
105 { |
|
106 string.replace("\"", "\\\""); |
|
107 string = "\"" + string + "\""; |
|
108 } |
|
109 else |
|
110 { |
|
111 string = "'" + string + "'"; |
|
112 } |
|
113 return string; |
|
114 } |
|