Boost logo

Boost :

From: Jonathan Turkanis (technews_at_[hidden])
Date: 2005-01-29 16:15:22


christopher diggins wrote:
> ----- Original Message -----
> From: "Jonathan Turkanis" <technews_at_[hidden]>
> To: <boost_at_[hidden]>
> Sent: Friday, January 28, 2005 6:00 PM
> Subject: [boost] Re: BIL and boost::any

>> One can think of smart references as generalizations of any in which
>>
>> - the ownership policy can vary; e.g., it could be reference-counted
>> instead of
>> clone-on-copy
>> - the type of admissible objects can restricted using interfaces
>> - the syntax for binding is slightly different
>>
>> For instance, a reference-counted any that can bind to anything is
>> shared_obj<IAnything>.
>
> Would it be a reasonable request then to have clone(interface_value)?

Cloning must be introduced at some point. I've been trying to find a way to make
cloning just another function, but am becoming convinced it's sui generis. Since
Thortsen uses cloning for his Smart Containers library, I think I'll just borrow
concepts and machinery from him.

I'm not sure what you mean by "clone(interface_value)", though.

> Would make sense to also have dynamic traits, i.e.
> is_clonesable(interface_value). This seems to be pointing down a path
> of never ending feature requests to interface. I think it would be
> nice to lay down an easily extendible interface type. I mentioned
> earlier about allowing users to extend interface types. One way which
> I would like to extend interface types is to have an interface type
> which provides an extra function:

I don't really understand.

> Usage:
>
> dynamic_traits traits = extract_traits(interface_value);
>
> dyanmic_traits could be a class which provides run-time functions
> like:
>
> is_copy_constructible();
> is_default_constructible();
> size_of();
> is_primitive();
> is_integral();
> etc.

You could determine this stuff (to the extent the language allows) at the time
of binding, and make it available at runtime. However, most of this stuff is
useful only at compile time.

>> I'm thinking of adding a template boost::interfaces::any, which has
>> cloning
>> semantics and uses the same syntax as any for binding, i.e.,
>> assignment and
>> construction from a const reference.
>>
>> template<typename Interface = IAnything>
>> class any;
>>
>> (I think boost::interfaces::null might be a better name for
>> IAnything.)
>
> How about IUnknown? It will be especially meaningful when
> boost::interfaces allow dynamic introspection.

Even when reflection is added, you'll only be able to query the functions of the
interface; you won't be able to bind the underlying object to an interface
discovered at runtime -- unless this functionality is built into the class of
the bound object.

>> However, maybe what is needed instead is just a policy-based smart
>> reference.
>
> That would be a good thing.

I'm thinking now that smart references should have syntax like boost::any
instead of smart pointer syntax. They could be called smart interfaces.

> Excited about C++ again,

:-)

> Christopher

Jonathan


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk