Hi, I was wondering if the compiler Visual C++ is smart enough to optimize code like this:
string temp = "abcd";
string temp2 = "hahaha";
string temp3 = temp + temp2;
"temp + temp2" can be replaced by "abcdhahaha"
vector<char> alphabet;
for (char i = 'a'; i <= 'z'; i++)
{
alphabet.push_back(i);
}
can be optimized to:
vector<char> alphabet;
//Avoid dynamic allocation
alphabet.reserve('z'-'a');
for (char i = 'a'; i <= 'z'; i++)
{
alphabet.push_back(i);
}
Does the compiler do all of this this?
Thanks in advance!