All pastes #1590534 Raw Edit

無名

public cpp v1 · immutable
#1590534 ·published 2009-10-03 13:16 UTC
rendered paste body
#include <iostream>#include <map>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 <typename _Tcoeff, typename _Texp>		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<literal_value, _Texp>::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<literal_value, _Texp>::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<literal_value, _Texp>::value_type(it->first, it->second));					}				}				return tmp;			}		private:			_Tcoeff _coeff;			map<literal_value, _Texp> _factor;		};		typedef basic_monomial_expression<double, double> 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;}