|
Boost : |
Subject: Re: [boost] Formal Review Request: TypeErasure
From: Hite, Christopher (Christopher.Hite_at_[hidden])
Date: 2012-06-06 11:25:56
My 0.02EUR.
A big issue of type deletion is dealing with storage.
1) Please do a better job of SBO than boost::function. It'd be cool if you let the user pick the SBO size or even configure his own container.
boost::function might have been implemented using shared_ptr, but there would have been issues with stateful f-tors.
2) On a related note I could see the use of an any_ref type holding only a virtual table pointer and a ref to an object it doesn't own. Just two words no heaping. That pushes the storage problem out to the user.
I think you could do that optimization with a specialization where the 2nd parameter is a ref.
Would the second parameter ever be shared_ptr<_self> ?
3) What about optionality?
Should they always use optional<any<> > ? boost::function can be null.
4) What about and any_base<> + any_derived<> ?
Based on several cases where I've seen/done type deletion a common pattern is to define a base class and a templated derived class.
boost::asio::detail::op_base+op
The technique can be implemented with either function pointers or virtual functions.
If you could provide an elegant way of doing that, it'd be pretty cool. The user is free to store his any_derived<> however he sees fit.
My example is a buffered logging class that takes functor< void (std::ostream&)> and stores them in a linear buffer, which gets flushed out later.
Can that be done in a more formal way?
5) The library overlaps quite a bit with Concept checking libs. Perhaps you should expose this to the user.
You can implement an assert_fits_any<any_type,T> (is a macro better)?
You can probably also implement a check_any<any_type,T > metafunction and that lets the user check a type to see if it fits and do something else if it doesn't.
6) Could you add an example where it has a call operator like boost::function?
I can see some antipatterns forming:
* people shouldn't use any to replace classic interfaces and virtual functions
* special purpose type deletion may be better like any_range
Pretty cool library!
Chris
-----Original Message-----
From: boost-bounces_at_[hidden] [mailto:boost-bounces_at_[hidden]] On Behalf Of Steven Watanabe
Sent: Tuesday, May 22, 2012 10:34 PM
To: boost_at_[hidden]
Subject: [boost] Formal Review Request: TypeErasure
AMDG
I'd like to request a formal review of the TypeErasure library that I've posted about several times before here.
The TypeErasure library is a generalization of boost::any and boost::function. It allows easy composition of arbitrary type erased operators.
As an example of basic usage, we
can simulate Boost.Any:
any<mpl::vector<copy_constructible<>, typeid_<> > > x(10); int i = any_cast<int>(x); // i == 10
The library is available in the Boost Sandbox at http://svn.boost.org/svn/boost/sandbox/type_erasure/
You can download archives with pre-built documentation from http://sourceforge.net/projects/steven-watanabe.u/files/
Online documentation can be found here:
http://steven_watanabe.users.sourceforge.net/type_erasure/libs/type_erasure/
In Christ,
Steven Watanabe
_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk