Giter Club home page Giter Club logo

Comments (5)

Lastique avatar Lastique commented on August 25, 2024

Yes, it looks like you have to define resource traits in this case.

from scope.

Lastique avatar Lastique commented on August 25, 2024

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.

liubing avatar liubing commented on August 25, 2024

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.

Lastique avatar Lastique commented on August 25, 2024

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.

liubing avatar liubing commented on August 25, 2024

Got it, thank you.

from scope.

Related Issues (17)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.