📄 unaryexpr.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: UnaryExpr
#ifndef __UNRYEXPR_H //Required for current class
#define __UNRYEXPR_H
#include <functional> // required for base classes
/****************************************************************************
* UnaryExpr represents an unary operation on an expressions. * E is the expression and Op is an applicative template representing * the operation. */ template <class E, class Op>
class UnaryExpr : public std::unary_function < typename E::argument_type,
typename Op::result_type >
{
public:
typedef typename E::argument_type argument_type;
typedef typename Op::result_type result_type;
private:
E expr;
public:
//Default constructor
UnaryExpr () : expr() { }
//Constructor with arguments
explicit UnaryExpr(const E & e) : expr(e) {;}
//Copy constructor
UnaryExpr(const UnaryExpr& aUnaryExpr ) : expr(aUnaryExpr.expr) {;}
//Assignment Operator
UnaryExpr& operator= (const UnaryExpr& aUnaryExpr)
{
if(&aUnaryExpr != this)
expr = aUnaryExpr.expr;
return *this;
}
// Evaluator operator: Op::apply() will be invoked
result_type operator ()(const argument_type& x) const
{ return Op::apply(expr(x)); }
// Destructor
~UnaryExpr() {}
};
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -