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

📄 vec_scal_aop_expr.hpp

📁 矩阵运算源码最新版本
💻 HPP
字号:
// Software License for MTL// // Copyright (c) 2007 The Trustees of Indiana University. All rights reserved.// Authors: Peter Gottschling and Andrew Lumsdaine// // This file is part of the Matrix Template Library// // See also license.mtl.txt in the distribution.
#ifndef MTL_VEC_SCAL_AOP_EXPR_INCLUDE
#define MTL_VEC_SCAL_AOP_EXPR_INCLUDE

#include <boost/numeric/mtl/vector/vec_expr.hpp>
#include <boost/numeric/mtl/operation/sfunctor.hpp>


namespace mtl { namespace vector {

// Generic assign operation expression template for vectors
// Model of VectorExpression
template <class E1, class E2, typename SFunctor>
class vec_scal_aop_expr 
    : public vec_expr< vec_scal_aop_expr<E1, E2, SFunctor> >
{
public:
    typedef vec_expr< vec_scal_aop_expr<E1, E2, SFunctor> >  expr_base;
    typedef typename E1::value_type              value_type;
    
    // temporary solution
    typedef typename E1::size_type               size_type;
    //typedef typename utilities::smallest< typename E1::size_type, typename E2::size_type >::type                          size_type ;

    typedef value_type reference_type ;

    typedef E1 first_argument_type ;
    typedef E2 second_argument_type ;
    
    vec_scal_aop_expr( first_argument_type& v1, second_argument_type const& v2 )
	: expr_base( *this ), first( v1 ), second( v2 ), delayed_assign( false )
    {}

    ~vec_scal_aop_expr()
    {
	if (!delayed_assign)
	    for (size_type i= 0; i < first.size(); ++i)
		SFunctor::apply( first(i), second );
    }
    
    void delay_assign() const { delayed_assign= true; }

    size_type size() const 
    {
	return first.size() ;
    }

    value_type& operator() ( size_type i ) const 
    {
	assert( delayed_assign );
	return SFunctor::apply( first(i), second );
    }

    value_type& operator[] ( size_type i ) const
    {
	assert( delayed_assign );
	return SFunctor::apply( first(i), second );
    }

  private:
     mutable first_argument_type&        first ;
     second_argument_type const&         second ;
     mutable bool                        delayed_assign;
  } ; // vec_scal_aop_expr

} } // Namespace mtl::vector





#endif

⌨️ 快捷键说明

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