microsoft / proxy

Proxy: Next Generation Polymorphism in C++

Home Page:https://wg21.link/p3086

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[FR] SBO-only targets

psiha opened this issue · comments

Add a trait to specify that only targets that fit into the SBO are allowed (to be assigned).
(or is specifying noexcept copyiablity enough, i.e. it implies that?)

For SBO, the implementation of proxy is different from mainstream implementation of std::function or std::any. proxy is a runtime binding of "pointers" rather than "values". SBO is only in the scope of function template make_proxy (it will select details::deep_ptr or details::sbo_ptr at compile-time), but out of the scope of class template proxy. If we need make_proxy to reject value types that uses details::deep_ptr, it might be a good idea to wrap make_proxy in another function template with more constraints, e.g.,

template <class F, class T, class... Args> requires(pro::proxiable<pro::details::sbo_ptr<T>, F>)
pro::proxy<F> make_proxy_with_no_heap_allocation(Args&&... args)
    { return pro::make_proxy<F, T>(std::forward<Args>(args)...); }

Unfortunately, pro::details::sbo_ptr is not public, and therefore you may need to copy the implementation of pro::details::sbo_ptr<T> from proxy.h to somewhere else to make the code work, in case it changes in the future. Like std::any, there is currently no plan to make SBO information public, but you can always implement your own make_proxy().

Close this issue since there's no more update.