<commit_before>#include <iostream>
#include <stdexcept>

template <typename T>
auto new_with_copy( T const * src, size_t src_size, size_t dst_size ) -> T *
{
    T * dst = new T [ dst_size ];
    
    try {
        std::copy( src, src + src_size, dst );
    }
    catch (...) {
        delete [] dst;
        throw;
    }
    
    return dst;
}


template <typename T>
class stack {
public:
    stack();
    stack( stack const & );
    ~stack();
    auto operator =( stack const & ) -> stack &;
    
    auto empty() const noexcept -> bool;
    auto count() const noexcept -> size_t;
    auto push( T const & value ) -> void;
    auto pop() -> void;
    auto top() -> T &;
    auto top() const -> T const &;
    
private:
    auto throw_is_empty() -> void;
    auto swap( stack & other ) -> void;
    
    T * ptr_;
    size_t size_;
    size_t count_;
};

template <typename T>
stack<T>::stack() :
    ptr_( nullptr ),
    size_( 0 ),
    count_( 0 )
{
    ;
}

template <typename T>
stack<T>::stack(stack const & other) :
    ptr_( new_with_copy( other.ptr_, other.count_, other.count_) ),
    size_( other.count_ ),
    count_( other.count_ )
{
    ;
}

template <typename T>
auto stack<T>::operator =(stack const & other) -> stack &
{
    if ( this != &other ) {
        this->swap( stack( other ) );
    };
    
    return *this;
}

template <typename T>
stack<T>::~stack<T>()
{
    delete [] ptr_;
}

template <typename T>
auto stack<T>::empty() const noexcept -> bool
{
    return count_ == 0;
}

template <typename T>
auto stack<T>::count() const noexcept -> size_t
{
    return count_;
}

template <typename T>
auto stack<T>::push(const T & value) -> void
{
    if ( count_ == size_ ) {
        size_t size = size_ * 2 + (size_ == 0);
        
        T * ptr = new_with_copy(ptr_, count_, size);
        
        delete [] ptr_;
        ptr_ = ptr;
        size_ = size;
        ptr_ = ptr;
    }
    
    ptr_[count_] = value;
    ++count_;
}

template <typename T>
auto stack<T>::pop() -> void
{
    if ( count_ == 0 ) {
        throw_is_empty();
    }
    
    --count_;
}

template <typename T>
auto stack<T>::top() -> T &
{
    if ( count_ == 0 ) {
        throw_is_empty();
    }
    
    return ptr_[count_ - 1];
}

template <typename T>
auto stack<T>::top() const -> T const &
{
    if ( count_ == 0 ) {
        throw_is_empty();
    }
    
    return ptr_[count_ - 1];
}

template <typename T>
auto stack<T>::throw_is_empty() -> void
{
    throw std::logic_error("stack is empty");
}

template <typename T>
auto stack<T>::swap( stack & other ) -> void
{
    std::swap( ptr_, other.ptr_ );
    std::swap( size_, other.size_ );
    std::swap( count_, other.count_ );
}
<commit_msg>Update stack.hpp<commit_after>#include "allocator.hpp"

template <typename T>
class stack : private allocator<T>
{
public:
	stack(size_t size = 0); /*noexcept*/
	stack(const stack & _stack); /*strong*/
	stack& operator=(const stack & _stack); /*strong*/
	size_t count() const; /*noexcept*/
	void push(T const &); /*strong*/
	const T & top() const; /*strong*/
	void pop(); /*strong*/
	bool empty() { return this->count_ == 0; } /*noexcept*/
	~stack(); /*noexcept*/
};

template<typename T>
stack<T>::stack(size_t size) : allocator(size) {
	;
}

template<typename T>
stack<T>::stack(const stack & _stack) /*strong*/
{
	this->ptr_ = operatorNewCopiedArray(_stack.ptr_, _stack.count_, _stack.size_);
	this->size_ = _stack.size_;
	this->count_ = _stack.count_;
}

template<typename T>
stack<T> & stack<T>::operator=(const stack & _stack) /*strong*/
{
	if (this != &_stack) {
		stack(_stack).swap(*this);
		/*T* midterm = newCopiedArray(_stack.ptr_, _stack.count_, _stack.size_);
		delete[] this->ptr_;
		this->ptr_ = midterm;
		this->count_ = _stack.count_;
		this->size_ = _stack.size_;*/
	}
	return *this;
}

template<typename T>
size_t stack<T>::count() const /*noexcept*/
{
	return this->count_;
}

template <typename T>
void stack<T>::push(const T & value) /*strong*/
{
	if (this->count_ == this->size_) {
		size_t array_size = (this->size_ * 3) / 2 + 1;

		stack temp(array_size);
		while (temp.count() < this->count_) {
			temp.push(this->ptr_[temp.count()]);
		}

		this->swap(temp);
	}
	construct(this->ptr_ + this->count_, value);
	++this->count_;
}

template<typename T>
const T & stack<T>::top() const /*strong*/
{
	if (this->count_ == 0) {
		throw ("top: count_ == 0");
	}
	return this->ptr_[this->count_ - 1];
}

template<typename T>
void stack<T>::pop() /*strong*/
{
	if (this->count_ == 0) {
		throw("pop(): count_ == 0");
	}
	destroy(&(this->ptr_[this->count_ - 1]));
	this->count_--;
}

template<typename T>
stack<T>::~stack() /*noexcept*/
{
	destroy(this->ptr_, this->ptr_ + this->count_);
}
{'fraction_non_alphanumeric': 0.18031044014458855, 'fraction_numerical': 0.0044652349564108015, 'mean_word_length': 2.8779884583676836, 'pattern_counts': {'":': 0, '<': 52, '<?xml version=': 0, '>': 99, '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': '6154370', 'n_tokens_mistral': 1725, 'n_tokens_neox': 1684, 'n_words': 427}