#pragma once
#include <vector>
#include <concepts>
namespace refl {
	template<typename T>
	class sarray {
	protected:
		const T* m_ptr;
		int m_size;
	public:
        constexpr sarray(const std::vector<T>& list) : m_ptr(&list.front()), m_size(list.size()) {}
        constexpr sarray() :m_ptr(nullptr), m_size(0) {}
        constexpr sarray(std::initializer_list<T> list) : m_ptr(list.begin()), m_size(list.size()) {}
		template<int N>
        constexpr sarray(const std::array<T, N>& arr):m_ptr(&arr[0]), m_size(arr.size()){}
		const T* get() const noexcept {
			return m_ptr;
		}
        const T* last()const noexcept {
            if (m_size > 0)
                return m_ptr + m_size - 1;
            return m_ptr;
        }
		const T* at(int i) const noexcept {
			if (i < m_size) {
				return m_ptr + i;
			}
			return nullptr;
		}
        constexpr int size() const noexcept {
			return m_size;
		}
        constexpr auto begin()const noexcept {
            return iterator{ m_ptr };
        }
        constexpr auto end() const noexcept {
            return iterator{ m_ptr + m_size};
        }
        // Iterator class
        class iterator {
        private:
            const T* ptr;

        public:
            constexpr iterator(const T* p) : ptr(p) {}

            // Overload ++ to move to next element
            constexpr iterator& operator++() noexcept{
                ++ptr;
                return *this;
            }
            //这里其实是--it,而不是it--
            constexpr iterator& operator--(int) noexcept {
                --ptr;
                return *this;
            }
            constexpr const T* operator->() const noexcept {
                return ptr;
            }
            // Overload * to dereference iterator
            constexpr const T& operator*() const noexcept {
                return *ptr;
            }

            // Overload != to compare iterators
            constexpr bool operator!=(const iterator& other) const noexcept {
                return ptr != other.ptr;
            }
        };
	};
}