I coded the following:
#include <string>
#include <iostream>
#include <boost/algorithm/string.hpp>
using namespace std;
string encode(const string& word) {
boost::algorithm::to_upper(word);
return word;
}
int main() {
string word = "a";
string word1 = encode(word);
cout << word << endl;
}
This compiles, and the output is "A". Even though the function takes a const
reference, to_upper
modifies it.
I'm using Intel's 16.0.2 compiler
On other compilers (like g++), this code throws a compilation error.