diff --git a/include/cow/slice.hpp b/include/cow/slice.hpp index bd8fbf7..76a3ab1 100644 --- a/include/cow/slice.hpp +++ b/include/cow/slice.hpp @@ -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 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(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; diff --git a/src/test/main.cpp b/src/test/main.cpp index a83b1ef..15d1753 100644 --- a/src/test/main.cpp +++ b/src/test/main.cpp @@ -4,14 +4,8 @@ #include #include -#include +using namespace _cow_util; -int main() -{ - return 0; -} - -/* template void print_slice(Slice 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; -}*/ +}