cheshirekow  v0.1.0
RValue.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_RVALUE_H_
28 #define MPBLOCKS_POLYNOMIAL_RVALUE_H_
29 
30 namespace mpblocks {
31 namespace polynomial {
32 
34 template <typename Scalar, class Exp>
35 class RValue
36 {
37  public:
38  typedef unsigned int Size_t;
39 
41  Size_t size() const
42  {
43  return static_cast<Exp const&>(*this).size();
44  }
45 
46  Size_t degree() const
47  {
48  return size()-1;
49  }
50 
51 
53  Scalar operator[]( Size_t i ) const
54  {
55  if( i < size() )
56  return static_cast<Exp const&>(*this)[i];
57  else
58  return 0;
59  }
60 
62  operator Exp&()
63  {
64  return static_cast<Exp&>(*this);
65  }
66 
68  operator Exp const&()
69  {
70  return static_cast<Exp const&>(*this);
71  }
72 
73 
74 };
75 
76 
77 
78 
79 } // polynomial
80 } // mpblocks
81 
82 
83 
84 
85 
86 #endif // MATRIXEXPRESSION_H_
Size_t degree() const
Definition: RValue.h:46
Size_t size() const
return the size for a vector
Definition: RValue.h:41
expression template for rvalues
Definition: RValue.h:35
Scalar operator[](Size_t i) const
return the evaluated i'th element of a vector expression
Definition: RValue.h:53