#ifndef glas_abs_hpp #define glas_abs_hpp #include #include #include #include #include #ifdef GLAS_COMPLEX # include #endif #include namespace glas { template struct abs_functor { typedef T argument_type ; typedef T result_type ; //BOOST_MPL_ASSERT( (boost::mpl::or_< boost::is_integral,boost::is_float >) ) ; inline result_type operator() ( argument_type const& v ) const { return std::abs( v ) ; } }; #ifdef GLAS_COMPLEX template struct abs_functor< std::complex > { typedef std::complex argument_type ; typedef T result_type ; inline result_type operator() ( argument_type const& v ) const { return std::abs( v ) ; } }; #endif // GLAS_COMPLEX template struct abs_functor : abs_functor< T > {} ; template inline typename abs_functor::result_type abs( T const& v ) { return abs_functor() ( v ) ; } /// square_abs() template struct square_abs_functor { typedef T argument_type ; typedef typename abs_functor::result_type result_type ; //BOOST_STATIC_ASSERT( (boost::is_integral::value || boost::is_float::value) ) ; inline result_type operator() ( argument_type const& t ) const { return t * t ; } }; #ifdef GLAS_COMPLEX template struct square_abs_functor< std::complex > { typedef std::complex argument_type ; typedef typename abs_functor::result_type result_type ; inline result_type operator() ( argument_type const& t ) const { return t.real() * t.real() + t.imag() * t.imag() ; } }; #endif // GLAS_COMPLEX template struct square_abs_functor : square_abs_functor {} ; template inline typename square_abs_functor::result_type square_abs( T const& t ) { return square_abs_functor() ( t ) ; } } #endif