cheshirekow  v0.1.0
Negative.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 Josh Bialkowski (jbialk@mit.edu)
3  *
4  * This file is part of mpblocks.
5  *
6  * mpblocks is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * mpblocks is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with mpblocks. If not, see <http://www.gnu.org/licenses/>.
18  */
27 #ifndef MPBLOCKS_POLYNOMIAL_NEGATIVE_H_
28 #define MPBLOCKS_POLYNOMIAL_NEGATIVE_H_
29 
30 namespace mpblocks {
31 namespace polynomial {
32 
34 template <typename Scalar, class Exp>
35 class Negative :
36  public RValue< Scalar,Negative<Scalar,Exp> >
37 {
38  Exp const& m_exp;
39 
40  public:
41  typedef std::size_t Size_t;
42 
43  Negative( Exp const& exp ):
44  m_exp(exp)
45  {
46  }
47 
49  Size_t size() const
50  {
51  return m_exp.size();
52  }
53 
55  Scalar operator[]( Size_t i ) const
56  {
57  return -m_exp[i];
58  }
59 
60  Scalar eval( Scalar x )
61  {
62  return -m_exp.eval(x);
63  }
64 };
65 
66 
67 
68 
69 template <typename Scalar, class Exp>
71  RValue<Scalar,Exp> const& exp )
72 {
73  typedef Negative<Scalar,Exp> Negative_t;
74  return Negative_t( static_cast<Exp const&>(exp) );
75 }
76 
77 
78 
79 
80 } // polynomial
81 } // mpblocks
82 
83 
84 
85 
86 
87 #endif // NEGATIVE_H_
Scalar eval(Scalar x)
Definition: Negative.h:60
Difference< Scalar, Exp1, Exp2 > operator-(RValue< Scalar, Exp1 > const &A, RValue< Scalar, Exp2 > const &B)
Definition: Difference.h:81
expression template for rvalues
Definition: RValue.h:35
Size_t size() const
return the size for a vector
Definition: Negative.h:49
Scalar operator[](Size_t i) const
return the evaluated i'th element of a vector expression
Definition: Negative.h:55
expression template for sum of two matrix expressions
Definition: Negative.h:35
Negative(Exp const &exp)
Definition: Negative.h:43