<commit_before>#ifndef _BLISPP_MEMORY_HPP_
#define _BLISPP_MEMORY_HPP_

#include "blis++.hpp"

namespace blis
{

template <typename T, typename Allocator=std::allocator<T> >
class Memory
{
    public:
        typedef T type;

    private:
        struct _mem_s : Allocator
        {
            type* _base = NULL;
            _mem_s(Allocator alloc) : Allocator(alloc), _base(NULL) {}
        } _mem;
        type* _ptr = NULL;
        siz_t _size = 0;

    public:
        Memory(const Memory&) = delete;

        Memory(Memory&&) = default;

        Memory& operator=(const Memory&) = delete;

        Memory& operator=(Memory&&) = default;

        explicit Memory(siz_t size, Allocator alloc = Allocator())
        : _mem(alloc)
        {
            reset(size);
        }

        explicit Memory(Allocator alloc = Allocator())
        : _mem(alloc) {}

        explicit Memory(type* ptr)
        : _mem(Allocator())
        {
            reset(ptr);
        }

        ~Memory()
        {
            free();
        }

        void reset(siz_t size = 0)
        {
            free();
            if (size > 0)
            {
                _mem._base = _mem.allocate(size);
                _size = size;
                _ptr = _mem._base;
            }
        }

        void reset(type* ptr)
        {
            free();
            _ptr = ptr;
        }

        void free()
        {
            if (_mem._base) _mem.deallocate(_mem._base, _size);
            _mem._base = NULL;
            _size = 0;
            _ptr = NULL;
        }

        Memory& operator+=(inc_t x)
        {
            _ptr += x;
            return *this;
        }

        Memory& operator-=(inc_t x)
        {
            _ptr -= x;
            return *this;
        }

        type& operator[](dim_t i)
        {
            return _ptr[i];
        }

        const type& operator[](dim_t i) const
        {
            return _ptr[i];
        }

        operator type*() { return _ptr; }

        operator const type*() const { return _ptr; }
};

template <typename T>
class PooledMemory : private mem_t
{
    public:
        typedef T type;

    private:
        packbuf_t _packbuf;

        void init()
        {
            memset(static_cast<mem_t*>(this), 0, sizeof(mem_t));
        }

    public:
        PooledMemory(const PooledMemory&) = delete;

        PooledMemory(PooledMemory&& other)
        {
            *this = std::move(other);
        }

        PooledMemory& operator=(const PooledMemory&) = delete;

        PooledMemory& operator=(PooledMemory&& other)
        {
            if (this != &other)
            {
                memcpy(static_cast<mem_t*>(this), static_cast<mem_t*>(other), sizeof(mem_t));
                _packbuf = other._packbuf;
                other.init();
            }
            return *this;
        }

        explicit PooledMemory(packbuf_t packbuf) : _packbuf(packbuf)
        {
            init();
        }

        explicit PooledMemory(siz_t size, packbuf_t packbuf) : _packbuf(packbuf)
        {
            init();
            reset(size);
        }

        ~PooledMemory()
        {
            free();
        }

        void reset() {}

        void reset(siz_t size)
        {
            if (bli_mem_is_unalloc(this))
            {
                bli_mem_acquire_m(size, _packbuf, this);
            }
            else if (size > bli_mem_size(this))
            {
                bli_mem_release(this);
                bli_mem_acquire_m(size, _packbuf, this);
            }
        }

        void free()
        {
            if (bli_mem_is_alloc(this)) bli_mem_release(this);
        }

        operator type*() { return (type*)bli_mem_buffer(this); }

        operator const type*() const { return (type*)bli_mem_buffer(this); }
};

}

#endif
<commit_msg>Default move operators for Memory were invalid.<commit_after>#ifndef _BLISPP_MEMORY_HPP_
#define _BLISPP_MEMORY_HPP_

#include "blis++.hpp"

namespace blis
{

template <typename T, typename Allocator=std::allocator<T> >
class Memory
{
    public:
        typedef T type;

