Is the expression with multiple '<<' full?

Hello to everyone.
I need to implement simple wrapper for logging function log(const char *).

So the solution is below:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <stdio.h>
#include <sstream>

using namespace std;

void log(const char * str){ printf(str);}

class StreamLogger{
private:
  ostringstream stream;
public:
  StreamLogger & operator <<(const char * str){
    stream << str;
}
  ~StreamLogger(){
    log(stream.str().c_str());
    return *this;
};


int main(){
StreamLogger() << "foo1" << "foo2" << "foo3"; 
return 0;
}


So, according to standard the temporary objects should not be destroyed before full expression execution (expression whitch is not a part of another expression).
The question is: is StreamLogger() << "foo1" << "foo2" << "foo3"; full expression or not?
What you are doing is fine and perfectly safe.
Thx
Topic archived. No new replies allowed.