
I found numeric::ublas::promote_traits to be pretty useful. This tiny addition is also useful to go the other direction: #include <complex> template<typename T> struct Scalar { typedef T type; }; template<typename T> struct Scalar<std::complex<T> > { typedef T type; };

"Neal D. Becker" <ndbecker2@verizon.net> wrote
I found numeric::ublas::promote_traits to be pretty useful. This tiny addition is also useful to go the other direction:
#include <complex>
template<typename T> struct Scalar { typedef T type; };
template<typename T> struct Scalar<std::complex<T> > { typedef T type; };
I found this scheme useful to do this job. BTW, works as is on complex because complex has a value_type member: Only needs to be specialised if UDT has no value_type member typedef: template <typename T> struct to_arithmetic; /// whatever name... namespace detail{ template<bool Condition,typename T> struct apply_value_type_if; // if T is not arithmetic // recursively apply to get to arithmetic type template<typename T> struct apply_value_type_if<true,T>{ typedef typename to_arithmetic< typename T::value_type >::type type; }; //if T is arithmetic template<typename T> struct apply_value_type_if<false,T>{ typedef T type; }; } template <typename T> struct to_arithmetic : detail::apply_value_type_if< (boost::is_arithmetic<T>::value == false), T >{}; regards Andy Little
participants (2)
-
Andy Little
-
Neal D. Becker