In C++, why does <cctype> define both std::isspace and ::isspace? -


and why c++ compilers able deduce type of ::isspace , implicitly convert std::function, not able std::isspace?

please see the following not compile:

#include <cctype> #include <functional>  template <typename functish> bool bar1(functish f) { return f('a'); }  inline bool bar2(std::function<bool(char)> f) { return f('a'); }  #if 1 #define ff &std::isspace #else #define ff &::isspace #endif  #if 0 bool foo() {     return bar1(ff); } #else bool foo() {     return bar2(ff); } #endif 

of compilers supported compiler explorer, ellcc seems 1 std::isspace has deducibility/convertibility expect.

there multiple overloads of std::isspace, 1 ::isspace.

the header <cctype> declares function int std::isspace(int), , maybe declares same function in global namespace (it doesn't have though).

the header <locale> defines function template template <class chart> bool std::isspace(chart, const std::locale&).

the header <ctype.h> declares function int isspace(int), , may declare same function in namespace std (it doesn't have though).

it seems on compilers besides ellcc, <cctype> includes <locale> (or both std::isspace overloads declared somewhere else , included both headers). standard specifies symbols standard headers must declare; doesn't prohibit them declaring other symbols aren't required.

since std::isspace overloaded, you'll have cast int(*)(int) compiler knows overload select.


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -