c++ generic programming with templates and nullptr -
let's have generic function:
template<typename t> void foo(t data) { if(data == nullptr) return; //... }
the problem can not write that. if t primitive type or object passed value, can not compare nullptr.
on other hand, if t pointer int? able compare nullptr.
is there way?
as @j_random_hacker suggested, overload foo() function. way have 2 differents behaviour depending of type pass foo()
template<typename t> void foo(t *data) { if(data == nullptr) return; //... } template<typename t> void foo(t data) { //... }
Comments
Post a Comment