v0.5.86
single.cpp
Go to the documentation of this file.
1 #include <iostream>
2 #include <ostream>
3 template<char i>
4 class Index
5 {
6 public:
7  Index() {};
8 };
9 
10 class Tensor1;
11 
12 template <class A, char i>
13 class Tensor1_Expr
14 {
15  A *iter;
16 public:
17  Tensor1_Expr(A *a): iter(a) {}
18  double & operator()(const int N)
19  {
20  return (*iter)(N);
21  }
22  double operator()(const int N) const
23  {
24  return (*iter)(N);
25  }
26 
27  const A operator=(const Tensor1_Expr<Tensor1,'i'> &result)
28  {
29  cout << "equaling" << endl;
30  iter->data0=result(0);
31  iter->data1=result(1);
32  iter->data2=result(2);
33  return *iter;
34  }
35 
36 // template<class B>
37 // const A operator=(const Tensor1_Expr<B,'i'> &result)
38 // {
39 // cout << "equaling" << endl;
40 // iter->data0=result(0);
41 // iter->data1=result(1);
42 // iter->data2=result(2);
43 // return iter;
44 // }
45 };
46 
47 class Tensor1
48 {
49 public:
50  double data0, data1, data2;
51 public:
52  Tensor1(double d0, double d1, double d2): data0(d0), data1(d1), data2(d2) {}
53  double & operator()(const int N)
54  {
55  return N==0 ? data0 : (N==1 ? data1 : data2);
56  }
57 
58  double operator()(const int N) const
59  {
60  return N==0 ? data0 : (N==1 ? data1 : data2);
61  }
62 
63  template<char i>
65  {
66  return Tensor1_Expr<Tensor1,i>(this);
67  }
68 
69  friend ostream& operator<<(ostream& s, const Tensor1 &a);
70 };
71 
72 ostream& operator<<(ostream& s, const Tensor1 &a)
73 {
74  return s << a.data0 << " " << a.data1 << " " << a.data2 << " ";
75 }
76 
77 int main()
78 {
79  Tensor1 y(0,1,2);
80  Tensor1 x(2,3,4);
81  const Index<'i'> i;
82 
83  y(i)=x(i);
84 
85  cout << y << endl;
86 }
double & operator()(const int N)
Definition: single.cpp:53
double data1
Definition: single.cpp:50
double data0
Definition: single.cpp:50
Tensor1(double d0, double d1, double d2)
Definition: single.cpp:52
Index()
Definition: single.cpp:7
ostream & operator<<(ostream &s, const Tensor1 &a)
Definition: single.cpp:72
double operator()(const int N) const
Definition: single.cpp:22
int main()
Definition: single.cpp:77
Definition: Index.hpp:20
Tensor1_Expr(A *a)
Definition: single.cpp:17
const A operator=(const Tensor1_Expr< Tensor1, 'i'> &result)
Definition: single.cpp:27
double operator()(const int N) const
Definition: single.cpp:58
const int N
Definition: speed_test.cpp:3
double & operator()(const int N)
Definition: single.cpp:18
Tensor1_Expr< Tensor1, i > operator()(const Index< i > index)
Definition: single.cpp:64
double data2
Definition: single.cpp:50