/* */ #ifndef COMMON_HPP_INCLUDED #define COMMON_HPP_INCLUDED #define FOREACH(basetype, it, src) for(basetype::const_iterator it = src.begin(); it != src.end(); ++ it) #define FOREACH_M(basetype, it, src) for(basetype::iterator it = src.begin(); it != src.end(); ++ it) #include #include #include #define DEBUG(ss) do{ ::std::cerr << __FUNCTION__ << ": " << ss << ::std::endl; } while(0) 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 AST { 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