I'm searching a way to check function arguments in compile-time if it's possible to do for compiler.
To be more specific: assume that we have some class Matrix.
class Matrix
{
int x_size;
int y_size;
public:
Matrix(int width, int height):
x_size{width},
y_size{height}
{}
Matrix():
Matrix(0, 0)
{}
};
int main()
{
Matrix a; // good.
Matrix b(1, 10); // good.
Matrix c(0, 4); // bad, I want compilation error here.
}
So, can I check or differentiate behavior (function overloading?) in case of static (source-encoded) values passed to function?
If value isn't static:
std::cin >> size;
Matrix d(size, size);
we're only able to do runtime checks. But if values are encoded in source? Can I make compile-time check in this case?
EDIT: I think this can be possible with constexpr constructor, but anyway overloading with and without constexpr isn't allowed. So problem can't be resolved in way I suppose.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With