O
Old Wolf
Hi all. G++ fails to compile the following:
#include <string>
int main()
{
std::string foo("abc=123");
std::string::const_iterator delimiter
= std::find(foo.begin(), foo.end(), '=');
std::string left (foo.begin(), delimiter);
}
The construction of 'left' fails, saying that there's no matching
constructor. The problem appears to be that it is searching
for a constructor taking (iterator, const_iterator) and finds
none. Is this conforming behaviour?
The following change doesn't fix it:
std::string::const_iterator
begin = foo.begin(),
delimiter = std::find(begin, foo.end(), '=');
std::string left (begin, delimiter);
Now it complains that there's no match for std::find() for
the same reason. The following does compile correctly:
std::string::const_iterator
begin = foo.begin(),
end = foo.end(),
delimiter = std::find(begin, end, '=');
std::string left (begin, delimiter);
I thought that non-const iterators should be implicitly
converted to const ones, or that the version of begin()
that returns a const_iterator should be found when it's
trying to find a matching call to std::find().
BCC has no problem with the code.
#include <string>
int main()
{
std::string foo("abc=123");
std::string::const_iterator delimiter
= std::find(foo.begin(), foo.end(), '=');
std::string left (foo.begin(), delimiter);
}
The construction of 'left' fails, saying that there's no matching
constructor. The problem appears to be that it is searching
for a constructor taking (iterator, const_iterator) and finds
none. Is this conforming behaviour?
The following change doesn't fix it:
std::string::const_iterator
begin = foo.begin(),
delimiter = std::find(begin, foo.end(), '=');
std::string left (begin, delimiter);
Now it complains that there's no match for std::find() for
the same reason. The following does compile correctly:
std::string::const_iterator
begin = foo.begin(),
end = foo.end(),
delimiter = std::find(begin, end, '=');
std::string left (begin, delimiter);
I thought that non-const iterators should be implicitly
converted to const ones, or that the version of begin()
that returns a const_iterator should be found when it's
trying to find a matching call to std::find().
BCC has no problem with the code.