{"action":"created","issue":{"url":"https://api.github.com/repos/miloyip/rapidjson/issues/430","labels_url":"https://api.github.com/repos/miloyip/rapidjson/issues/430/labels{/name}","comments_url":"https://api.github.com/repos/miloyip/rapidjson/issues/430/comments","events_url":"https://api.github.com/repos/miloyip/rapidjson/issues/430/events","html_url":"https://github.com/miloyip/rapidjson/issues/430","id":108143823,"number":430,"title":"std::iostream support","user":{"login":"bruno-j-nicoletti","id":1868608,"avatar_url":"https://avatars.githubusercontent.com/u/1868608?v=3","gravatar_id":"","url":"https://api.github.com/users/bruno-j-nicoletti","html_url":"https://github.com/bruno-j-nicoletti","followers_url":"https://api.github.com/users/bruno-j-nicoletti/followers","following_url":"https://api.github.com/users/bruno-j-nicoletti/following{/other_user}","gists_url":"https://api.github.com/users/bruno-j-nicoletti/gists{/gist_id}","starred_url":"https://api.github.com/users/bruno-j-nicoletti/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bruno-j-nicoletti/subscriptions","organizations_url":"https://api.github.com/users/bruno-j-nicoletti/orgs","repos_url":"https://api.github.com/users/bruno-j-nicoletti/repos","events_url":"https://api.github.com/users/bruno-j-nicoletti/events{/privacy}","received_events_url":"https://api.github.com/users/bruno-j-nicoletti/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-09-24T14:36:19Z","updated_at":"2015-09-26T10:46:10Z","closed_at":null,"body":"Hi,\r\n\r\nI'm implementing std::iostream support for rapidjson, because my code doesn't work with FILEs. Would you like it pushed back to you? It is just two extra headers.\r\n\r\ncheers\r\n\r\nBruno"},"comment":{"url":"https://api.github.com/repos/miloyip/rapidjson/issues/comments/143418722","html_url":"https://github.com/miloyip/rapidjson/issues/430#issuecomment-143418722","issue_url":"https://api.github.com/repos/miloyip/rapidjson/issues/430","id":143418722,"user":{"login":"bruno-j-nicoletti","id":1868608,"avatar_url":"https://avatars.githubusercontent.com/u/1868608?v=3","gravatar_id":"","url":"https://api.github.com/users/bruno-j-nicoletti","html_url":"https://github.com/bruno-j-nicoletti","followers_url":"https://api.github.com/users/bruno-j-nicoletti/followers","following_url":"https://api.github.com/users/bruno-j-nicoletti/following{/other_user}","gists_url":"https://api.github.com/users/bruno-j-nicoletti/gists{/gist_id}","starred_url":"https://api.github.com/users/bruno-j-nicoletti/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bruno-j-nicoletti/subscriptions","organizations_url":"https://api.github.com/users/bruno-j-nicoletti/orgs","repos_url":"https://api.github.com/users/bruno-j-nicoletti/repos","events_url":"https://api.github.com/users/bruno-j-nicoletti/events{/privacy}","received_events_url":"https://api.github.com/users/bruno-j-nicoletti/received_events","type":"User","site_admin":false},"created_at":"2015-09-26T10:46:10Z","updated_at":"2015-09-26T10:46:10Z","body":"The helper class that manages the blocks is non intrusive already, but it is templated.\r\n\r\nThe code for it is....\r\n```C++\r\n////////////////////////////////////////////////////////////////////////////////\r\ntemplate<class WRITER>\r\nclass AutoObjectBlock {\r\npublic :\r\n  AutoObjectBlock(WRITER *w)\r\n    : writer_(w)\r\n  {}\r\n\r\n  // move copy constructor\r\n  AutoObjectBlock(AutoObjectBlock &&src)\r\n    : writer_(src.writer_)\r\n  {\r\n    src.writer_ = NULL;\r\n  }\r\n\r\n  ~AutoObjectBlock()\r\n  {\r\n    if(writer_) {\r\n      writer_->EndObject();\r\n    }\r\n  }\r\nprotected :\r\n  WRITER *writer_;\r\n};\r\n\r\n////////////////////////////////////////////////////////////////////////////////\r\ntemplate<class WRITER>\r\nclass AutoArrayBlock {\r\npublic :\r\n  AutoArrayBlock(WRITER *w)\r\n    : writer_(w)\r\n  {}\r\n\r\n  // move copy constructor\r\n  AutoArrayBlock(AutoArrayBlock &&src)\r\n    : writer_(src.writer_)\r\n  {\r\n    src.writer_ = NULL;\r\n  }\r\n\r\n  ~AutoArrayBlock()\r\n  {\r\n    if(writer_) {\r\n      writer_->EndArray();\r\n    }\r\n  }\r\n\r\nprotected :\r\n  WRITER *writer_;\r\n};\r\n```\r\n\r\nSo you suggestion already works, but needs to look like....\r\n\r\n```C++\r\nObjectBlock<PrettyWriter> b1(writer);\r\n{\r\n    writer.Key(...);\r\n    ArrayBlock<PrettyWriter> b2(writer);\r\n    // ...\r\n}\r\n```\r\nAlso, given my coding standard, I won't allow 'using namespace' in my code. Which means the above gets even more verbose. By adding the intrusive members to PrettyWriter/Writer below, combined with auto, you get the much tighter code from the post above.\r\n\r\n```C++\r\n    AutoArrayBlock<PrettyWriter> ArrayBlock()\r\n    {\r\n      StartArray();\r\n      return std::move(AutoArrayBlock<PrettyWriter>(this));\r\n    }\r\n\r\n    AutoArrayBlock<PrettyWriter> ArrayBlock(const std::string &key)\r\n    {\r\n      Key(key);\r\n      StartArray();\r\n      return std::move(AutoArrayBlock<PrettyWriter>(this));\r\n    }\r\n```"}}