Boost logo

Boost :

Subject: Re: [boost] Formal Review Request: TypeErasure
From: lcaminiti (lorcaminiti_at_[hidden])
Date: 2012-06-06 17:38:57


Maybe I used the wrong term in saying "arbitrary". I meant it looks
arbitrary to users because it essentially just exposes a library
implementation detail (but it's clear it's a "special" base that the lib
needs you to put there for the implementation to work). There is probably no
way for getting rid of Base, Enable, etc but to use macros. I think macros
would be a nice addition as an alternative to define concepts in your lib.
I'll see what macro syntax could be implemented (especially with variadic
macros, we can do a lot of nice stuff).

If there was a desire for it, /maybe/ the following macro could be
implemented:

BOOST_TYPE_ERASURE_CONCEPT(
    concept (push_back_callable) ( class C, typename T )
    (
        void member_body(C, push_back) ( (T const&) value ) ;
    )
)

std::vector<int> v;
boost::type_erasure::any<
      boost::type_erasure::push_back_callable<_self, int>
    , _self&
> c(v);
c.push_back(10);

The macro would expand to code equivalent to this (from TypeErasure docs):

namespace boost { namespace type_erasure {

template< class C, typename T>
struct push_back_callable
{
    static void apply ( C& obj, T const& value )
    {
        obj.push_back(value);
    }
};

template< class C, typename T, class Base >
struct concept_interface< push_back_callable<C, T>, Base, C > : Base
{
    void push_back ( typename rebind<Base, T const&amp;>::type value )
    {
        call(push_back_callable<C, T>(), *this, value);
    }
};

}} // namespace

I haven't tried to implement the macro so I can't be sure if it can be done.
Also, I'd have to study your TypeErasure lib more to make sure the macro is
general enough to handle all cases where TypeErasure concepts can be
defined.

--Lorenzo

--
View this message in context: http://boost.2283326.n4.nabble.com/Formal-Review-Request-TypeErasure-tp4630373p4630993.html
Sent from the Boost - Dev mailing list archive at Nabble.com.

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