I have the class below, but it only works with floating points. How to add integers too? That is multiple requires statements? or is there something that can include all numerical types?
Or there is a better way?
#ifndef COMPLEX_H
#define COMPLEX_H
#include <concepts>
#include <iostream>
template <class T>
requires std::floating_point<T> // How to add integral, signed integral, etc
class Complex {
private:
T re = 0;
T im = 0;
public:
Complex() {
std::cout << "Complex: Default constructor" << std::endl;
};
Complex(T real) : re{re} {
std::cout << "Complex: Constructing from assignement!" << std::endl;
};
bool operator<(const Complex<T>& other) {
return re < other.re && im < other.im;
}
};
#endif // COMPLEX_H