expression_types.hpp

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

HPP
489
字号
////  Copyright (c) 2000-2002//  Joerg Walter, Mathias Koch////  Distributed under the Boost Software License, Version 1.0. (See//  accompanying file LICENSE_1_0.txt or copy at//  http://www.boost.org/LICENSE_1_0.txt)////  The authors gratefully acknowledge the support of//  GeNeSys mbH & Co. KG in producing this work.//#ifndef _BOOST_UBLAS_EXPRESSION_TYPE_#define _BOOST_UBLAS_EXPRESSION_TYPE_#include <boost/numeric/ublas/exception.hpp>#include <boost/numeric/ublas/traits.hpp>#include <boost/numeric/ublas/functional.hpp>// Expression templates based on ideas of Todd Veldhuizen and Geoffrey Furnish// Iterators based on ideas of Jeremy Sieknamespace boost { namespace numeric { namespace ublas {    // Base class for uBLAS staticaly derived expressions - see the Barton Nackman trick    //  Provides numeric properties for linear algebra    template<class E>    class ublas_expression {    public:        typedef E expression_type;        /* E can be an incomplete type - to define the following we would need more template arguments        typedef typename E::type_category type_category;        typedef typename E::value_type value_type;        */                // Directly implement nonassignable - simplifes debugging call trace!    protected:        ublas_expression () {}        ~ublas_expression () {}    private:        const ublas_expression& operator= (const ublas_expression &);    };    // Base class for Scalar Expression models -    //  it does not model the Scalar Expression concept but all derived types should.    // The class defines a common base type and some common interface for all    // statically derived Scalar Expression classes    // We implement the casts to the statically derived type.    template<class E>    class scalar_expression:        public ublas_expression<E> {    public:        typedef E expression_type;        typedef scalar_tag type_category;        BOOST_UBLAS_INLINE        const expression_type &operator () () const {            return *static_cast<const expression_type *> (this);        }        BOOST_UBLAS_INLINE        expression_type &operator () () {            return *static_cast<expression_type *> (this);        }    };    template<class T>    class scalar_reference:        public scalar_expression<scalar_reference<T> > {        typedef scalar_reference<T> self_type;    public:        typedef T value_type;        typedef const value_type &const_reference;        typedef typename boost::mpl::if_<boost::is_const<T>,                                          const_reference,                                          value_type &>::type reference;        typedef const self_type const_closure_type;        typedef const_closure_type closure_type;        // Construction and destruction        BOOST_UBLAS_INLINE        explicit scalar_reference (reference t):            t_ (t) {}        // Conversion        BOOST_UBLAS_INLINE        operator value_type () const {            return t_;        }        // Assignment        BOOST_UBLAS_INLINE        scalar_reference &operator = (const scalar_reference &s) {            t_ = s.t_;            return *this;        }        template<class AE>        BOOST_UBLAS_INLINE        scalar_reference &operator = (const scalar_expression<AE> &ae) {            t_ = ae;            return *this;        }        // Closure comparison        BOOST_UBLAS_INLINE        bool same_closure (const scalar_reference &sr) const {            return &t_ == &sr.t_;        }    private:        reference t_;    };    template<class T>    class scalar_value:        public scalar_expression<scalar_value<T> > {        typedef scalar_value<T> self_type;    public:        typedef T value_type;        typedef const value_type &const_reference;        typedef typename boost::mpl::if_<boost::is_const<T>,                                          const_reference,                                          value_type &>::type reference;        typedef const scalar_reference<const self_type> const_closure_type;        typedef scalar_reference<self_type> closure_type;        // Construction and destruction        BOOST_UBLAS_INLINE        scalar_value ():            t_ () {}        BOOST_UBLAS_INLINE        scalar_value (const value_type &t):            t_ (t) {}        BOOST_UBLAS_INLINE        operator value_type () const {            return t_;        }        // Assignment        BOOST_UBLAS_INLINE        scalar_value &operator = (const scalar_value &s) {            t_ = s.t_;            return *this;        }        template<class AE>        BOOST_UBLAS_INLINE        scalar_value &operator = (const scalar_expression<AE> &ae) {            t_ = ae;            return *this;        }        // Closure comparison        BOOST_UBLAS_INLINE        bool same_closure (const scalar_value &sv) const {            return this == &sv;    // self closing on instances value        }    private:        value_type t_;    };    // Base class for Vector Expression models -    //  it does not model the Vector Expression concept but all derived types should.    // The class defines a common base type and some common interface for all    // statically derived Vector Expression classes    // We implement the casts to the statically derived type.    template<class E>    class vector_expression:        public ublas_expression<E> {    public:        static const unsigned complexity = 0;        typedef E expression_type;        typedef vector_tag type_category;        /* E can be an incomplete type - to define the following we would need more template arguments        typedef typename E::size_type size_type;        */         BOOST_UBLAS_INLINE        const expression_type &operator () () const {            return *static_cast<const expression_type *> (this);        }        BOOST_UBLAS_INLINE        expression_type &operator () () {            return *static_cast<expression_type *> (this);        }#ifdef BOOST_UBLAS_ENABLE_PROXY_SHORTCUTS    private:        // projection types        typedef vector_range<E> vector_range_type;        typedef vector_range<const E> const_vector_range_type;        typedef vector_slice<E> vector_slice_type;        typedef vector_slice<const E> const_vector_slice_type;        // vector_indirect_type will depend on the A template parameter         typedef basic_range<> default_range;    // required to avoid range/slice name confusion        typedef basic_slice<> default_slice;   public:        BOOST_UBLAS_INLINE        const_vector_range_type operator () (const default_range &r) const {            return const_vector_range_type (operator () (), r);        }        BOOST_UBLAS_INLINE        vector_range_type operator () (const default_range &r) {            return vector_range_type (operator () (), r);        }        BOOST_UBLAS_INLINE        const_vector_slice_type operator () (const default_slice &s) const {            return const_vector_slice_type (operator () (), s);        }        BOOST_UBLAS_INLINE        vector_slice_type operator () (const default_slice &s) {            return vector_slice_type (operator () (), s);        }        template<class A>        BOOST_UBLAS_INLINE        const vector_indirect<const E, indirect_array<A> > operator () (const indirect_array<A> &ia) const {            return vector_indirect<const E, indirect_array<A> >  (operator () (), ia);        }        template<class A>        BOOST_UBLAS_INLINE        vector_indirect<E, indirect_array<A> > operator () (const indirect_array<A> &ia) {            return vector_indirect<E, indirect_array<A> > (operator () (), ia);        }        BOOST_UBLAS_INLINE        const_vector_range_type project (const default_range &r) const {            return const_vector_range_type (operator () (), r);        }        BOOST_UBLAS_INLINE        vector_range_type project (const default_range &r) {            return vector_range_type (operator () (), r);        }        BOOST_UBLAS_INLINE        const_vector_slice_type project (const default_slice &s) const {            return const_vector_slice_type (operator () (), s);        }        BOOST_UBLAS_INLINE        vector_slice_type project (const default_slice &s) {            return vector_slice_type (operator () (), s);        }        template<class A>

⌨️ 快捷键说明

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