I don't think the compiler will take advantage of that either, I believe it will generate identical code as your current version. This is a better way because it will not invoke the overloaded "<<" operator twice (or thrice as your code would result in):
query << "foo"
"bar";