{"action":"created","issue":{"url":"https://api.github.com/repos/boutproject/BOUT-dev/issues/1218","repository_url":"https://api.github.com/repos/boutproject/BOUT-dev","labels_url":"https://api.github.com/repos/boutproject/BOUT-dev/issues/1218/labels{/name}","comments_url":"https://api.github.com/repos/boutproject/BOUT-dev/issues/1218/comments","events_url":"https://api.github.com/repos/boutproject/BOUT-dev/issues/1218/events","html_url":"https://github.com/boutproject/BOUT-dev/issues/1218","id":353446894,"node_id":"MDU6SXNzdWUzNTM0NDY4OTQ=","number":1218,"title":"Proposal for helper class to quieten output in a block","user":{"login":"ZedThree","id":1486942,"node_id":"MDQ6VXNlcjE0ODY5NDI=","avatar_url":"https://avatars3.githubusercontent.com/u/1486942?v=4","gravatar_id":"","url":"https://api.github.com/users/ZedThree","html_url":"https://github.com/ZedThree","followers_url":"https://api.github.com/users/ZedThree/followers","following_url":"https://api.github.com/users/ZedThree/following{/other_user}","gists_url":"https://api.github.com/users/ZedThree/gists{/gist_id}","starred_url":"https://api.github.com/users/ZedThree/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ZedThree/subscriptions","organizations_url":"https://api.github.com/users/ZedThree/orgs","repos_url":"https://api.github.com/users/ZedThree/repos","events_url":"https://api.github.com/users/ZedThree/events{/privacy}","received_events_url":"https://api.github.com/users/ZedThree/received_events","type":"User","site_admin":false},"labels":[{"id":56118090,"node_id":"MDU6TGFiZWw1NjExODA5MA==","url":"https://api.github.com/repos/boutproject/BOUT-dev/labels/enhance%20request","name":"enhance request","color":"84b6eb","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2018-08-23T15:56:37Z","updated_at":"2018-08-23T16:28:25Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"Sometimes it's nice to be able to turn off output while calling a function and turn it back on after. Currently, it can be done like so:\r\n```cpp\r\noutput.disable();\r\nnoisy_func();\r\noutput.enable();\r\n```\r\nwhich is ironically a bit verbose.\r\n\r\nI propose a helper class that would disable an output on creation and automatically re-enable it on exiting that block. A working proof-of-concept implementation:\r\n```cpp\r\nclass QuietOutput {\r\npublic:\r\n  QuietOutput(ConditionalOutput &output) : output(output) { output.disable(); }\r\n  ~QuietOutput() { output.enable(); }\r\n  ConditionalOutput &output;\r\n};\r\n```\r\nwhich would be used like this:\r\n```cpp\r\n{\r\n  QuietOutput quiet{output};\r\n  noisy_func();\r\n}\r\n```\r\n\r\nVariadic templates could be used to turn off multiple outputs in one line.\r\n\r\nI think this is likely to be useful at least for the unit tests, but might be more generally useful too"},"comment":{"url":"https://api.github.com/repos/boutproject/BOUT-dev/issues/comments/415480403","html_url":"https://github.com/boutproject/BOUT-dev/issues/1218#issuecomment-415480403","issue_url":"https://api.github.com/repos/boutproject/BOUT-dev/issues/1218","id":415480403,"node_id":"MDEyOklzc3VlQ29tbWVudDQxNTQ4MDQwMw==","user":{"login":"ZedThree","id":1486942,"node_id":"MDQ6VXNlcjE0ODY5NDI=","avatar_url":"https://avatars3.githubusercontent.com/u/1486942?v=4","gravatar_id":"","url":"https://api.github.com/users/ZedThree","html_url":"https://github.com/ZedThree","followers_url":"https://api.github.com/users/ZedThree/followers","following_url":"https://api.github.com/users/ZedThree/following{/other_user}","gists_url":"https://api.github.com/users/ZedThree/gists{/gist_id}","starred_url":"https://api.github.com/users/ZedThree/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ZedThree/subscriptions","organizations_url":"https://api.github.com/users/ZedThree/orgs","repos_url":"https://api.github.com/users/ZedThree/repos","events_url":"https://api.github.com/users/ZedThree/events{/privacy}","received_events_url":"https://api.github.com/users/ZedThree/received_events","type":"User","site_admin":false},"created_at":"2018-08-23T16:28:25Z","updated_at":"2018-08-23T16:28:25Z","author_association":"CONTRIBUTOR","body":"I count 40 :P \r\n\r\nThis uses RAII which is pretty idiomatic C++, see e.g. `std::lock_guard` which works in a similar way: make a local variable which gets a resource and cleans up after itself automatically. Here I guess the resource is silence!"}}
{"actor":{"display_login":"ZedThree"}}