Hi all,
this piece of code is rejected by gcc, however icpc on Linux (tested: v14 and 15)
- does not complain about using a non-const-iterator / changing a const string,
- and changes the content of the string passed as const, not only in the copy inside cv2up, but also in main.
#include <algorithm> #include <string> #include <iostream> using namespace std; void cv2up(const std::string typ) { // convert to upper case std::transform(typ.begin(), typ.end(),typ.begin(), ::toupper); cout << typ << endl; } int main() { string typ("abc"); cout << typ << endl; cv2up(typ); cout << typ << endl; return 0; }
$ icpc conststr.cpp && ./a.out
abc
ABC
ABC
Regards,
Christopher