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