Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

std::string insert method has ambiguous overloads?

Tags:

c++

stl

stlport

Environment: VS2005 C++ using STLPort 5.1.4.

Compiling the following code snippet:

std::string copied = "asdf";
char ch = 's';
copied.insert(0,1,ch);

I receive an error:

Error   1   error C2668: 'stlpx_std::basic_string<_CharT,_Traits,_Alloc>::insert' : ambiguous call to overloaded function   

It appears that the problem is the insert method call on the string object.

The two defined overloads are

void insert ( iterator p, size_t n, char c );
string& insert ( size_t pos1, size_t n, char c );

But given that STLPort uses a simple char* as its iterator, the literal zero in the insert method in my code is ambiguous.

So while I can easily overcome the problem by hinting such as

copied.insert(size_t(0),1,ch);

My question is: is this overloading and possible ambiguity intentional in the specification? Or more likely an unintended side-effect of the specific STLPort implementation?

(Note that the Microsoft-supplied STL does not have this problem as it has a class for the iterator, instead of a naked pointer)

like image 504
sdg Avatar asked Nov 14 '22 10:11

sdg


1 Answers

Known issue, ruled "Not A Defect". http://std.dkuug.dk/jtc1/sc22/wg21/docs/lwg-closed.html#84

like image 134
MSalters Avatar answered Nov 16 '22 23:11

MSalters