template<typename T, size_t N>
requires (N > 0)
struct static_array {
using type = T;
using const_type = const type;
using pointer = type*;
using const_pointer = const_type*;
type arr[N];
static_array() noexcept(std::is_nothrow_default_constructible_v<type>)
requires std::is_default_constructible_v<type> {
}
static_array(std::initializer_list<type> il)
requires std::is_copy_constructible_v<type> : arr(std::forward<std::initializer_list<type>>(il)) {
if (il.size() != N) {
throw invalid_range();
}
}
static_array(const static_array& other) noexcept(std::is_nothrow_copy_constructible_v<type>)
requires std::is_copy_constructible_v<type> : arr(other.arr) {
}
pointer begin() noexcept {
return arr;
}
const_pointer begin() const noexcept {
return arr;
}
pointer end() noexcept {
return arr + N;
}
const_pointer end() const noexcept {
return arr + N;
}
static_array& operator=(const static_array& other) noexcept(std::is_nothrow_copy_assignable_v<type>)
requires std::is_copy_assignable_v<type> {
if (this == &other) {
return *this;
}
pointer iter = begin();
for (const_type& val : other) {
*iter = val;
++iter;
}
return *this;
}
template<typename U>
requires std::is_assignable_v<type, const U&>
static_array& operator=(const static_array<U, N>& other) noexcept(std::is_nothrow_assignable_v<type, const U&>) {
if (this == &other) {
return *this;
}
pointer iter = begin();
for (const U& val : other) {
*iter = val;
++iter;
}
return *this;
}
static_array& operator=(static_array&& other) noexcept
requires std::is_swappable_v<type> {
if (this == &other) {
return *this;
}
pointer iter = begin();
for (type& val : other) {
std::swap(*iter, val);
++iter;
}
return *this;
}
type& operator[](size_t index) {
if (!(index < N)) {
throw out_of_range();
}
return arr[index];
}
const_type& operator[](size_t index) const {
if (!(index < N)) {
throw out_of_range();
}
return arr[index];
}
};
version(dte_utils::static_array<char, 4> value = {0,0,0,0});
static_array(std::initializer_list<type> il)
requires std::is_copy_constructible_v<type> : arr(std::forward<std::initializer_list<type>>(il))
возникает ошибка:#include <initializer_list>
namespace dte_utils {
template<typename T, size_t N>
requires (N > 0)
struct static_array {
using type = T;
using const_type = const type;
using pointer = type*;
using const_pointer = const_type*;
type arr[N];
static_array() noexcept(std::is_nothrow_default_constructible_v<type>)
requires std::is_default_constructible_v<type> {
pointer iter = end();
while (iter != begin()) {
place_at(--iter);
}
}
template<typename U>
requires std::is_constructible_v<type, const U&>
static_array(const U (&arr)[N]) noexcept(std::is_nothrow_constructible_v<type, const U&>) {
pointer iter = begin();
for (const U& val : arr) {
place_at(iter, val);
++iter;
}
}
static_array(std::initializer_list<type> il)
requires std::is_copy_constructible_v<type> {
if (il.size() != N) {
throw invalid_range();
}
pointer iter = begin();
for (const_type& val : il) {
place_at(iter, val);
++iter;
}
}
static_array(const static_array& other) noexcept(std::is_nothrow_copy_constructible_v<type>)
requires std::is_copy_constructible_v<type> {
pointer iter = begin();
for (const_type& val : other) {
place_at(iter, val);
++iter;
}
}
template<typename U>
requires std::is_constructible_v<type, const U&>
static_array(const static_array<U, N> other) noexcept(std::is_nothrow_constructible_v<type, const U&>) {
pointer iter = begin();
for (const U& val : other) {
place_at(iter, val);
++iter;
}
}
pointer begin() noexcept {
return arr;
}
const_pointer begin() const noexcept {
return arr;
}
pointer end() noexcept {
return arr + N;
}
const_pointer end() const noexcept {
return arr + N;
}
static_array& operator=(const static_array& other) noexcept(std::is_nothrow_copy_assignable_v<type>)
requires std::is_copy_assignable_v<type> {
if (this == &other) {
return *this;
}
pointer iter = begin();
for (const_type& val : other) {
*iter = val;
++iter;
}
return *this;
}
template<typename U>
requires std::is_assignable_v<type, const U&>
static_array& operator=(const static_array<U, N>& other) noexcept(std::is_nothrow_assignable_v<type, const U&>) {
if (this == &other) {
return *this;
}
pointer iter = begin();
for (const U& val : other) {
*iter = val;
++iter;
}
return *this;
}
static_array& operator=(static_array&& other) noexcept
requires std::is_swappable_v<type> {
if (this == &other) {
return *this;
}
pointer iter = begin();
for (type& val : other) {
std::swap(*iter, val);
++iter;
}
return *this;
}
type& operator[](size_t index) {
if (!(index < N)) {
throw out_of_range();
}
return arr[index];
}
const_type& operator[](size_t index) const {
if (!(index < N)) {
throw out_of_range();
}
return arr[index];
}
};
}
namespace dte_token {
struct data_stack;
struct c_function {
struct metadata {
dte_utils::dynamic_cstring name;
//max jump index this function can output
size_t max_jump;
//size of data type pushed on stack
//if it is <=sizeof(void*) uses casted void* as data
size_t data_size_push;
};
using func = size_t(data_stack&, const semi_pointer::data&);
protected:
metadata _meta;
func* _body;
destructor* _args_destructor;
public:
c_function(func* body, const metadata& meta, destructor* args_destructor = nullptr);
c_function(func* body, metadata&& meta, destructor* args_destructor = nullptr);
c_function(const c_function& other) : _meta(other.get_meta()), _body(other.get_body()), _args_destructor(other.get_args_destructor()) {};
c_function(c_function&& other) noexcept;
const metadata& get_meta() const noexcept;
func* get_body() const noexcept;
destructor* get_args_destructor() const noexcept;
c_function& operator=(const c_function&) = delete;
c_function& operator=(c_function&&) = delete;
size_t operator()(data_stack& stack, const semi_pointer::data& spd) const;
};
}
using namespace dte_utils;
using namespace dte_token;
c_function::c_function(func* body, const metadata& meta, destructor* args_destructor) : _body(body), _meta(meta), _args_destructor(args_destructor) {}
c_function::c_function(func* body, metadata&& meta, destructor* args_destructor) : _body(body), _meta(std::move(meta)), _args_destructor(args_destructor) {}
c_function::c_function(c_function&& other) noexcept : _body(other._body), _meta(std::move(other._meta)) {}
const c_function::metadata& c_function::get_meta() const noexcept {
return _meta;
}
c_function::func* c_function::get_body() const noexcept {
return _body;
}
destructor* c_function::get_args_destructor() const noexcept {
return _args_destructor;
}
size_t c_function::operator()(data_stack& stack, const semi_pointer::data& spd) const {
return _body(stack, spd);
}
type arr[N];