based

Opinionated utility library
git clone git://git.dimitrijedobrota.com/based.git
Log | Files | Refs | README | LICENSE | HACKING | CONTRIBUTING | CODE_OF_CONDUCT | BUILDING

commit e2e5c682a35189a3924de4679064e7fc43377f21
parent 87de479f3b8f1a935ae8485e35fbf00fd1b5e2ab
author Dimitrije Dobrota < mail@dimitrijedobrota.com >
date Sun, 29 Jun 2025 20:19:59 +0200

Allocator takes size_type as template parameter

Diffstat:
M include/based/memory/allocator.hpp | +++++++++++++ ------------

1 files changed, 13 insertions(+), 12 deletions(-)


diff --git a/ include/based/memory/allocator.hpp b/ include/based/memory/allocator.hpp

@@ -4,34 +4,35 @@

* Standard: https://eel.is/c++draft/default.allocator
*/

#include "based/concept/is_integral.hpp"
#include "based/integral/types.hpp"
#include "based/trait/integral_constant.hpp"

namespace based
{

template<class T>
template<class T, trait::IsUnsignedIntegral U>
class Allocator;

template<>
class Allocator<void>
template<trait::IsUnsignedIntegral U>
class Allocator<void, U>
{
};

template<class T>
template<class T, trait::IsUnsignedIntegral U>
class Allocator
{
public:
using value_type = T;
using size_type = SizeT;
using size_type = U;
using difference_type = PtrDiffT;
using propagate_on_container_move_assignment = TrueType;

constexpr Allocator() noexcept = default;

template<class U>
template<class T_, trait::IsUnsignedIntegral U_>
// NOLINTNEXTLINE(*explicit*,*unused*)
constexpr Allocator(const Allocator<U>& that) noexcept
constexpr Allocator(const Allocator<T_, U_>& that) noexcept
{
}

@@ -47,14 +48,14 @@ public:

constexpr void deallocate(T* ptr, size_type size);
};

template<class T>
constexpr T* Allocator<T>::allocate(Allocator::size_type size)
template<class T, trait::IsUnsignedIntegral U>
constexpr T* Allocator<T, U>::allocate(size_type size)
{
return static_cast<value_type*>(::operator new(size * sizeof(T)));
return static_cast<value_type*>(::operator new(size.value * sizeof(T)));
}

template<class T>
constexpr void Allocator<T>::deallocate(T* ptr, size_type size)
template<class T, trait::IsUnsignedIntegral U>
constexpr void Allocator<T, U>::deallocate(T* ptr, size_type size)
{
(void)size;
::operator delete(static_cast<void*>(ptr));