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

📄 binexpr.h

📁 精确的函数表达模板,里面包含了许多C和C++的函数表达模板
💻 H
字号:

/****************************************************************************
 * Copyright (C) 2001        Piece Wise Functions
 *                           Carlo Galotto
 *                           Italy
 *                           Email: carlo.galotto@libero.it
 *                                  cgalotto@hotmail.com
 *
 *
 * This framework is free  software; you can  redistribute it and/or modify
 * it. This framework is distributed  in the  hope  that  it  will  be useful,
 * but WITHOUT ANY WARRANTY;  without even the   implied  warranty of
 * MERCHANTABILITY  or FITNESS FOR A PARTICULAR PURPOSE.
 * The proposed framework is based upon the paper "Expression Templates" by
 * Todd Veldhuizen.
 ****************************************************************************/

// Class: BinExpr

#ifndef __BINEXPR_H  //Required for current class
  #define __BINEXPR_H

#ifndef fn_traits_h
   #include "FnTraits.h"  // Required to promote types
#endif

#include <functional> // required for base classes


/****************************************************************************
 * BinExpr represents a binary operation on two expressions A and B that is * BinaryOperation (a, b). * A and B are the two expressions being combined, and Op is an applicative * template representing the operation. */   template <class A, class B, class Op>   class BinExpr
      : public std::unary_function <
         typename Promote<typename A::argument_type, typename B::argument_type>::promoted_t,
         typename Op::result_type >
   {
      public:
         typedef typename Promote<typename A::argument_type, typename B::argument_type>::promoted_t argument_type;
         typedef typename Op::result_type result_type;

      private:
         A lo;    // Left operand
         B ro;    // Right operand

      public:
         explicit BinExpr(const A & a, const B & b) : lo(a), ro(b){;}

         //Default constructor
         BinExpr () : lo(),   ro() {}

	      //Copy constructor
         BinExpr (const BinExpr& aBinExpr ) : lo( aBinExpr.lo ), ro( aBinExpr.ro ) {}

	      //Operator=
         BinExpr& operator= (const BinExpr& aBinExpr)
         {
            if(&aBinExpr != this)
            {
               lo = aBinExpr.lo;
               ro = aBinExpr.ro;
            }
            return *this;
         }
         // Destructor
         ~ BinExpr() {}

         // Evaluator operator: Op::apply() will be invoked
         result_type operator ()(const argument_type& x) const
         {return Op::apply(lo(x), ro(x)); }
   };

#endif




⌨️ 快捷键说明

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