/* * memoy_string.hpp * * Created on: 08.10.2017 * Author: julian */ #ifndef MEMORY_STRING_HPP_ #define MEMORY_STRING_HPP_ #include class MemoryString { template struct _iterator : public std::iterator { T* pos; _iterator operator++(int){ _iterator temp(*this); pos++; return temp; } _iterator operator--(int){ _iterator temp(*this); pos--; return temp; } _iterator &operator++() { pos++; return *this; } _iterator &operator--() { pos--; return *this; } _iterator &operator+=(int i) { pos += i; return *this; } _iterator &operator-=(int i) { pos -= i; return *this; } _iterator operator+(int i) { _iterator temp(*this); temp += i; return temp; } _iterator operator-(int i) { _iterator temp(*this); temp -= i; return temp; } T operator*() { return *pos; } T operator*() const { return *pos; } T * operator&() { return pos; } T * operator->() { return pos; } template _iterator(const _iterator &other) { *this = other; } template _iterator &operator=(const _iterator &other) const { if (this != &other) pos = other.pos; return *this; } template bool operator==(const _iterator &other) const { return pos == other.pos; } template bool operator!=(const _iterator &other) const { return pos != other.pos; } private: _iterator(T *pos) : pos(pos) {} friend MemoryString; }; public: typedef size_t size_type; typedef char value_type; typedef _iterator const_iterator; typedef _iterator iterator; MemoryString(value_type * base, size_type size): _ptr(base), _size(size) {} ~MemoryString() {} iterator begin() { return iterator(_ptr); } const_iterator begin() const { return const_iterator(_ptr); } iterator end() { return iterator(_ptr + _size); } const_iterator end() const { return const_iterator(_ptr + _size); } size_type size() { return _size; } protected: value_type * _ptr; size_type _size; }; #endif /* MEMORY_STRING_HPP_ */