|
|
- #pragma once
- #include <initializer_list>
- #include <gp/buffer.hpp>
-
- namespace gp{
- template<typename T, std::size_t sz>
- class array{
- T ary[sz];
- public:
- using associated_iterator = pointer_iterator<T>;
- using associated_const_iterator = pointer_iterator<T>;
-
- array()
- : ary()
- {}
-
- template<typename ...U>
- array(U&& ...v)
- : ary{gp::forward(v...)}
- {}
-
- template<>
- array<T[sz]>(T (&& oth)[sz]) {
- gp::move_uninitialized(
- gp::nameless_range(oth, oth+sz),
- gp::nameless_range(*this)
- );
- }
-
- constexpr T& operator[] (size_t off)
- {
- if constexpr (gp_config::has_buffer_bounds)
- {
- gp_config::assertion(
- off < sz,
- "Array bounds infringed"
- );
- }
- return ary[off];
- }
-
- constexpr const T& operator[] (size_t off) const
- {
- return ary[off];
- }
-
- constexpr size_t size() const
- {
- return sz;
- }
-
- constexpr associated_iterator begin()
- {
- return associated_iterator(&ary[0]);
- }
-
- constexpr associated_iterator end()
- {
- return associated_iterator(&ary[sz]);
- }
-
- constexpr associated_const_iterator cbegin() const
- {
- return ary;
- }
-
- constexpr associated_const_iterator cend() const
- {
- return ary+sz;
- }
-
- constexpr bool operator==(const array& oth) const
- {
- for(size_t idx = 0; idx<sz; idx++)
- {
- if(ary[idx] != oth.ary[idx])
- {
- return false;
- }
- }
- return true;
- }
-
- constexpr bool operator!=(const array& oth) const
- {
- return !(*this == oth);
- }
-
- gp::buffer<T> as_buffer()
- {
- return gp::buffer<T>{(T*)ary, (T*)ary+sz};
- }
- };
- }
|