Skip to content

Commit 319af8d

Browse files
authored
Merge pull request #1962 from zhehangd/fix_static_inline
Fix static inline template in defs.hpp
2 parents a3f5035 + fcde547 commit 319af8d

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

include/godot_cpp/core/defs.hpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,12 @@ constexpr auto CLAMP(const T m_a, const T2 m_min, const T3 m_max) {
145145

146146
// Returns `true` if a positive integer is a power of 2, `false` otherwise.
147147
template <typename T>
148-
inline bool is_power_of_2(const T x) {
148+
constexpr bool is_power_of_2(const T x) {
149149
return x && ((x & (x - 1)) == 0);
150150
}
151151

152152
// Function to find the next power of 2 to an integer.
153-
static _FORCE_INLINE_ unsigned int next_power_of_2(unsigned int x) {
153+
constexpr unsigned int next_power_of_2(unsigned int x) {
154154
if (x == 0) {
155155
return 0;
156156
}
@@ -166,7 +166,7 @@ static _FORCE_INLINE_ unsigned int next_power_of_2(unsigned int x) {
166166
}
167167

168168
// Function to find the previous power of 2 to an integer.
169-
static _FORCE_INLINE_ unsigned int previous_power_of_2(unsigned int x) {
169+
constexpr unsigned int previous_power_of_2(unsigned int x) {
170170
x |= x >> 1;
171171
x |= x >> 2;
172172
x |= x >> 4;
@@ -176,14 +176,14 @@ static _FORCE_INLINE_ unsigned int previous_power_of_2(unsigned int x) {
176176
}
177177

178178
// Function to find the closest power of 2 to an integer.
179-
static _FORCE_INLINE_ unsigned int closest_power_of_2(unsigned int x) {
179+
constexpr unsigned int closest_power_of_2(unsigned int x) {
180180
unsigned int nx = next_power_of_2(x);
181181
unsigned int px = previous_power_of_2(x);
182182
return (nx - x) > (x - px) ? px : nx;
183183
}
184184

185185
// Get a shift value from a power of 2.
186-
static inline int get_shift_from_power_of_2(unsigned int p_bits) {
186+
constexpr int get_shift_from_power_of_2(unsigned int p_bits) {
187187
for (unsigned int i = 0; i < 32; i++) {
188188
if (p_bits == (unsigned int)(1 << i)) {
189189
return i;
@@ -194,13 +194,13 @@ static inline int get_shift_from_power_of_2(unsigned int p_bits) {
194194
}
195195

196196
template <typename T>
197-
static _FORCE_INLINE_ T nearest_power_of_2_templated(T x) {
197+
constexpr T nearest_power_of_2_templated(T x) {
198198
--x;
199199

200200
// The number of operations on x is the base two logarithm
201201
// of the number of bits in the type. Add three to account
202202
// for sizeof(T) being in bytes.
203-
size_t num = get_shift_from_power_of_2(sizeof(T)) + 3;
203+
constexpr size_t num = get_shift_from_power_of_2(sizeof(T)) + 3;
204204

205205
// If the compiler is smart, it unrolls this loop.
206206
// If it's dumb, this is a bit slow.
@@ -212,7 +212,7 @@ static _FORCE_INLINE_ T nearest_power_of_2_templated(T x) {
212212
}
213213

214214
// Function to find the nearest (bigger) power of 2 to an integer.
215-
static inline unsigned int nearest_shift(unsigned int p_number) {
215+
constexpr unsigned int nearest_shift(unsigned int p_number) {
216216
for (int i = 30; i >= 0; i--) {
217217
if (p_number & (1 << i)) {
218218
return i + 1;

0 commit comments

Comments
 (0)