New version

This commit is contained in:
Morten Delenk 2016-09-03 17:58:38 +02:00
parent e9975cc218
commit 8aa094bf5f
No known key found for this signature in database
GPG key ID: 3F818D0F65DCB490
4 changed files with 61 additions and 275 deletions

53
array.hpp Normal file
View file

@ -0,0 +1,53 @@
#pragma once
#include <nall/range.hpp>
namespace nall {
template<typename T, uint Capacity>
struct array {
auto capacity() const -> uint { return Capacity; }
auto size() const -> uint { return _size; }
auto reset() -> void {
for(uint n : range(_size)) _pool.t[n].~T();
_size = 0;
}
auto operator[](uint index) -> T& {
return _pool.t[index];
}
auto operator[](uint index) const -> const T& {
return _pool.t[index];
}
auto append() -> T& {
new(_pool.t + _size) T;
return _pool.t[_size++];
}
auto append(const T& value) -> void {
new(_pool.t + _size++) T(value);
}
auto append(T&& value) -> void {
new(_pool.t + _size++) T(move(value));
}
auto begin() { return &_pool.t[0]; }
auto end() { return &_pool.t[_size]; }
auto begin() const { return &_pool.t[0]; }
auto end() const { return &_pool.t[_size]; }
private:
union U {
U() {}
~U() {}
T t[Capacity];
} _pool;
uint _size = 0;
};
}

View file

@ -15,6 +15,7 @@
#include <nall/algorithm.hpp> #include <nall/algorithm.hpp>
#include <nall/any.hpp> #include <nall/any.hpp>
#include <nall/array.hpp>
#include <nall/atoi.hpp> #include <nall/atoi.hpp>
#include <nall/bit.hpp> #include <nall/bit.hpp>
#include <nall/bit-field.hpp> #include <nall/bit-field.hpp>

View file

