GQCP
Loading...
Searching...
No Matches
VectorSpaceArithmetic.hpp
Go to the documentation of this file.
1// This file is part of GQCG-GQCP.
2//
3// Copyright (C) 2017-2020 the GQCG developers
4//
5// GQCG-GQCP is free software: you can redistribute it and/or modify
6// it under the terms of the GNU Lesser General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// GQCG-GQCP is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU Lesser General Public License for more details.
14//
15// You should have received a copy of the GNU Lesser General Public License
16// along with GQCG-GQCP. If not, see <http://www.gnu.org/licenses/>.
17
18#pragma once
19
20
21#include "Utilities/CRTP.hpp"
22
23
24namespace GQCP {
25
26
33template <typename T, typename Scalar>
35 public CRTP<T> {
36public:
37 /*
38 * MARK: Pure virtual functions
39 */
40
44 virtual T& operator+=(const T& rhs) = 0;
45
49 virtual T& operator*=(const Scalar& a) = 0;
50
51
52 /*
53 * MARK: Canonical implementations of operators
54 */
55
59 friend T operator+(T lhs, const T& rhs) {
60 lhs += rhs;
61 return lhs;
62 }
63
64
68 T& operator-=(const T& rhs) {
69 *this += (-rhs);
70 return this->derived();
71 }
72
73
77 friend T operator-(T lhs, const T& rhs) {
78 lhs -= rhs;
79 return lhs;
80 }
81
82
86 friend T operator*(const Scalar& a, T rhs) {
87 return rhs *= a;
88 }
89
90
94 friend T operator*(T lhs, const Scalar& a) {
95 return lhs *= a;
96 }
97
101 friend T operator/(T lhs, const Scalar& a) {
102 return lhs *= Scalar {1} / a;
103 }
104
108 T operator-() const {
109 return Scalar {-1} * this->derived();
110 }
111};
112
113} // namespace GQCP
Definition: CRTP.hpp:32
Derived & derived()
Definition: CRTP.hpp:46
Definition: VectorSpaceArithmetic.hpp:35
friend T operator+(T lhs, const T &rhs)
Definition: VectorSpaceArithmetic.hpp:59
friend T operator/(T lhs, const Scalar &a)
Definition: VectorSpaceArithmetic.hpp:101
T & operator-=(const T &rhs)
Definition: VectorSpaceArithmetic.hpp:68
T operator-() const
Definition: VectorSpaceArithmetic.hpp:108
virtual T & operator+=(const T &rhs)=0
friend T operator-(T lhs, const T &rhs)
Definition: VectorSpaceArithmetic.hpp:77
friend T operator*(const Scalar &a, T rhs)
Definition: VectorSpaceArithmetic.hpp:86
friend T operator*(T lhs, const Scalar &a)
Definition: VectorSpaceArithmetic.hpp:94
virtual T & operator*=(const Scalar &a)=0
Definition: BaseOneElectronIntegralBuffer.hpp:25