Comments (5)
Yes, it looks like you have to define resource traits in this case.
from scope.
In C++20 you could work around it with something like this:
struct invalid_iconv
{
operator iconv_t() const noexcept
{
return (iconv_t)(-1);
}
};
using unique_iconv_t = boost::scope::unique_resource<iconv_t, boost::core::functor<iconv_close>, boost::scope::unallocated_resource<invalid_iconv{}>>;
but this is a hack and is not much shorter code than the proper resource traits.
from scope.
Thank you for the explanation. What puzzles me is that iconv_t
is actually void*
, and a Windows HANDLE
is also a void*
, and INVALID_HANDLE_VALUE
is defined as:
#define INVALID_HANDLE_VALUE ((HANDLE)(LONG_PTR)-1)
It looks exactly the same as (iconv_t)(-1)
. So why is this working?
using unique_handle = boost::scope::unique_resource<
HANDLE,
boost::core::functor< CloseHandle >,
boost::scope::unallocated_resource< INVALID_HANDLE_VALUE, (HANDLE)NULL >
>;
Could it be that MSVC is more permissive than GCC?
from scope.
Could it be that MSVC is more permissive than GCC?
Apparently so. You can see in this CI run that MSVC succeeded but clang and gcc on Windows failed to compile this code.
Looks like I should remove the INVALID_HANDLE_VALUE
example from the docs, or at least note that this code only works on MSVC.
from scope.
Got it, thank you.
from scope.
Related Issues (17)
- Docs: usage of `activate` in the initial example HOT 2
- Possible double-move of resource on `unique_resource` construction
- Add support for default construction to scope guards HOT 1
- Wrong description of what can be passed to a guard HOT 3
- Add a new set of examples in the Introduction section in the docs
- Prohibit default construction of function pointers
- Possible alias for C++-17 unique_resource HOT 1
- Why detail::compact_storage? HOT 2
- Example in Introduction doesn't return a value on success HOT 1
- make_default returns wrong type in example HOT 1
- Put safety checks in exception_checker HOT 1
- Outdated documentation in Boost HOT 1
- Add a docs section discussing differences with Library Fundamentals TS
- Passing a function reference to a scope guard factory fails to compile
- Add `BOOST_SCOPE_DETAIL_DOC_HIDDEN` to `unique_resource::reset` HOT 2
- Change `unique_resource` example in the documentation
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from scope.