#include #include namespace nvsofts { namespace expression { using namespace std; class literal_value { public: literal_value(char ch) : _ch(ch) {} char get_ch(void) { return _ch; } bool operator==(const literal_value& obj) const { return (this->_ch == obj._ch); } bool operator!=(const literal_value& obj) const { return (this->_ch != obj._ch); } bool operator<(const literal_value& obj) const { return (this->_ch < obj._ch); } bool operator<=(const literal_value& obj) const { return (this->_ch <= obj._ch); } bool operator>(const literal_value& obj) const { return (this->_ch > obj._ch); } bool operator>=(const literal_value& obj) const { return (this->_ch >= obj._ch); } private: char _ch; }; literal_value _a = literal_value('a'); template class basic_monomial_expression { public: basic_monomial_expression() : _coeff(), _factor() {} basic_monomial_expression<_Tcoeff, _Texp>& operator=(const basic_monomial_expression<_Tcoeff, _Texp>& obj) { this->_coeff = obj._coeff; this->_factor = obj._factor; return *this; } basic_monomial_expression<_Tcoeff, _Texp>& operator=(const literal_value& obj) { this->_coeff = 1; this->_factor.insert(map::value_type(obj, 1)); return *this; } basic_monomial_expression<_Tcoeff, _Texp> operator*(const basic_monomial_expression<_Tcoeff, _Texp>& obj) { basic_monomial_expression<_Tcoeff, _Texp> tmp; tmp._coeff = this->_coeff * obj._coeff; tmp._factor.insert(this->_factor.begin(), this->_factor.end()); for (map::const_iterator it = obj._factor.begin(); it != obj._factor.end(); it++) { if (tmp._factor.count(it->first)) { tmp._factor[it->first] += it->second; }else{ tmp._factor.insert(map::value_type(it->first, it->second)); } } return tmp; } private: _Tcoeff _coeff; map _factor; }; typedef basic_monomial_expression monomial_expression; } } using namespace nvsofts::expression; int main(int argc, char* argv[]) { monomial_expression expr; monomial_expression expr2; monomial_expression expr3; expr = _a; // a expr2 = _a; // a expr3 = expr * expr2; // a^2 return 0; }