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

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -