00001
00002
00003
00004
00005
00006
00007
00008 #ifndef mmx_assign_hpp
00009 #define mmx_assign_hpp
00010
00011 #include <cstdlib>
00012 #include <complex>
00013 #include <iostream>
00014
00015 namespace std {template<class C> struct complex;}
00016
00017 namespace mmx {
00018
00019 #ifndef WITH_AS
00020 #define WITH_AS
00021 template<typename T,typename F> struct as_helper {
00022 static inline T cv (const F& x) { return T(x); }
00023 };
00024 template<typename T,typename F> inline T as (const F& x) {
00025 return as_helper<T,F>::cv (x);
00026 }
00027
00028 template<typename T,typename F, class U> inline T
00029 as (const F& x, const U& u) {
00030 return as_helper<T,F>::cv (x,u);
00031 }
00032
00033 template<typename T,typename F, class U, class V> inline T
00034 as (const F& x, const U& u, const V& v) {
00035 return as_helper<T,F>::cv (x,u,v);
00036 }
00037 #endif
00038
00039
00041
00047 namespace let {
00048
00049
00050
00052 template<class A, class B> inline void assign(A& a, const B & b) {
00053 a=as<A>(b);
00054 }
00055 inline void assign( int & a, double d ) { a = (int)rint(d); };
00056
00057 inline void assign(double & d, int i) {d = double(i);}
00058 inline void assign(double & d, unsigned i) {d = double(i);}
00059 inline void assign(double & d, double z) {d = z;}
00060
00061 template<class C> inline void
00062 assign(std::complex<C> & z, const C& x) { z= std::complex<C>(x);}
00063
00064 template<class X> inline void assign(X & a, const char *s) { a = X(s); }
00065
00066 template<> inline void assign(int &i, const char *s) {i = atoi(s);}
00067 template<> inline void assign(long int &i, const char *s) {i = atol(s);}
00068
00069 #ifndef __CYGWIN__
00070 template<> inline void assign(long long int &i, const char *s) {i = atoll(s);}
00071 #endif //__CYGWIN__
00072
00073
00074 inline void assign(float & d, char* s) {d = atof(s);}
00075
00076 inline void assign(double & d, char* s) {d = atof(s);}
00077
00078 inline void assign(long double & d, char *s) {d = atof(s);}
00079
00080 inline void
00081 assign(std::complex<double> & z, const char* s) {
00082 z = std::complex<double>(atof(s),0);
00083 }
00084
00085 }
00086
00087 }
00088
00089 #endif // realroot_assign_hpp
00090