use [[gnu::...]] attributes

This commit is contained in:
Max Kellermann
2023-03-06 15:57:36 +01:00
parent 3b9aab0684
commit 42f6a0441c
101 changed files with 167 additions and 234 deletions

View File

@@ -4,20 +4,21 @@
#ifndef CLAMP_HPP
#define CLAMP_HPP
#include "Compiler.h"
/**
* Clamps the specified value in a range. Returns #min or #max if the
* value is outside.
*/
template<typename T>
constexpr const T &
Clamp(const T &value, const T &min, const T &max)
Clamp(const T &value, const T &min, const T &max) noexcept
{
return gcc_unlikely(value < min)
? min
: (gcc_unlikely(value > max)
? max : value);
if (value < min) [[unlikely]]
return min;
if (value > max) [[unlikely]]
return max;
return value;
}
#endif