I have a method with a template parameter
bool insert_into_tree(const T new_key, const long &new_index){}
T is limited to std::string and int types. I would like values of new_key to be meaningful and thus I do not want an empty std::string but can accept a zero value for int.
This is an example of a Java template comparison to null
if (key == null) {}
key defined as T extends Comparable<? super T>
Within c++
key is defined as template <class T>
If T is std::string, there is no overloaded operator== such that comparison to NULL is possible.
If T is int, comparison to null is acceptable.
Thus, what method could I employ to make the template parameter comparison work as in Java?
In other words, if in Java I have a template parameter I can compare to null, how could I compare a template parameter in c++ such that NULL or some other appropriate value indicating null could be achieved.
bool?inttoNULLworks, but probably not the way you think. It simply compares to0(sinceNULLis a macro for0). In the Java case,keyis a pointer (which can thus benull). In your C++ case, you're working with akeyobject directly, so beingnullis not really defined there.Thus, what method could I employ to make the template parameter comparison work as in Java?