Boost logo

Boost :

Subject: Re: [boost] An alternative approach to TypeErasure
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2012-06-24 10:21:32


AMDG

On 06/24/2012 03:34 AM, Pyry Jahkola wrote:
>
> I am aware that Steven Watanabe has put some astonishing work on his
> proposed Boost.TypeErasure. I'm open for discussion whether and how his
> or mine is a better approach, or if we could combine these into an
> eventual Boost.Interface library or such!
>

I don't think your approach is fundamentally
very different from mine. Consider:

template<class T = _self>
struct to_string {
  static std::string apply(T const&) { return std::to_string(t); }
};

typedef boost::type_erasure::any<
  mpl::vector<copy_constructible<>,
  to_string<> > > x(...);

call(to_string<>(), x);

vs.

POLY_CALLABLE(to_string);
template<class T>
std::string call(to_string_, T const& t) { return std::to_string(t); }

poly::interface<std::string(to_string_, poly::self)> x(...);

to_string(x);

The changes are:
1) replace a static member apply, with a free function call
2) copy_constructible<> is implicit
3) The concept is deduced from the signature, instead
   of the signature being deduced from the concept.
4) replace call(to_string<>, x) with to_string(x)

The transformation is basically 1-to-1. In principle,
every feature of my library could be implemented
with yours and vice versa, just changing the base
definitions.

There's only one real difference in capability.
Compare:
call(to_string<>(), x) with to_string(x).
My library knows from the signature of to_string<>,
that it should dispatch on the first (and only)
argument, while yours has to deduce this
from the arguments. This can only cause
an unresolvable ambiguity for mutually recursive
anys like this:

template<class T1, class T2>
struct aconcept { static void apply(const T1&, const T2&); };

struct concept1;

struct concept2;

struct concept1 :
  boost::mpl::vector<
    copy_constructible<>,
    aconcept<_self, any<concept2> > >
{};

struct concept2 :
  boost::mpl::vector<
    copy_constructible<>,
    aconcept<any<concept1>, _self> >
{};

The way you handle template arguments
to poly::interface makes it impossible to
create this kind of mutually recursive any.

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