⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vector_expression.hpp

📁 boost库提供标准的C++ API 配合dev c++使用,功能更加强大
💻 HPP
📖 第 1 页 / 共 5 页
字号:
//
//  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 VECTOR_EXPRESSION_H
#define VECTOR_EXPRESSION_H

#include <boost/numeric/ublas/config.hpp>
#include <boost/numeric/ublas/exception.hpp>
#include <boost/numeric/ublas/functional.hpp>
#include <boost/numeric/ublas/noalias.hpp>

// Expression templates based on ideas of Todd Veldhuizen and Geoffrey Furnish
// Iterators based on ideas of Jeremy Siek

namespace boost { namespace numeric { namespace ublas {

    template<class T>
    struct scalar_expression:
        private boost::nonassignable {
        typedef T value_type;
    };

    template<class T>
    class scalar_value:
        public scalar_expression<T> {
    public:
        typedef T value_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_;
        }

    private:
        value_type t_;
    };

    template<class T>
    class scalar_const_reference:
        public scalar_expression<T> {
    public:
        typedef T value_type;

        // Construction and destruction
        BOOST_UBLAS_INLINE
        scalar_const_reference ():
            t_ (nil_) {}
        BOOST_UBLAS_INLINE
        scalar_const_reference (const value_type &t):
            t_ (t) {}

        BOOST_UBLAS_INLINE
        operator value_type () const {
            return t_;
        }

    private:
        const value_type &t_;
        static value_type nil_;
    };

    template<class T>
    typename scalar_const_reference<T>::value_type scalar_const_reference<T>::nil_;

    // Base class for the Barton Nackman trick
    template<class E>
    struct vector_expression:
        private boost::nonassignable {
        BOOST_STATIC_CONSTANT (int, complexity = 0);
        typedef E expression_type;
        typedef vector_tag type_category;
        typedef abstract_tag simd_category;
        typedef noalias_proxy<E> noalias_proxy_type;
        typedef const vector_range<const E> const_vector_range_type;
        typedef vector_range<E> vector_range_type;
        typedef const vector_slice<const E> const_vector_slice_type;
        typedef vector_slice<E> vector_slice_type;
        typedef const vector_indirect<const E> const_vector_indirect_type;
        typedef vector_indirect<E> vector_indirect_type;

        // This class could define an common interface for all
        // statically derived expression type classes.
        // Due to a compiler deficiency - one can not reference class typedefs of E
        // on MSVC 6.0 (error C2027) - we only implement the casts.

        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);
        }

        BOOST_UBLAS_INLINE
        noalias_proxy_type noalias () {
            return noalias_proxy_type (operator () ());
        }
#ifndef BOOST_UBLAS_NO_PROXY_SHORTCUTS
        BOOST_UBLAS_INLINE
        const_vector_range_type operator () (const range &r) const {
            return const_vector_range_type (operator () (), r);
        }
        BOOST_UBLAS_INLINE
        vector_range_type operator () (const range &r) {
            return vector_range_type (operator () (), r);
        }
        BOOST_UBLAS_INLINE
        const_vector_slice_type operator () (const slice &s) const {
            return const_vector_slice_type (operator () (), s);
        }
        BOOST_UBLAS_INLINE
        vector_slice_type operator () (const slice &s) {
            return vector_slice_type (operator () (), s);
        }
        template<class A>
        BOOST_UBLAS_INLINE
        const_vector_indirect_type operator () (const indirect_array<A> &ia) const {
            return const_vector_indirect_type (operator () (), ia);
        }
        template<class A>
        BOOST_UBLAS_INLINE
        vector_indirect_type operator () (const indirect_array<A> &ia) {
            return vector_indirect_type (operator () (), ia);
        }
#else
        BOOST_UBLAS_INLINE
        const_vector_range_type project (const range &r) const {
            return const_vector_range_type (operator () (), r);
        }
        BOOST_UBLAS_INLINE
        vector_range_type project (const range &r) {
            return vector_range_type (operator () (), r);
        }
        BOOST_UBLAS_INLINE
        const_vector_slice_type project (const slice &s) const {
            return const_vector_slice_type (operator () (), s);
        }
        BOOST_UBLAS_INLINE
        vector_slice_type project (const slice &s) {
            return vector_slice_type (operator () (), s);
        }
        template<class A>
        BOOST_UBLAS_INLINE
        const_vector_indirect_type project (const indirect_array<A> &ia) const {
            return const_vector_indirect_type (operator () (), ia);
        }
        template<class A>
        BOOST_UBLAS_INLINE
        vector_indirect_type project (const indirect_array<A> &ia) {
            return vector_indirect_type (operator () (), ia);
        }
#endif
    };

