What are the existing rules for taking function pointers or member function pointers to Standard functions? For example, something like
auto p = &std::string::size;
Is this legal? Would it be more or less legal if I explicitly requested the correct type, so it would function even if there was an additional implementation-added overload of std::string::size?
Using the “correct” type doesn’t make things better: Except for the
virtualfunctions all functions in the standard C++ library can have additional arguments as long as these are defaulted. Since the functions can also be declared with additional overloads (again with the exception of thevirtualfunction), you can end up trying to assign an overload set a variable. Thus, the code isn’t portable and there is no way to make it portable by using some sort of cast or some signature instead ofauto.The relevant quote is 17.6.5.5 [member.functions] paragraph 1:
I don’t see a similar permission for non-member functions, though. Not sure where the permission to mess with these is hiding but I’m relatively sure that there are some weasel words for these as well. Looking further, it seems non-member functions are more constrained according to 17.6.5.4 [global.functions] paragraph 3:
This would imply that you can take the address of the non-member functions, at least, when specifying the desired signature.