const to non-const pointer template argument conversion
Question
VC10 and GCC 4.4 accept the following, while Sun Studio 12 does not:
std::pair<char*, int> p1;
std::pair<char* const, int> p2;
p1 = p2
Sun Studio 12 complains:
Error: Cannot use std::pair<char*const, int> to initialize std::pair<char*, int>.
Any ideas why this is happening and how I can get Sun Studio to ignore this. I am working with a third party library, which would be a pain to rewrite just for this sort of thing.
Solution
It seems to be a known issue with Sun's std library.
Your best bet may be to convince the author of the code to replace the assignment with:
p1 = std::make_pair(p2.first, p2.second);
Or at construction time:
std::pair<char*, int> p1(p2.first, p2.second);
OTHER TIPS
Are you making sure to use libstlport rather than libCstd? See: https://stackoverflow.com/a/4481452/196844
This is definitely an error in the STL implementation. Section 20.2.2, Pairs, of the C++98 Standard provides for the template constructor template <class U, class V> pair(const pair<U, V>& p)
which initializes members first
and second
from the corresponding members of p
, performing implicit conversions as needed.