#ifndef BOOST_UBLAS_CT_REFERENCE_BASE_TYPEDEFS
    template<class E>
    class vector_const_reference:
        public vector_expression<vector_const_reference<E> > {
    public:
#ifndef BOOST_UBLAS_NO_PROXY_SHORTCUTS
        BOOST_UBLAS_USING vector_expression<vector_const_reference<E> >::operator ();
#endif
        typedef E expression_type;
        typedef typename E::simd_category simd_category;
        typedef typename E::size_type size_type;
        typedef typename E::difference_type difference_type;
        typedef typename E::value_type value_type;
        typedef typename E::const_reference const_reference;
        typedef const_reference reference;
        typedef typename E::const_pointer const_pointer;
        typedef const_pointer pointer;
        typedef typename E::const_iterator const_iterator_type;
        typedef unknown_storage_tag storage_category;

        // Construction and destruction
        BOOST_UBLAS_INLINE
        vector_const_reference ():
            e_ (nil_) {}
        BOOST_UBLAS_INLINE
        vector_const_reference (const expression_type &e):
            e_ (e) {}

        // Accessors
        BOOST_UBLAS_INLINE
        size_type size () const {
            return e_.size ();
        }
        BOOST_UBLAS_INLINE
        const expression_type &expression () const {
            return e_;
        }

        // Element access
        BOOST_UBLAS_INLINE
        const_reference operator () (size_type i) const {
            return expression () (i);
        }

        BOOST_UBLAS_INLINE
        const_reference operator [] (size_type i) const {
            return expression () [i];
        }

        // Comparison
        BOOST_UBLAS_INLINE
        bool operator == (const vector_const_reference &vr) const {
            return &(*this).expression () == &vr.expression ();
        }

        typedef const_iterator_type const_iterator;
        typedef const_iterator iterator;

        // Element lookup
        BOOST_UBLAS_INLINE
        const_iterator find (size_type i) const {
            return expression ().find (i);
        }

        // Iterator is the iterator of the referenced expression.

        BOOST_UBLAS_INLINE
        const_iterator begin () const {
            return expression ().begin ();
        }
        BOOST_UBLAS_INLINE
        const_iterator end () const {
            return expression ().end ();
        }

        // Reverse iterator

#ifdef BOOST_MSVC_STD_ITERATOR
        typedef reverse_iterator_base<const_iterator, value_type, const_reference> const_reverse_iterator;
#else
        typedef reverse_iterator_base<const_iterator> const_reverse_iterator;
#endif

        BOOST_UBLAS_INLINE
        const_reverse_iterator rbegin () const {
            return const_reverse_iterator (end ());
        }
        BOOST_UBLAS_INLINE
        const_reverse_iterator rend () const {
            return const_reverse_iterator (begin ());
        }

#ifdef BOOST_MSVC_STD_ITERATOR
        typedef reverse_iterator_base<const_iterator, value_type, const_reference> reverse_iterator;
#else
        typedef reverse_iterator_base<const_iterator> reverse_iterator;
#endif

    private:
        const expression_type &e_;
        static expression_type nil_;
    };

    template<class E>
    typename vector_const_reference<E>::expression_type vector_const_reference<E>::nil_;
#endif

    template<class E>
    class vector_reference:
        public vector_expression<vector_reference<E> > {
    public:
#ifndef BOOST_UBLAS_NO_PROXY_SHORTCUTS
        BOOST_UBLAS_USING vector_expression<vector_reference<E> >::operator ();
#endif
        typedef E expression_type;
        typedef typename E::simd_category simd_category;
        typedef typename E::size_type size_type;
        typedef typename E::difference_type difference_type;
        typedef typename E::value_type value_type;
#ifndef BOOST_UBLAS_CT_REFERENCE_BASE_TYPEDEFS
        typedef typename E::const_reference const_reference;
        typedef typename E::reference reference;
        typedef typename E::const_pointer const_pointer;
        typedef typename E::pointer pointer;
#else
        typedef typename E::const_reference const_reference;
        typedef typename boost::mpl::if_c<boost::is_const<E>::value,
                                          typename E::const_reference,
                                          typename E::reference>::type reference;
        typedef typename E::const_pointer const_pointer;
        typedef typename boost::mpl::if_c<boost::is_const<E>::value,
                                          typename E::const_pointer,
                                          typename E::pointer>::type pointer;
#endif
        typedef const vector_reference<E> const_self_type;
        typedef vector_reference<E> self_type;
        typedef const_self_type const_closure_type;
        typedef const_closure_type closure_type;
#ifndef BOOST_UBLAS_CT_REFERENCE_BASE_TYPEDEFS
        typedef typename E::const_iterator const_iterator_type;
        typedef typename E::iterator iterator_type;
#else
        typedef typename E::const_iterator const_iterator_type;
        typedef typename boost::mpl::if_c<boost::is_const<E>::value,
                                          typename E::const_iterator,
                                          typename E::iterator>::type iterator_type;
#endif
        typedef unknown_storage_tag storage_category;

        // Construction and destruction
        BOOST_UBLAS_INLINE
        vector_reference ():
            e_ (nil_) {}
        BOOST_UBLAS_INLINE
        vector_reference (expression_type &e):
            e_ (e) {}

        // Accessors
        BOOST_UBLAS_INLINE
        size_type size () const {
            return e_.size ();
        }
        BOOST_UBLAS_INLINE
        const expression_type &expression () const {
            return e_;
        }
        BOOST_UBLAS_INLINE
        expression_type &expression () {
            return e_;
        }

        // Comparison
        BOOST_UBLAS_INLINE

⌨️ 快捷键说明

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