Boost logo

Boost :

From: Tobias Schwinger (tschwinger_at_[hidden])
Date: 2006-01-27 16:14:58


Arkadiy Vertleyb wrote:
> "Tobias Schwinger" <tschwinger_at_[hidden]> wrote
>
>
>>[discussing approach with the function type...]
>
>
> So, if we decided to implement this approach, the following would need to be
> done:
>
> 1) change encode_type to modify the type before forwarding it to
> encode_type_impl, such as (pseudo-code):
>
> if (void)
> typedef my_return_type(*)(my_void) type;
> else if (const void)
> typedef my_return_type(*)(my_const_void) type;
> ...
> else
> typedef my_return_type(*)(T) type;
>
> (using function pointer would probably be more portable)
>
> 2) change all specializations of encode_type_impl to specialize on
> my_return_type(*)(T) instead of T, and to restore the special types;
>
> 3) implement REGISTER_SPEC in terms of parenthesized parameter.
>
> Do I understand this correctly?
>

Yes, I think so.

But the REGISTER_SPEC macro in itself is not enough, I'm afraid. Yes, it theoretically solves the "forward declaration problem" but can be very unpractical; let's therefore take a look at mpl::vector:

    template<typename T0, typename T1, ...
    // ^^ forward declaratoin

    REGISTER_TYPE(boost::mpl::vector<>)
    REGISTER_SPEC((typename),
                  boost::mpl::vector,
                  (boost::mpl::vector<P1, boost::mpl::n_a, boost::mpl::na ...
    REGISTER_SPEC((typename)(typename),
                  boost::mpl::vector,
                  (boost::mpl::vector<P1, P2, boost::mpl::na ...
    // ...

Not exactly user-friendly, is it?

While REGISTER_SPEC is definitely a nice feature, it would be great to have another macro for the special case illustrated by the example above, which
- forward declares a template, and
- registers all possible default argument specializations.
The interface would ideally look similar to a forward declaration with default arguments. BTW. here our "comma problem" pops up again (for the default arguments) but "Dave's function trick" can be applied again (and this time we get away without rather intrusive changes to the Typeof implementation):

    // given

    template<typename T> struct strip_special_func
    { typedef T type; };

    template<typename T> struct strip_special_func< ret_type(T) >
    { typedef T type; };

    // we can define a partial specialization like this one

    template<typename T> struct a_template
    < T, typename strip_special_func< my_type expr1 >::type
       , typename strip_special_func< my_type expr2 >
    { ...

OK. That's it for now.

> As far as wrapping is concerned, Outlook Express forces me to enter a value
> between 30 and 132 :-(

Good to know that the extra memory (and start-up time) for Thunderbird isn't entirely wasted ;-).

Regards,

Tobias


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