mercredi 31 mai 2017

When is an rvalue evaluated?

So I understand that s2 binds to the expression s1 + s1, but is this evaluated at the time s2 is assigned or is it lazy and evaluated when s2 += "Test"; is called? And also would s2 hold memory for a temporary string?

#include <iostream>
#include <string>

int main()
{
    std::string s1 = "Test";
    std::string&& s2 = s1 + s1;
    s2 += "Test";
    std::cout << s2 << '\n';
}

Aucun commentaire:

Enregistrer un commentaire