Boost logo

Boost :

Subject: Re: [boost] [type_erasure] Review ends today July 27, 2012
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2012-08-01 09:23:23


AMDG

On 08/01/2012 05:34 AM, Joel de Guzman wrote:
>>>>> 3. What is your evaluation of the documentation?
>
> I just skimmed through the docs to get what I need (see below). It
> would be good to have examples at the bottom of each of the reference
> sections like that of MPL, Fusion and the PPlib. Example:
>
> http://www.boost.org/doc/libs/1_50_0/libs/mpl/doc/refmanual/fold.html
>
> At the bottom, we have an example.
>

Noted.

>>>>> 5. Did you try to use the library? With what compiler? Did you have
>>>>> any problems?
>
> Yes. I tried to use it as a replacement for Boost.Function in Boost.Spirit.
> It worked like a charm. My only difficulty was in trying to figure out
> how to detect a default-initialized 'any'. With Boost.Function, you can use
> an instance in a condition, e.g. if (f) ... This seems to be not the case
> with 'any'. I'm pretty sure this is something simple to do, but I can't dig
> it out in the docs.

any_cast to void* is the simplest way that
exists right now.

Something like this would enable a bool conversion:

template<class T = _self>
struct empty_bool_conversion : mpl::vector<> {};

template<class T, class Base>
struct concept_interface<empty_bool_conversion<T>, Base, T> : Base {
  explicit operator bool() const {
    return any_cast<void*>(static_cast<
      const typename derived<Base>::type*>(*this)); }
};

> I ended up casting to void*. It turns out that it
> returns
> 0 (null) if any hasn't been initialized yet. I'm not sure about the cost of
> that though (would that have to use RTTI? It seems that way as it says in
> the any_cast docs: http://tinyurl.com/d8sx46m where it says that typeid_
> is required.
>

I'll fix the documentation. RTTI shouldn't
be required for a cast to void*.

> I did a CT test on one of the largest examples in spirit. I compared
> it against 1) the original implementation using Boost.Function and
> 2) A hand-coded implementation using virtual functions. Here are
> the results:
>
> TypeErasure: 01:14 secs
> Boost.Function: 00:55 secs
> Virtual Function: 00:52 secs
>

That's expected. There are a number of
constructs that I know are inefficient
in my metaprogramming. I haven't made
any attempt to optimize it yet.

> For that matter, I'm not ready to use TypeErasure yet for my purpose,
> but I'm hoping that Steven can improve CT. It might also be possible
> that I am using TypeErasure incorrectly when I resort to any_cast to
> test for null any. Would this explain the CT slowdown? I am not sure.
>

Using any_cast like this should have
little effect on compile-time performance.

> I'd also suggest the addition of an easy to use Boost.Function
> replacement in there that can be used out of the box with full
> compliance.
>

It isn't possible to replicate Boost.Function
perfectly.

a) Boost.Function doesn't care about the
   constness of function call operator.
b) Boost.Function has special handling for boost::ref

I don't really want to replicate either behavior.

In Christ,
Steven Watanabe


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