I was reading another question, and it got me thinking. Often the standard specifies functions which have default parameters in their descriptions. Does the standard allow writing these as overloads instead?
For example, the standard says that std::basic_string::copy
has the following declaration:
size_type copy(Ch* p, size_type n, size_type pos = 0) const;
Could a conforming implementation of the standard library implement this instead as two functions like this?
size_type copy(Ch* p, size_type n, size_type pos) const;
size_type copy(Ch* p, size_type n) const;
In this example, the second version could skip the if(pos > size()) { throw out_of_range(); }
test that is necessary in the first one. A micro-optimization, but still you see the point of the example.
Yes. The C++ Standard (C++03 17.4.4.4/2-3) says: