/* */ #pragma once template class slice { T* m_first; unsigned int m_len; public: slice(::std::vector& v): m_first(&v[0]), m_len(v.size()) {} ::std::vector to_vec() const { return ::std::vector(begin(), end()); } unsigned int size() const { return m_len; } T& operator[](unsigned int i) const { assert(i < m_len); return m_first[i]; } T* begin() const { return m_first; } T* end() const { return m_first + m_len; } }; template ::std::ostream& operator<<(::std::ostream& os, slice s) { if( s.size() > 0 ) { bool is_first = true; for( const auto& i : s ) { if(!is_first) os << ", "; is_first = false; os << i; } } return os; } namespace rust { template class option { bool m_set; T m_data; public: option(T ent): m_set(true), m_data( ::std::move(ent) ) {} option(): m_set(false) {} bool is_none() const { return !m_set; } bool is_some() const { return m_set; } const T& unwrap() const { assert(is_some()); return m_data; } }; template class option { T* m_ptr; public: option(T& ent): m_ptr(&ent) {} option(): m_ptr(nullptr) {} bool is_none() const { return m_ptr == nullptr; } bool is_some() const { return m_ptr != nullptr; } T& unwrap() const { assert(is_some()); return *m_ptr; } }; template option Some(T data) { return option( ::std::move(data) ); } template option None() { return option( ); } };