/* */ #ifndef COMMON_HPP_INCLUDED #define COMMON_HPP_INCLUDED #include #include #include #include extern int g_debug_indent_level; #define FMT(ss) (dynamic_cast< ::std::stringstream&>(::std::stringstream() << ss).str()) #define INDENT() do { g_debug_indent_level += 1; } while(0) #define UNINDENT() do { g_debug_indent_level -= 1; } while(0) #define DEBUG(ss) do{ ::std::cerr << ::RepeatLitStr{" ", g_debug_indent_level} << __FUNCTION__ << ": " << ss << ::std::endl; } while(0) struct RepeatLitStr { const char *s; int n; friend ::std::ostream& operator<<(::std::ostream& os, const RepeatLitStr& r) { for(int i = 0; i < r.n; i ++ ) os << r.s; 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( ); } }; namespace std { template inline ::std::ostream& operator<<(::std::ostream& os, const ::std::vector& v) { if( v.size() > 0 ) { bool is_first = true; for( const auto& i : v ) { if(!is_first) os << ", "; is_first = false; os << i; } } return os; } } #endif