diff options
| author | John Hodge <tpg@mutabah.net> | 2016-04-30 12:10:35 +0800 |
|---|---|---|
| committer | John Hodge <tpg@mutabah.net> | 2016-04-30 12:10:35 +0800 |
| commit | f5c9ee756d97fb8c02fd74faeab7a50907de6690 (patch) | |
| tree | 854f70f73fdfb23fccca203f0136febdec57e50d /src/include | |
| parent | bce9d5618eb54201cef08b1ba158d267cdef0b4f (diff) | |
| download | mrust-f5c9ee756d97fb8c02fd74faeab7a50907de6690.tar.gz | |
Resolve - Further work on use/index.
- Use recurses into (some) code blocks
- Index does three passes to reduce the chance of wildcard import troubles. (HACK)
Diffstat (limited to 'src/include')
| -rw-r--r-- | src/include/rustic.hpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/include/rustic.hpp b/src/include/rustic.hpp index 15588565..3b4a0386 100644 --- a/src/include/rustic.hpp +++ b/src/include/rustic.hpp @@ -8,10 +8,22 @@ class slice T* m_first; unsigned int m_len; public: + slice(): + m_first(nullptr), + m_len(0) + {} + slice(const ::std::vector<T>& v): + m_first(&v[0]), + m_len(v.size()) + {} slice(::std::vector<T>& v): m_first(&v[0]), m_len(v.size()) {} + slice(T* ptr, unsigned int len): + m_first(ptr), + m_len(len) + {} ::std::vector<T> to_vec() const { return ::std::vector<T>(begin(), end()); @@ -24,9 +36,18 @@ public: assert(i < m_len); return m_first[i]; } + slice<T> subslice(unsigned int ofs, unsigned int len) const { + assert(ofs < m_len); + assert(len <= m_len); + assert(ofs + len <= m_len); + return slice { m_first + ofs, len }; + } T* begin() const { return m_first; } T* end() const { return m_first + m_len; } + + T& front() const { return m_first[0]; } + T& back() const { return m_first[m_len-1]; } }; template<typename T> |
