You are having trouble understanding your question. I think you are asking if it makes sense to be sure about the class domain (data that can be passed to it and make sense), and if so, how to be sure.
The first has a very clear answer: yes, absolutely. You want your class to be "easy to use correctly and difficult to use incorrectly." This includes ensuring that customers in this class are told when they are doing something wrong.
The second has a less clear answer. Most of the time, you just want to use the assert () function to validate the function or domain of the class. In other cases, you want to throw an exception. Sometimes you want to do both. When performance can be a problem, sometimes you want to provide an interface that does neither. Usually you want to provide an interface that, at least, can be checked so that clients can specify what is a valid / invalid input before trying to pass it to your class or function.
The reason you might want to both claim and throw is because throwing an exception destroys stack information and can make debugging difficult, but approval only happens during build and actually does nothing to protect you from performing calculations or performing actions, may lead to data crashes or invalidation. Thus, asserting and then throwing is often the best answer, so you can debug it while testing, but protect the user when these errors go to the shelf.
For your class, you can consider a couple of ways to provide min / max. One of them is to provide min / max functions in the class interface. The use of external functions may be different, and yes, numeric_limits may simply be the fact that a range is sometimes a type of numeric quantity. You can even provide a more general interface that has the validate_input () function in your class so that you can make any comparison that may be appropriate.
The second part of your question has many valid answers, depending on many variables, including personal taste.
source share