C++: Check whether user has implemented std::numeric_limits<USERTYPE>::lowest() for his class

119 Views Asked by At

I have a library class which for correct functioning needs numeric_limits<USERTYPE>::lowest() to be implemented for the user's class USERTYPE. Requirement for USERTYPE is that it has an operator<.

Is there a recommended way to check whether the user has forgotten to implement "lowest()"? Per default lowest() returns USERTYPE(), the default constructed value. Firstly, it might not have a default constructor. Secondly, it might be the wrong value.

I came up using a static assertion for numeric_limits::is_specialized to be true, since the default is false. But is there a more elegant solution?

Of course I can also add a runtime assertion to a function where I get passed keys, to check that none is smaller than "lowest()" says. I was just wondering if I can do it cleanly at compile time.

0

There are 0 best solutions below