traits.hpp

来自「Boost provides free peer-reviewed portab」· HPP 代码 · 共 517 行 · 第 1/2 页

HPP
517
字号
    struct type_traits<std::complex<double> > : complex_traits<std::complex<double> >{        typedef type_traits<std::complex<double> > self_type;        typedef std::complex<double> value_type;        typedef const value_type &const_reference;        typedef value_type &reference;        typedef double real_type;        typedef std::complex<long double> precision_type;    };    template<>    struct type_traits<std::complex<long double> > : complex_traits<std::complex<long double> > {        typedef type_traits<std::complex<long double> > self_type;        typedef std::complex<long double> value_type;        typedef const value_type &const_reference;        typedef value_type &reference;        typedef long double real_type;        typedef value_type precision_type;    };#ifdef BOOST_UBLAS_USE_INTERVAL    // Define scalar interval type traits    template<>    struct type_traits<boost::numeric::interval<float> > : scalar_traits<boost::numeric::interval<float> > {        typedef type_traits<boost::numeric::interval<float> > self_type;        typedef boost::numeric::interval<float> value_type;        typedef const value_type &const_reference;        typedef value_type &reference;        typedef value_type real_type;        typedef boost::numeric::interval<double> precision_type;    };    template<>    struct type_traits<boost::numeric::interval<double> > : scalar_traits<boost::numeric::interval<double> > {        typedef type_traits<boost::numeric::interval<double> > self_type;        typedef boost::numeric::interval<double> value_type;        typedef const value_type &const_reference;        typedef value_type &reference;        typedef value_type real_type;        typedef boost::numeric::interval<long double> precision_type;    };    template<>    struct type_traits<boost::numeric::interval<long double> > : scalar_traits<boost::numeric::interval<long double> > {        typedef type_traits<boost::numeric::interval<long double> > self_type;        typedef boost::numeric::interval<long double> value_type;        typedef const value_type &const_reference;        typedef value_type &reference;        typedef value_type real_type;        typedef value_type precision_type;    };#endif    // Storage tags -- hierarchical definition of storage characteristics    struct unknown_storage_tag {};    struct sparse_proxy_tag: public unknown_storage_tag {};    struct sparse_tag: public sparse_proxy_tag {};    struct packed_proxy_tag: public sparse_proxy_tag {};    struct packed_tag: public packed_proxy_tag {};    struct dense_proxy_tag: public packed_proxy_tag {};    struct dense_tag: public dense_proxy_tag {};    template<class S1, class S2>    struct storage_restrict_traits {        typedef S1 storage_category;    };    template<>    struct storage_restrict_traits<sparse_tag, dense_proxy_tag> {        typedef sparse_proxy_tag storage_category;    };    template<>    struct storage_restrict_traits<sparse_tag, packed_proxy_tag> {        typedef sparse_proxy_tag storage_category;    };    template<>    struct storage_restrict_traits<sparse_tag, sparse_proxy_tag> {        typedef sparse_proxy_tag storage_category;    };    template<>    struct storage_restrict_traits<packed_tag, dense_proxy_tag> {        typedef packed_proxy_tag storage_category;    };    template<>    struct storage_restrict_traits<packed_tag, packed_proxy_tag> {        typedef packed_proxy_tag storage_category;    };    template<>    struct storage_restrict_traits<packed_tag, sparse_proxy_tag> {        typedef sparse_proxy_tag storage_category;    };    template<>    struct storage_restrict_traits<packed_proxy_tag, sparse_proxy_tag> {        typedef sparse_proxy_tag storage_category;    };    template<>    struct storage_restrict_traits<dense_tag, dense_proxy_tag> {        typedef dense_proxy_tag storage_category;    };    template<>    struct storage_restrict_traits<dense_tag, packed_proxy_tag> {        typedef packed_proxy_tag storage_category;    };    template<>    struct storage_restrict_traits<dense_tag, sparse_proxy_tag> {        typedef sparse_proxy_tag storage_category;    };    template<>    struct storage_restrict_traits<dense_proxy_tag, packed_proxy_tag> {        typedef packed_proxy_tag storage_category;    };    template<>    struct storage_restrict_traits<dense_proxy_tag, sparse_proxy_tag> {        typedef sparse_proxy_tag storage_category;    };    // Iterator tags -- hierarchical definition of storage characteristics    struct sparse_bidirectional_iterator_tag : public std::bidirectional_iterator_tag {};    struct packed_random_access_iterator_tag : public std::random_access_iterator_tag {};    struct dense_random_access_iterator_tag : public packed_random_access_iterator_tag {};    // Thanks to Kresimir Fresl for convincing Comeau with iterator_base_traits ;-)    template<class IC>    struct iterator_base_traits {};    template<>    struct iterator_base_traits<std::forward_iterator_tag> {        template<class I, class T>        struct iterator_base {            typedef forward_iterator_base<std::forward_iterator_tag, I, T> type;        };    };    template<>    struct iterator_base_traits<std::bidirectional_iterator_tag> {        template<class I, class T>        struct iterator_base {            typedef bidirectional_iterator_base<std::bidirectional_iterator_tag, I, T> type;        };    };    template<>    struct iterator_base_traits<sparse_bidirectional_iterator_tag> {        template<class I, class T>        struct iterator_base {            typedef bidirectional_iterator_base<sparse_bidirectional_iterator_tag, I, T> type;        };    };    template<>    struct iterator_base_traits<std::random_access_iterator_tag> {        template<class I, class T>        struct iterator_base {            typedef random_access_iterator_base<std::random_access_iterator_tag, I, T> type;        };    };    template<>    struct iterator_base_traits<packed_random_access_iterator_tag> {        template<class I, class T>        struct iterator_base {            typedef random_access_iterator_base<packed_random_access_iterator_tag, I, T> type;        };    };    template<>    struct iterator_base_traits<dense_random_access_iterator_tag> {        template<class I, class T>        struct iterator_base {            typedef random_access_iterator_base<dense_random_access_iterator_tag, I, T> type;        };    };    template<class I1, class I2>    struct iterator_restrict_traits {        typedef I1 iterator_category;    };    template<>    struct iterator_restrict_traits<packed_random_access_iterator_tag, sparse_bidirectional_iterator_tag> {        typedef sparse_bidirectional_iterator_tag iterator_category;    };    template<>    struct iterator_restrict_traits<sparse_bidirectional_iterator_tag, packed_random_access_iterator_tag> {        typedef sparse_bidirectional_iterator_tag iterator_category;    };    template<>    struct iterator_restrict_traits<dense_random_access_iterator_tag, sparse_bidirectional_iterator_tag> {        typedef sparse_bidirectional_iterator_tag iterator_category;    };    template<>    struct iterator_restrict_traits<sparse_bidirectional_iterator_tag, dense_random_access_iterator_tag> {        typedef sparse_bidirectional_iterator_tag iterator_category;    };    template<>    struct iterator_restrict_traits<dense_random_access_iterator_tag, packed_random_access_iterator_tag> {        typedef packed_random_access_iterator_tag iterator_category;    };    template<>    struct iterator_restrict_traits<packed_random_access_iterator_tag, dense_random_access_iterator_tag> {        typedef packed_random_access_iterator_tag iterator_category;    };    template<class I>    BOOST_UBLAS_INLINE    void increment (I &it, const I &it_end, typename I::difference_type compare, packed_random_access_iterator_tag) {        it += (std::min) (compare, it_end - it);    }    template<class I>    BOOST_UBLAS_INLINE    void increment (I &it, const I &/* it_end */, typename I::difference_type /* compare */, sparse_bidirectional_iterator_tag) {        ++ it;    }    template<class I>    BOOST_UBLAS_INLINE    void increment (I &it, const I &it_end, typename I::difference_type compare) {        increment (it, it_end, compare, typename I::iterator_category ());    }    template<class I>    BOOST_UBLAS_INLINE    void increment (I &it, const I &it_end) {#if BOOST_UBLAS_TYPE_CHECK        I cit (it);        while (cit != it_end) {            BOOST_UBLAS_CHECK (*cit == typename I::value_type/*zero*/(), internal_logic ());            ++ cit;        }#endif        it = it_end;    }    namespace detail {        // specialisation which define whether a type has a trivial constructor        // or not. This is used by array types.        template<typename T>        struct has_trivial_constructor : public boost::has_trivial_constructor<T> {};        template<typename T>        struct has_trivial_destructor : public boost::has_trivial_destructor<T> {};        template<typename FLT>        struct has_trivial_constructor<std::complex<FLT> > : public boost::true_type {};                template<typename FLT>        struct has_trivial_destructor<std::complex<FLT> > : public boost::true_type {};    }}}}#endif

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?