
What kind of HANDLE that can be returned from DuplicateHandle should not be disposed by CloseHandle?
The only time I should call `CloseHandle` on the `HANDLE` result from `DuplicateHandle` is if the `DuplicateHandle` call succeeded. This is because the MSDN documentation does not assert that the `HANDLE` resulting from `DuplicateHandle` will never be `NULL` or `INVALID_HANDLE_VALUE`.
Essentially the underlying resource type in this case is a pair of a `HANDLE` and `BOOL`, where the "invalid value" is a pair with the `BOOL` set to `FALSE` and an indeterminate value of the `HANDLE`. In order to use the `rcpp::resource` template, I would need to override the `==` operator so that equality of the resource means equality of the `BOOL` member only, which is not ideal. I think that an `is_invalid` member would do the trick rather nicely, however. Why do not use boost::optional<HANDLE> as underlying resource type?
I hadn't thought of this. Seems like it would work...
Also, I think that it would be nice to have a `shared_resource` template. I have an application in mind where I would like to create a shared `HANDLE` that is only closed if it is invalid and all references to it have been destroyed (a shared reference count reaches 0). I thought about that. I don't think it has wide application. Moreover it can be emulated with boost::shared_ptr<rcpp::resource>. Is it worth while?
I think so because `boost::shared_ptr` adds a level of indirection that is unnecessary.