Giter Club home page Giter Club logo

Comments (4)

mingxwa avatar mingxwa commented on May 16, 2024

If I understand correctly, proxy already provides the capability. You can simply instantiate a proxy<F> with any raw pointer type P (although proxy<F> still has nontrivial move ctor and dtor, it behaves like a raw pointer).

If proxy<F> is intended not to take any ownership for all P, it is allowed to fine tune performance like std::function_ref does. Lifetime semantics is associated with the definition of a facade (F::constraints). If you are using PRO_DEF_FACADE to define a facade, the constraints can be specified on the 3rd parameter, e.g.,

PRO_DEF_MEMBER_DISPATCH(Draw, void(std::ostream& out));
PRO_DEF_FACADE(DrawableRef, Draw, pro::trivial_ptr_constraints);

proxy<DrawableRef> will have trivial copy ctor and move ctor, but it can no longer hold any smart pointers (e.g., std::unique_ptr std::shared_ptr or pro::details::sbo_ptr).

from proxy.

psiha avatar psiha commented on May 16, 2024

That's not the same: a function_ref-like thingy does not need an SBO (or heap allocation) for any kind of target object - as it references it directly (as opposed to owning it) - it can/should be able to bind to a temprary (function argument).
A reference to a trivial proxy<> has two indirections: reference to the proxy and then a reference to the vtable (and possibly an additional one to the target if it did not fit into the SBO storage).
trivial_ptr_constraints will make proxy the size of two pointers, like function_ref but will require a heap allocation and a nontrivial destructor for larger-than-a-pointer targets or not support those at all.

from proxy.

mingxwa avatar mingxwa commented on May 16, 2024

trivial_ptr_constraints will make proxy the size of two pointers, like function_ref but will require a heap allocation and a nontrivial destructor for larger-than-a-pointer targets or not support those at all.

In the design of proxy, if trivial_ptr_constraints is specified in a facade definition F, proxy<F> is a trivial type. It is covered in our unit tests.

from proxy.

mingxwa avatar mingxwa commented on May 16, 2024

The dereferencing of small vtable is triaged as a QoI issue (filed #69).

from proxy.

Related Issues (20)

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.