General Purpose library for Freestanding C++ and POSIX systems
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 

100 satır
1.8 KiB

#pragma once
#include <stddef.h>
#include <stdint.h>
enum class iterator_type_t{
contiguous_iterator,
non_contiguous_iterator,
lazy_iterator
};
template<typename T>
struct pointer_iterator final
{
T* data;
typedef T value_type;
typedef std::size_t difference_type;
static constexpr iterator_type_t iterator_type = iterator_type_t::contiguous_iterator;
constexpr pointer_iterator(const pointer_iterator& oth)
: data{oth.data}
{}
constexpr pointer_iterator(T* ptr)
: data{ptr}
{}
constexpr operator T&()
{
return *data;
}
constexpr T& operator*(){
return *data;
}
constexpr pointer_iterator operator++()
{
return pointer_iterator{++data};
}
constexpr pointer_iterator operator++(int)
{
return pointer_iterator{data++};
}
constexpr pointer_iterator operator--()
{
return pointer_iterator{--data};
}
constexpr pointer_iterator operator--(int)
{
return pointer_iterator{data--};
}
constexpr pointer_iterator operator+(const std::size_t offset)
{
return pointer_iterator{data+offset};
}
constexpr pointer_iterator operator+(const int offset)
{
return pointer_iterator{data+offset};
}
constexpr pointer_iterator operator-(const std::size_t offset)
{
return pointer_iterator{data-offset};
}
constexpr pointer_iterator operator-(const int offset)
{
return pointer_iterator{data-offset};
}
constexpr difference_type operator-(const pointer_iterator& oth) const
{
return (T*)data-(T*)oth.data;
}
constexpr bool operator==(const pointer_iterator& oth)
{
return data==oth.data;
}
constexpr bool operator!=(pointer_iterator& oth)
{
return data!=oth.data;
}
constexpr bool before_or_equal(const pointer_iterator& oth)
{
return reinterpret_cast<std::intptr_t>(data) <= reinterpret_cast<std::intptr_t>(oth.data);
}
constexpr bool operator<=(const pointer_iterator& oth)
{
return before_or_equal(oth);
}
};