Home Dashboard Directory Help
Search

Incorrect Overload Resolution by WorkingHorse


Status: 

Closed
 as Fixed Help for as Fixed


1
0
Sign in
to vote
Type: Bug
ID: 606746
Opened: 9/29/2010 11:13:57 AM
Access Restriction: Public
0
Workaround(s)
view
2
User(s) can reproduce this bug

Description

The C++ compiler cannot match the correct overload for the std::transform template in the algorithm library -- this is just one example, there are no doubt others where code that used to work in Visual Studio 2005 no longer works in 2010.
Details
Sign in to post a comment.
Posted by Microsoft on 2/16/2011 at 8:11 PM
Hi,

Thanks for reporting this bug. We've fixed it, and the fix will be available in VC11. Note that due to changes between C++98/03 and C++0x, you'll have to use either make_pair<string&, string&> or make_pair<const string&, const string&>. Here's an example:

C:\Temp>type meow.cpp
#include <algorithm>
#include <iostream>
#include <iterator>
#include <map>
#include <ostream>
#include <string>
#include <utility>
#include <vector>
using namespace std;

void print(const map<string, string>& m) {
    for (auto i = m.begin(); i != m.end(); ++i) {
        cout << "(" << i->first << ", " << i->second << ")" << endl;
    }
}

int main() {
    vector<string> series;
    series.push_back("TOS");
    series.push_back("TNG");
    series.push_back("DS9");
    series.push_back("VOY");
    series.push_back("ENT");

    vector<string> captains;
    captains.push_back("Kirk");
    captains.push_back("Picard");
    captains.push_back("Sisko");
    captains.push_back("Janeway");
    captains.push_back("Archer");

    map<string, string> m;

    transform(series.begin(), series.end(), captains.begin(), inserter(m, m.end()), make_pair<string&, string&>);

    print(m);

    cout << "-----" << endl;
    m.clear();

    const vector<string> vs = series;
    const vector<string> vc = captains;

    transform(vc.begin(), vc.end(), vs.begin(), inserter(m, m.end()), make_pair<const string&, const string&>);

    print(m);
}

C:\Temp>cl /EHsc /nologo /W4 meow.cpp
meow.cpp

C:\Temp>meow
(DS9, Sisko)
(ENT, Archer)
(TNG, Picard)
(TOS, Kirk)
(VOY, Janeway)
-----
(Archer, ENT)
(Janeway, VOY)
(Kirk, TOS)
(Picard, TNG)
(Sisko, DS9)

Also, please note that the STL's headers include each other in unspecified ways, so you should always be careful to include the headers that you need (e.g. <string> for string and <utility> for make_pair).

If you have any further questions, feel free to E-mail me at stl@microsoft.com .

Stephan T. Lavavej
Visual C++ Libraries Developer
Posted by Microsoft on 9/29/2010 at 7:44 PM
Thanks for your feedback.

We are rerouting this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will

follow-up with your issue.

Posted by Microsoft on 9/29/2010 at 6:23 PM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.