BAN: Add min, max and clamp
This commit is contained in:
parent
ef0b2010e0
commit
b60af90538
|
@ -1,4 +1,5 @@
|
|||
#include <BAN/Errors.h>
|
||||
#include <BAN/Math.h>
|
||||
#include <BAN/Memory.h>
|
||||
#include <BAN/Move.h>
|
||||
#include <BAN/String.h>
|
||||
|
@ -6,7 +7,6 @@
|
|||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <sys/param.h>
|
||||
|
||||
namespace BAN
|
||||
{
|
||||
|
@ -200,7 +200,7 @@ namespace BAN
|
|||
{
|
||||
if (m_capasity >= size)
|
||||
return {};
|
||||
size_type new_cap = MAX(size, m_capasity * 1.5f);
|
||||
size_type new_cap = BAN::max<size_type>(size, m_capasity * 1.5f);
|
||||
void* new_data = BAN::allocator(new_cap);
|
||||
if (new_data == nullptr)
|
||||
return Error::FromString("String: Could not allocate memory");
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
#pragma once
|
||||
|
||||
namespace BAN
|
||||
{
|
||||
|
||||
template<typename T>
|
||||
T min(T a, T b)
|
||||
{
|
||||
return a < b ? a : b;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T max(T a, T b)
|
||||
{
|
||||
return a > b ? a : b;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T clamp(T x, T min, T max)
|
||||
{
|
||||
return x < min ? min : x > max ? max : x;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,12 +1,12 @@
|
|||
#pragma once
|
||||
|
||||
#include <BAN/Errors.h>
|
||||
#include <BAN/Math.h>
|
||||
#include <BAN/Memory.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <sys/param.h>
|
||||
|
||||
namespace BAN
|
||||
{
|
||||
|
@ -96,7 +96,7 @@ namespace BAN
|
|||
if (m_capacity > size)
|
||||
return {};
|
||||
|
||||
size_type new_cap = MAX(m_capacity * 1.5f, m_capacity + 1);
|
||||
size_type new_cap = BAN::max<size_type>(m_capacity * 1.5f, m_capacity + 1);
|
||||
void* new_data = BAN::allocator(new_cap * sizeof(T));
|
||||
if (new_data == nullptr)
|
||||
return Error::FromString("Queue: Could not allocate memory");
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
#pragma once
|
||||
|
||||
#include <BAN/Errors.h>
|
||||
#include <BAN/Math.h>
|
||||
#include <BAN/Memory.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <sys/param.h>
|
||||
|
||||
namespace BAN
|
||||
{
|
||||
|
@ -208,7 +208,7 @@ namespace BAN
|
|||
{
|
||||
if (m_capasity >= size)
|
||||
return {};
|
||||
size_type new_cap = MAX(size, m_capasity * 1.5f);
|
||||
size_type new_cap = BAN::max<size_type>(size, m_capasity * 1.5f);
|
||||
void* new_data = BAN::allocator(new_cap * sizeof(T));
|
||||
if (new_data == nullptr)
|
||||
return Error::FromString("Vector: Could not allocate memory");
|
||||
|
|
Loading…
Reference in New Issue