@ -59,6 +59,7 @@ template<uint Bits> struct Natural {
struct Reference { struct Reference {
inline Reference(Natural& source, uint lo, uint hi) : source(source), Lo(lo), Hi(hi) {} inline Reference(Natural& source, uint lo, uint hi) : source(source), Lo(lo), Hi(hi) {}
inline auto& operator=(Reference& source) { return set(source.get()); }
inline auto get() const -> type { inline auto get() const -> type {
const type RangeBits = Hi - Lo + 1; const type RangeBits = Hi - Lo + 1;
@ -85,8 +86,8 @@ template<uint Bits> struct Natural {
inline auto& operator *=(const type value) { return set(get() * value); } inline auto& operator *=(const type value) { return set(get() * value); }
inline auto& operator /=(const type value) { return set(get() / value); } inline auto& operator /=(const type value) { return set(get() / value); }
inline auto& operator %=(const type value) { return set(get() % value); } inline auto& operator %=(const type value) { return set(get() % value); }
inline auto& operator++(int) { auto value = get(); set(value + 1); return value; } inline auto operator++(int) { auto value = get(); set(value + 1); return value; }
inline auto& operator--(int) { auto value = get(); set(value - 1); return value; } inline auto operator--(int) { auto value = get(); set(value - 1); return value; }
inline auto& operator++() { return set(get() + 1); } inline auto& operator++() { return set(get() + 1); }
inline auto& operator--() { return set(get() - 1); } inline auto& operator--() { return set(get() - 1); }
@ -162,6 +163,7 @@ template<uint Bits> struct Integer {
struct Reference { struct Reference {
inline Reference(Integer& source, uint lo, uint hi) : source(source), Lo(lo), Hi(hi) {} inline Reference(Integer& source, uint lo, uint hi) : source(source), Lo(lo), Hi(hi) {}
inline auto& operator=(const Reference& source) { return set(source.get()); }
inline auto get() const -> utype { inline auto get() const -> utype {
const type RangeBits = Hi - Lo + 1; const type RangeBits = Hi - Lo + 1;
@ -188,8 +190,8 @@ template<uint Bits> struct Integer {
inline auto& operator *=(const utype value) { return set(get() * value); } inline auto& operator *=(const utype value) { return set(get() * value); }
inline auto& operator /=(const utype value) { return set(get() / value); } inline auto& operator /=(const utype value) { return set(get() / value); }
inline auto& operator %=(const utype value) { return set(get() % value); } inline auto& operator %=(const utype value) { return set(get() % value); }
inline auto& operator++(int) { auto value = get(); set(value + 1); return value; } inline auto operator++(int) { auto value = get(); set(value + 1); return value; }
inline auto& operator--(int) { auto value = get(); set(value - 1); return value; } inline auto operator--(int) { auto value = get(); set(value - 1); return value; }
inline auto& operator++() { return set(get() + 1); } inline auto& operator++() { return set(get() + 1); }
inline auto& operator--() { return set(get() - 1); } inline auto& operator--() { return set(get() - 1); }
@ -260,271 +262,7 @@ private:
using boolean = nall::Boolean; using boolean = nall::Boolean;
using natural = nall::Natural<sizeof(uint) * 8>; using natural = nall::Natural<sizeof(uint) * 8>;
using integer = nall::Integer<sizeof( int) * 8>; using integer = nall::Integer<sizeof(int) * 8>;
using real = nall::Real<sizeof(double) * 8>; using real = nall::Real<sizeof(double) * 8>;
using natural1 = nall::Natural< 1>;
using natural2 = nall::Natural< 2>;
using natural3 = nall::Natural< 3>;
using natural4 = nall::Natural< 4>;
using natural5 = nall::Natural< 5>;
using natural6 = nall::Natural< 6>;
using natural7 = nall::Natural< 7>;
using natural8 = nall::Natural< 8>;
using natural9 = nall::Natural< 9>;
using natural10 = nall::Natural<10>;
using natural11 = nall::Natural<11>;
using natural12 = nall::Natural<12>;
using natural13 = nall::Natural<13>;
using natural14 = nall::Natural<14>;
using natural15 = nall::Natural<15>;
using natural16 = nall::Natural<16>;
using natural17 = nall::Natural<17>;
using natural18 = nall::Natural<18>;
using natural19 = nall::Natural<19>;
using natural20 = nall::Natural<20>;
using natural21 = nall::Natural<21>;
using natural22 = nall::Natural<22>;
using natural23 = nall::Natural<23>;
using natural24 = nall::Natural<24>;
using natural25 = nall::Natural<25>;
using natural26 = nall::Natural<26>;
using natural27 = nall::Natural<27>;
using natural28 = nall::Natural<28>;
using natural29 = nall::Natural<29>;
using natural30 = nall::Natural<30>;
using natural31 = nall::Natural<31>;
using natural32 = nall::Natural<32>;
using natural33 = nall::Natural<33>;
using natural34 = nall::Natural<34>;
using natural35 = nall::Natural<35>;
using natural36 = nall::Natural<36>;
using natural37 = nall::Natural<37>;
using natural38 = nall::Natural<38>;
using natural39 = nall::Natural<39>;
using natural40 = nall::Natural<40>;
using natural41 = nall::Natural<41>;
using natural42 = nall::Natural<42>;
using natural43 = nall::Natural<43>;
using natural44 = nall::Natural<44>;
using natural45 = nall::Natural<45>;
using natural46 = nall::Natural<46>;
using natural47 = nall::Natural<47>;
using natural48 = nall::Natural<48>;
using natural49 = nall::Natural<49>;
using natural50 = nall::Natural<50>;
using natural51 = nall::Natural<51>;
using natural52 = nall::Natural<52>;
using natural53 = nall::Natural<53>;
using natural54 = nall::Natural<54>;
using natural55 = nall::Natural<55>;
using natural56 = nall::Natural<56>;
using natural57 = nall::Natural<57>;
using natural58 = nall::Natural<58>;
using natural59 = nall::Natural<59>;
using natural60 = nall::Natural<60>;
using natural61 = nall::Natural<61>;
using natural62 = nall::Natural<62>;
using natural63 = nall::Natural<63>;
using natural64 = nall::Natural<64>;
using integer1 = nall::Integer< 1>;
using integer2 = nall::Integer< 2>;
using integer3 = nall::Integer< 3>;
using integer4 = nall::Integer< 4>;
using integer5 = nall::Integer< 5>;
using integer6 = nall::Integer< 6>;
using integer7 = nall::Integer< 7>;
using integer8 = nall::Integer< 8>;
using integer9 = nall::Integer< 9>;
using integer10 = nall::Integer<10>;
using integer11 = nall::Integer<11>;
using integer12 = nall::Integer<12>;
using integer13 = nall::Integer<13>;
using integer14 = nall::Integer<14>;
using integer15 = nall::Integer<15>;
using integer16 = nall::Integer<16>;
using integer17 = nall::Integer<17>;
using integer18 = nall::Integer<18>;
using integer19 = nall::Integer<19>;
using integer20 = nall::Integer<20>;
using integer21 = nall::Integer<21>;
using integer22 = nall::Integer<22>;
using integer23 = nall::Integer<23>;
using integer24 = nall::Integer<24>;
using integer25 = nall::Integer<25>;
using integer26 = nall::Integer<26>;
using integer27 = nall::Integer<27>;
using integer28 = nall::Integer<28>;
using integer29 = nall::Integer<29>;
using integer30 = nall::Integer<30>;
using integer31 = nall::Integer<31>;
using integer32 = nall::Integer<32>;
using integer33 = nall::Integer<33>;
using integer34 = nall::Integer<34>;
using integer35 = nall::Integer<35>;
using integer36 = nall::Integer<36>;
using integer37 = nall::Integer<37>;
using integer38 = nall::Integer<38>;
using integer39 = nall::Integer<39>;
using integer40 = nall::Integer<40>;
using integer41 = nall::Integer<41>;
using integer42 = nall::Integer<42>;
using integer43 = nall::Integer<43>;
using integer44 = nall::Integer<44>;
using integer45 = nall::Integer<45>;
using integer46 = nall::Integer<46>;
using integer47 = nall::Integer<47>;
using integer48 = nall::Integer<48>;
using integer49 = nall::Integer<49>;
using integer50 = nall::Integer<50>;
using integer51 = nall::Integer<51>;
using integer52 = nall::Integer<52>;
using integer53 = nall::Integer<53>;
using integer54 = nall::Integer<54>;
using integer55 = nall::Integer<55>;
using integer56 = nall::Integer<56>;
using integer57 = nall::Integer<57>;
using integer58 = nall::Integer<58>;
using integer59 = nall::Integer<59>;
using integer60 = nall::Integer<60>;
using integer61 = nall::Integer<61>;
using integer62 = nall::Integer<62>;
using integer63 = nall::Integer<63>;
using integer64 = nall::Integer<64>;
using real32 = nall::Real<32>;
using real64 = nall::Real<64>;
//using real80 = nall::Real<80>;
} }
using int1 = nall::Integer< 1>;
using int2 = nall::Integer< 2>;
using int3 = nall::Integer< 3>;
using int4 = nall::Integer< 4>;
using int5 = nall::Integer< 5>;
using int6 = nall::Integer< 6>;
using int7 = nall::Integer< 7>;
using int8 = nall::Integer< 8>;
using int9 = nall::Integer< 9>;
using int10 = nall::Integer<10>;
using int11 = nall::Integer<11>;
using int12 = nall::Integer<12>;
using int13 = nall::Integer<13>;
using int14 = nall::Integer<14>;
using int15 = nall::Integer<15>;
using int16 = nall::Integer<16>;
using int17 = nall::Integer<17>;
using int18 = nall::Integer<18>;
using int19 = nall::Integer<19>;
using int20 = nall::Integer<20>;
using int21 = nall::Integer<21>;
using int22 = nall::Integer<22>;
using int23 = nall::Integer<23>;
using int24 = nall::Integer<24>;
using int25 = nall::Integer<25>;
using int26 = nall::Integer<26>;
using int27 = nall::Integer<27>;
using int28 = nall::Integer<28>;
using int29 = nall::Integer<29>;
using int30 = nall::Integer<30>;
using int31 = nall::Integer<31>;
using int32 = nall::Integer<32>;
using int33 = nall::Integer<33>;
using int34 = nall::Integer<34>;
using int35 = nall::Integer<35>;
using int36 = nall::Integer<36>;
using int37 = nall::Integer<37>;
using int38 = nall::Integer<38>;
using int39 = nall::Integer<39>;
using int40 = nall::Integer<40>;
using int41 = nall::Integer<41>;
using int42 = nall::Integer<42>;
using int43 = nall::Integer<43>;
using int44 = nall::Integer<44>;
using int45 = nall::Integer<45>;
using int46 = nall::Integer<46>;
using int47 = nall::Integer<47>;
using int48 = nall::Integer<48>;
using int49 = nall::Integer<49>;
using int50 = nall::Integer<50>;
using int51 = nall::Integer<51>;
using int52 = nall::Integer<52>;
using int53 = nall::Integer<53>;
using int54 = nall::Integer<54>;
using int55 = nall::Integer<55>;
using int56 = nall::Integer<56>;
using int57 = nall::Integer<57>;
using int58 = nall::Integer<58>;
using int59 = nall::Integer<59>;
using int60 = nall::Integer<60>;
using int61 = nall::Integer<61>;
using int62 = nall::Integer<62>;
using int63 = nall::Integer<63>;
using int64 = nall::Integer<64>;
using uint1 = nall::Natural< 1>;
using uint2 = nall::Natural< 2>;
using uint3 = nall::Natural< 3>;
using uint4 = nall::Natural< 4>;
using uint5 = nall::Natural< 5>;
using uint6 = nall::Natural< 6>;
using uint7 = nall::Natural< 7>;
using uint8 = nall::Natural< 8>;
using uint9 = nall::Natural< 9>;
using uint10 = nall::Natural<10>;
using uint11 = nall::Natural<11>;
using uint12 = nall::Natural<12>;
using uint13 = nall::Natural<13>;
using uint14 = nall::Natural<14>;
using uint15 = nall::Natural<15>;
using uint16 = nall::Natural<16>;
using uint17 = nall::Natural<17>;
using uint18 = nall::Natural<18>;
using uint19 = nall::Natural<19>;
using uint20 = nall::Natural<20>;
using uint21 = nall::Natural<21>;
using uint22 = nall::Natural<22>;
using uint23 = nall::Natural<23>;
using uint24 = nall::Natural<24>;
using uint25 = nall::Natural<25>;
using uint26 = nall::Natural<26>;
using uint27 = nall::Natural<27>;
using uint28 = nall::Natural<28>;
using uint29 = nall::Natural<29>;
using uint30 = nall::Natural<30>;
using uint31 = nall::Natural<31>;
using uint32 = nall::Natural<32>;
using uint33 = nall::Natural<33>;
using uint34 = nall::Natural<34>;
using uint35 = nall::Natural<35>;
using uint36 = nall::Natural<36>;
using uint37 = nall::Natural<37>;
using uint38 = nall::Natural<38>;
using uint39 = nall::Natural<39>;
using uint40 = nall::Natural<40>;
using uint41 = nall::Natural<41>;
using uint42 = nall::Natural<42>;
using uint43 = nall::Natural<43>;
using uint44 = nall::Natural<44>;
using uint45 = nall::Natural<45>;
using uint46 = nall::Natural<46>;
using uint47 = nall::Natural<47>;
using uint48 = nall::Natural<48>;
using uint49 = nall::Natural<49>;
using uint50 = nall::Natural<50>;
using uint51 = nall::Natural<51>;
using uint52 = nall::Natural<52>;
using uint53 = nall::Natural<53>;
using uint54 = nall::Natural<54>;
using uint55 = nall::Natural<55>;
using uint56 = nall::Natural<56>;
using uint57 = nall::Natural<57>;
using uint58 = nall::Natural<58>;
using uint59 = nall::Natural<59>;
using uint60 = nall::Natural<60>;
using uint61 = nall::Natural<61>;
using uint62 = nall::Natural<62>;
using uint63 = nall::Natural<63>;
using uint64 = nall::Natural<64>;

View file

@ -62,10 +62,4 @@ static_assert(sizeof(float) >= 4, "float32_t is not of the correct size")
static_assert(sizeof(double) >= 8, "float64_t is not of the correct size"); static_assert(sizeof(double) >= 8, "float64_t is not of the correct size");
//static_assert(sizeof(long double) >= 10, "float80_t is not of the correct size"); //static_assert(sizeof(long double) >= 10, "float80_t is not of the correct size");
using intmax = intmax_t;
using intptr = intptr_t;
using uintmax = uintmax_t;
using uintptr = uintptr_t;
using uint = unsigned int; using uint = unsigned int;