use [[gnu::...]] attributes
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user