c++/feature: make possible for each for RustSlice
@@ -92,14 +92,56 @@ class RustSlice final : private CContainerType {
public:
using value_type = typename std::remove_const<
typename std::remove_reference<decltype(*internal::field_type(&CContainerType::data))>::type>::type;
+ using iterator = value_type *;
+ using const_iterator = const value_type *;
explicit RustSlice(const CContainerType &o) noexcept
{
this->data = o.data;
this->len = o.len;
}
+ RustSlice(const RustSlice &) = delete;
+ RustSlice &operator=(const RustSlice &) = delete;
+ RustSlice(RustSlice &&o) noexcept
+ {
+ this->data = o.data;
+ this->len = o.len;
+
+ reset(o);
+ }
+ RustSlice &operator=(RustSlice &&o) noexcept
+ {
+ this->data = o.data;
+ this->len = o.len;
+
+ reset(o);
+ return *this;
+ }
size_t size() const noexcept { return this->len; }
bool empty() const noexcept { return this->len == 0; }
const value_type &operator[](size_t i) const noexcept { return this->data[i]; }
+ iterator begin() noexcept
+ {
+ return this->data;
+ }
+ const_iterator begin() const noexcept
+ {
+ return this->data;
+ }
+ iterator end() noexcept
+ {
+ return this->data + this->len;
+ }
+ const_iterator end() const noexcept
+ {
+ return this->data + this->len;
+ }
+
+private:
+ static void reset(RustSlice &o) noexcept
+ {
+ o.data = nullptr;
+ o.len = 0;
+ }
};
template <typename CContainerType, void (*FreeFunc)(CContainerType)>
