Boost logo

Boost :

From: Marco Costalba (mcostalba_at_[hidden])
Date: 2007-09-19 01:47:18


Hi Tobias,

On 9/18/07, Tobias Schwinger <tschwinger_at_[hidden]> wrote:
> >
> > template<typename T1>
> > static Base* object(detail::KeyRef nm, T1 a1)
>
> This one will fail to compile with a non-copyable argument for 'a1'
> (unless 'T1' is specified explicitly to be a reference).
>

Yes, but something like

static Base* object(detail::KeyRef nm, T1& a1)

will fail with temporaries and something like

static Base* object(detail::KeyRef nm, const T1& a1)

will fail when c'tor arguments should be modified by the c'tor.

I choose the first one because, as you noted, is the only one for whom
exists a simple and 'intuitive' workaround for those (rare) cases:
specify explicitly to be a reference.

BTW, a little digression, if the standard would allow to elide
argument passing for inline functions the real solution would be:

template<typename T1>
inline Base* shell(detail::KeyRef nm, T1 a1)
{
      return object<T1>(nm, a1);
}

template<typename T1>
Base * object<T1>(detail::KeyRef nm, traits<T1>::parameter a1);

In this case the 'shell' is just a way to allow to typedef the type T
inside a trait before to evaluate the argument and avoid the user to
specify it explicitly...but unfortunately this does not work....I
tried ;-)

>
> Maybe you mean that 'boost::factory<a_concrete>' and 'boost::factory<
> another_concrete>'are distinct (even incompatible) types?
>
> The clue is that both can be turned into objects of type
> 'boost::function<an_abstract*() >' to become polymorphic runtime entities.
>

I think your scheme will have troubles with multi argument support
because you need to foreseen more abstract bases:

an_abstract*(T1)
an_abstract*(T1,T2)

etc..

All with different types and this breaks single base polymorphic
assumption -> you need one map for each argument arity. Perhaps for
each argument arity _and_ types.

Marco


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