I have a piece of code for sending data to remote side, it is acting a little like picojson, for example:
server::value::object obj;
obj["cmd"] = server::value("test");
obj["url"] = server::value(url);
...
obj["code"] = server::value(std::to_string(code));
server::value v(obj);
client.send_to_server(v.process());
As long as there is something to send, there will be a block like this.
These lines are used in so many places in my project that I'm thinking of using a function or << operator to replace it, which should be able to handle variable arguments.
A << operator version would be like:
Data d << "cmd" << "test"
<< "url" << url
<< ... << ...
<< "code" << code;
client.send_to_server(d);
Is this a good idea doing so? How to implement it?
Thanks.