traits.hpp
来自「CGAL is a collaborative effort of severa」· HPP 代码 · 共 1,465 行 · 第 1/4 页
HPP
1,465 行
//// Copyright (c) 2000-2002// Joerg Walter, Mathias Koch//// Permission to use, copy, modify, distribute and sell this software// and its documentation for any purpose is hereby granted without fee,// provided that the above copyright notice appear in all copies and// that both that copyright notice and this permission notice appear// in supporting documentation. The authors make no representations// about the suitability of this software for any purpose.// It is provided "as is" without express or implied warranty.//// The authors gratefully acknowledge the support of// GeNeSys mbH & Co. KG in producing this work.//#ifndef BOOST_UBLAS_TRAITS_H#define BOOST_UBLAS_TRAITS_H#include <algorithm>#include <iterator>#include <complex>#include <cmath>#include <boost/numeric/ublas/iterator.hpp>#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) && !defined(BOOST_NO_SFINAE)#include <boost/numeric/ublas/returntype_deduction.hpp>#endifnamespace boost { namespace numeric { namespace ublas { template<class T> struct type_traits { typedef type_traits<T> self_type; typedef T value_type; typedef const T &const_reference; typedef T &reference; /* * Don't define unknown properties * typedef T real_type; typedef T precision_type; BOOST_STATIC_CONSTANT (unsigned, plus_complexity = 0); BOOST_STATIC_CONSTANT (unsigned, multiplies_complexity = 0); static BOOST_UBLAS_INLINE real_type real (const_reference) { } static BOOST_UBLAS_INLINE real_type imag (const_reference) { } static BOOST_UBLAS_INLINE value_type conj (const_reference) { } static BOOST_UBLAS_INLINE real_type abs (const_reference) { } static BOOST_UBLAS_INLINE value_type sqrt (const_reference) { } static BOOST_UBLAS_INLINE real_type norm_1 (const_reference t) { } static BOOST_UBLAS_INLINE real_type norm_2 (const_reference t) { } static BOOST_UBLAS_INLINE real_type norm_inf (const_reference t) { } static BOOST_UBLAS_INLINE bool equals (const_reference t1, const_reference t2) { } */ // Dummy definition for compilers that error if undefined even though it is never used#ifdef BOOST_NO_SFINAE typedef void real_type; typedef void precision_type;#endif }; template<> struct type_traits<float> { typedef type_traits<float> self_type; typedef float value_type; typedef const value_type &const_reference; typedef value_type &reference; typedef value_type real_type; typedef double precision_type; BOOST_STATIC_CONSTANT (unsigned, plus_complexity = 1); BOOST_STATIC_CONSTANT (unsigned, multiplies_complexity = 1); static BOOST_UBLAS_INLINE real_type real (const_reference t) { return t; } static BOOST_UBLAS_INLINE real_type imag (const_reference /*t*/) { return 0; } static BOOST_UBLAS_INLINE value_type conj (const_reference t) { return t; } static BOOST_UBLAS_INLINE real_type abs (const_reference t) {#if defined (BOOST_NO_STDC_NAMESPACE) || defined (BOOST_UBLAS_CMATH_BAD_STD) return ::fabsf (t);#else return std::abs (t);#endif } static BOOST_UBLAS_INLINE value_type sqrt (const_reference t) {#if defined (BOOST_NO_STDC_NAMESPACE) || defined (BOOST_UBLAS_CMATH_BAD_STD) return ::sqrtf (t);#else return std::sqrt (t);#endif } static BOOST_UBLAS_INLINE real_type norm_1 (const_reference t) { return self_type::abs (t); } static BOOST_UBLAS_INLINE real_type norm_2 (const_reference t) { return self_type::abs (t); } static BOOST_UBLAS_INLINE real_type norm_inf (const_reference t) { return self_type::abs (t); } static BOOST_UBLAS_INLINE bool equals (const_reference t1, const_reference t2) { return self_type::norm_inf (t1 - t2) < BOOST_UBLAS_TYPE_CHECK_EPSILON * (std::max) ((std::max) (self_type::norm_inf (t1), self_type::norm_inf (t2)), BOOST_UBLAS_TYPE_CHECK_MIN); } }; template<> struct type_traits<double> { typedef type_traits<double> self_type; typedef double value_type; typedef const value_type &const_reference; typedef value_type &reference; typedef value_type real_type;#ifndef BOOST_UBLAS_NO_LONG_DOUBLE typedef long double precision_type;#else typedef value_type precision_type;#endif BOOST_STATIC_CONSTANT (unsigned, plus_complexity = 1); BOOST_STATIC_CONSTANT (unsigned, multiplies_complexity = 1); static BOOST_UBLAS_INLINE real_type real (const_reference t) { return t; } static BOOST_UBLAS_INLINE real_type imag (const_reference /*t*/) { return 0; } static BOOST_UBLAS_INLINE value_type conj (const_reference t) { return t; } static BOOST_UBLAS_INLINE real_type abs (const_reference t) {#if defined (BOOST_NO_STDC_NAMESPACE) || defined (BOOST_UBLAS_CMATH_BAD_STD) return ::fabs (t);#else return std::abs (t);#endif } static BOOST_UBLAS_INLINE value_type sqrt (const_reference t) {#if defined (BOOST_NO_STDC_NAMESPACE) || defined (BOOST_UBLAS_CMATH_BAD_STD) return ::sqrt (t);#else return std::sqrt (t);#endif } static BOOST_UBLAS_INLINE real_type norm_1 (const_reference t) { return self_type::abs (t); } static BOOST_UBLAS_INLINE real_type norm_2 (const_reference t) { return self_type::abs (t); } static BOOST_UBLAS_INLINE real_type norm_inf (const_reference t) { return self_type::abs (t); } static BOOST_UBLAS_INLINE bool equals (const_reference t1, const_reference t2) { return self_type::norm_inf (t1 - t2) < BOOST_UBLAS_TYPE_CHECK_EPSILON * (std::max) ((std::max) (self_type::norm_inf (t1), self_type::norm_inf (t2)), BOOST_UBLAS_TYPE_CHECK_MIN); } };#ifndef BOOST_UBLAS_NO_LONG_DOUBLE template<> struct type_traits<long double> { typedef type_traits<long double> self_type; typedef long double value_type; typedef const value_type &const_reference; typedef value_type &reference; typedef value_type real_type; typedef value_type precision_type; BOOST_STATIC_CONSTANT (unsigned, plus_complexity = 1); BOOST_STATIC_CONSTANT (unsigned, multiplies_complexity = 1); static BOOST_UBLAS_INLINE real_type real (const_reference t) { return t; } static BOOST_UBLAS_INLINE real_type imag (const_reference /*t*/) { return 0; } static BOOST_UBLAS_INLINE value_type conj (const_reference t) { return t; } static BOOST_UBLAS_INLINE real_type abs (const_reference t) {#if defined (BOOST_NO_STDC_NAMESPACE) || defined (BOOST_UBLAS_CMATH_BAD_STD) return ::fabsl (t);#else return std::abs (t);#endif } static BOOST_UBLAS_INLINE value_type sqrt (const_reference t) {#if defined (BOOST_NO_STDC_NAMESPACE) || defined (BOOST_UBLAS_CMATH_BAD_STD) return ::sqrtl (t);#else return std::sqrt (t);#endif } static BOOST_UBLAS_INLINE real_type norm_1 (const_reference t) { return self_type::abs (t); } static BOOST_UBLAS_INLINE real_type norm_2 (const_reference t) { return self_type::abs (t); } static BOOST_UBLAS_INLINE real_type norm_inf (const_reference t) { return self_type::abs (t); } static BOOST_UBLAS_INLINE bool equals (const_reference t1, const_reference t2) { return self_type::norm_inf (t1 - t2) < BOOST_UBLAS_TYPE_CHECK_EPSILON * (std::max) ((std::max) (self_type::norm_inf (t1), self_type::norm_inf (t2)), BOOST_UBLAS_TYPE_CHECK_MIN); } };#endif template<> struct type_traits<std::complex<float> > { typedef type_traits<std::complex<float> > self_type; typedef std::complex<float> value_type; typedef const value_type &const_reference; typedef value_type &reference; typedef float real_type; typedef std::complex<double> precision_type; BOOST_STATIC_CONSTANT (unsigned, plus_complexity = 2); BOOST_STATIC_CONSTANT (unsigned, multiplies_complexity = 6); static BOOST_UBLAS_INLINE real_type real (const_reference t) { return std::real (t); } static BOOST_UBLAS_INLINE real_type imag (const_reference t) { return std::imag (t); } static BOOST_UBLAS_INLINE value_type conj (const_reference t) { return std::conj (t); } static BOOST_UBLAS_INLINE real_type abs (const_reference t) { return std::abs (t); } static BOOST_UBLAS_INLINE value_type sqrt (const_reference t) { return std::sqrt (t); } static BOOST_UBLAS_INLINE real_type norm_1 (const_reference t) { return type_traits<real_type>::abs (self_type::real (t)) + type_traits<real_type>::abs (self_type::imag (t)); } static BOOST_UBLAS_INLINE real_type norm_2 (const_reference t) { return self_type::abs (t); }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?