Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to check if function exists

I want to implement my own std::make_unique function with the function being part of std namespace. I know this helper function is added to C++14 but I do not have it in C++11. So, I want to check it with some C++11 template magic (couldn't find any options with macros) to check if a function exists inside the std namespace and if it doesn't define it on my own. Is that possible? I don't even know where to start.

like image 885
Gasim Avatar asked Jan 27 '14 13:01

Gasim


Video Answer


2 Answers

Your best bet is to use the standard __cplusplus macro which, for C++11, is 201103L. For C++14 onwards it will be a different value to this.

like image 186
Bathsheba Avatar answered Sep 22 '22 21:09

Bathsheba


You cannot add a new function to the ::std namespace. You are only allowed to add specializations of existing templates, and even then only for your own types.

like image 22
David Rodríguez - dribeas Avatar answered Sep 22 '22 21:09

David Rodríguez - dribeas