ampsci
c++ program for high-precision atomic structure calculations of single-valence systems
Template.hpp
1 #pragma once
2 #include <type_traits>
3 
4 namespace qip {
5 
7 
31 template <typename T, typename U = T>
32 class Comparison {
33  friend bool operator!=(const T &lhs, const U &rhs) { return !(lhs == rhs); }
34  friend bool operator>(const T &lhs, const U &rhs) { return rhs < lhs; }
35  friend bool operator<=(const T &lhs, const U &rhs) { return !(lhs > rhs); }
36  friend bool operator>=(const T &lhs, const U &rhs) { return !(lhs < rhs); }
37 };
38 
40 template <typename T>
41 class Arithmetic {
42  friend T operator+(T lhs, const T &rhs) { return lhs += rhs; }
43  friend T operator-(T lhs, const T &rhs) { return lhs -= rhs; }
44  friend T operator*(T lhs, const T &rhs) { return lhs *= rhs; }
45  friend T operator/(T lhs, const T &rhs) { return lhs /= rhs; }
46 };
47 
49 template <typename T, typename U>
50 class Arithmetic2 {
51  friend T operator+(T lhs, const U &rhs) { return lhs += rhs; }
52  friend T operator-(T lhs, const U &rhs) { return lhs -= rhs; }
53  friend T operator*(T lhs, const U &rhs) { return lhs *= rhs; }
54  friend T operator/(T lhs, const U &rhs) { return lhs /= rhs; }
55  // Also define these symmetric ones
56  friend T operator+(const U &lhs, T rhs) { return rhs += lhs; }
57  friend T operator*(const U &lhs, T rhs) { return rhs *= lhs; }
58 };
59 
60 } // namespace qip
Helper template for Arithmetic operations. Derive from this to provide +,-,*,/, given +=,...
Definition: Template.hpp:50
Helper template for Arithmetic operations. Derive from this to provide +,-,*,/, given +=,...
Definition: Template.hpp:41
Helper template for comparisons. Derive from this to provide !=,>,<=,>=, given == and <.
Definition: Template.hpp:32
qip library: A collection of useful functions
Definition: Array.hpp:8