slice conversion operators

cpp
Avril 4 years ago
parent eb45ce7212
commit b628571ed9
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -34,6 +34,8 @@ namespace _cow_util {
inline T& operator*() { return (*this)[0]; }
inline const T& operator*() const { return (*this)[0]; }
inline operator const T*() const { return &(*this)[0]; }
inline operator T*() { return &(*this)[0]; }
template<typename U>
inline U* area_as() requires(sizeof(T) % sizeof(U) == 0) { return (U*)area(); }
@ -45,6 +47,9 @@ namespace _cow_util {
struct Slice;
inline operator Slice() { return Slice(ptr(), size()); }
inline operator const Slice() const { return Slice(const_cast<T*>(ptr()), size()); }
inline bool bounds_ok(size_t start) const
{
return start < size();
@ -101,8 +106,7 @@ namespace _cow_util {
inline const void* area() const override { return _area; }
inline void* area() override { return _area; }
inline size_t size() const override { return _size; }
private:
void* const _area;
const size_t _size;

@ -4,14 +4,8 @@
#include <cstdlib>
#include <cstring>
#include <array>
using namespace _cow_util;
int main()
{
return 0;
}
/*
template<typename T = unsigned char>
void print_slice(Slice<T> memory)
{
@ -40,8 +34,10 @@ void moving_cow(Cow moved)
int main()
{
Cow real(4096);
memset(real, 0, real.size_bytes());
printf("Created real: ");
print_slice(real);
print_slice(real.slice_wrap(-20, -10));
write_fake(real, "Hello world");
@ -63,4 +59,4 @@ int main()
read_fake(clone); //clone still functions because of refcount on origin.
return 0;
}*/
}

Loading…
Cancel
Save