| 21 | //------------------------------------------------------------------------- |
| 22 | template <typename Value, typename CloseAction> |
| 23 | class AutoClose |
| 24 | { |
| 25 | public: |
| 26 | //--------------------------------------------------------------------- |
| 27 | AutoClose(Value value, Value invalidValue, CloseAction closeAction) |
| 28 | : value_{ value } |
| 29 | , closeAction_{ closeAction } |
| 30 | { |
| 31 | if (value_ == invalidValue) |
| 32 | throw std::runtime_error("The value is invalid"); |
| 33 | } |
| 34 | |
| 35 | //--------------------------------------------------------------------- |
| 36 | ~AutoClose() |
| 37 | { |
| 38 | closeAction_(value_); |
| 39 | } |
| 40 | |
| 41 | //--------------------------------------------------------------------- |
| 42 | Value operator*() |
| 43 | { |
| 44 | return value_; |
| 45 | } |
| 46 | |
| 47 | private: |
| 48 | Value value_; |
| 49 | CloseAction closeAction_; |
| 50 | }; |
| 51 | |
| 52 | //------------------------------------------------------------------------- |
| 53 | template <typename Value, typename InvalidValue, typename CloseAction> |
nothing calls this directly
no outgoing calls
no test coverage detected