    private:
        struct _mem_s : Allocator
        {
            type* _base = NULL;
            _mem_s(Allocator alloc) : Allocator(alloc), _base(NULL) {}
        } _mem;
        type* _ptr = NULL;
        siz_t _size = 0;

    public:
        Memory(const Memory&) = delete;

        Memory(Memory&& other)
        : _ptr(other._ptr), _size(other._size)
        {
            std::swap(_mem._base, other._mem._base);
        }

        Memory& operator=(const Memory&) = delete;

        Memory& operator=(Memory&& other)
        {
            std::swap(_ptr, other._ptr);
            std::swap(_size, other._size);
            std::swap(_mem._base, other._mem._base);
            return *this;
        }

        explicit Memory(siz_t size, Allocator alloc = Allocator())
        : _mem(alloc)
        {
            reset(size);
        }

        explicit Memory(Allocator alloc = Allocator())
        : _mem(alloc) {}

        explicit Memory(type* ptr)
        : _mem(Allocator())
        {
            reset(ptr);
        }

        ~Memory()
        {
            free();
        }

        void reset(siz_t size = 0)
        {
            free();
            if (size > 0)
            {
                _mem._base = _mem.allocate(size);
                _size = size;
                _ptr = _mem._base;
            }
        }

        void reset(type* ptr)
        {
            free();
            _ptr = ptr;
        }

        void free()
        {
            if (_mem._base) _mem.deallocate(_mem._base, _size);
            _mem._base = NULL;
            _size = 0;
            _ptr = NULL;
        }

        Memory& operator+=(inc_t x)
        {
            _ptr += x;
            return *this;
        }

        Memory& operator-=(inc_t x)
        {
            _ptr -= x;
            return *this;
        }

        type& operator[](dim_t i)
        {
            return _ptr[i];
        }

        const type& operator[](dim_t i) const
        {
            return _ptr[i];
        }

        operator type*() { return _ptr; }

        operator const type*() const { return _ptr; }
};

template <typename T>
class PooledMemory : private mem_t
{
    public:
        typedef T type;

    private:
        packbuf_t _packbuf;

        void init()
        {
            memset(static_cast<mem_t*>(this), 0, sizeof(mem_t));
        }

    public:
        PooledMemory(const PooledMemory&) = delete;

        PooledMemory(PooledMemory&& other)
        {
            *this = std::move(other);
        }

        PooledMemory& operator=(const PooledMemory&) = delete;

        PooledMemory& operator=(PooledMemory&& other)
        {
            if (this != &other)
            {
                memcpy(static_cast<mem_t*>(this), static_cast<mem_t*>(other), sizeof(mem_t));
                _packbuf = other._packbuf;
                other.init();
            }
            return *this;
        }

        explicit PooledMemory(packbuf_t packbuf) : _packbuf(packbuf)
        {
            init();
        }

        explicit PooledMemory(siz_t size, packbuf_t packbuf) : _packbuf(packbuf)
        {
            init();
            reset(size);
        }

        ~PooledMemory()
        {
            free();
        }

        void reset() {}

        void reset(siz_t size)
        {
            if (bli_mem_is_unalloc(this))
            {
                bli_mem_acquire_m(size, _packbuf, this);
            }
            else if (size > bli_mem_size(this))
            {
                bli_mem_release(this);
                bli_mem_acquire_m(size, _packbuf, this);
            }
        }

        void free()
        {
            if (bli_mem_is_alloc(this)) bli_mem_release(this);
        }

        operator type*() { return (type*)bli_mem_buffer(this); }

        operator const type*() const { return (type*)bli_mem_buffer(this); }
};

}

#endif

{'fraction_non_alphanumeric': 0.11192061298831806, 'fraction_numerical': 0.0012561236025624921, 'mean_word_length': 1.3605099318114438, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7535555', 'n_tokens_mistral': 2482, 'n_tokens_neox': 2389, 'n_words': 482}