|
Boost : |
Subject: Re: [boost] [type_erasure] Overloading
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2013-02-13 13:13:22
AMDG
On 02/12/2013 02:59 PM, Christophe Henry wrote:
> Hi Steven,
>
> I'm afraid I might need some help again.
> I try to take as model the example in the doc
> (http://steven_watanabe.users.sourceforge.net/type_erasure/libs/type_erasure/doc/html/boost_typeerasure/concept.html#boost_typeerasure.concept.overload).
>
> First problem, it seems that the example has a typo. It will not
> compile without a :Base in the concept_interface specialization:
>
> struct concept_interface< ::foo<T, U,void>, Base, T, Enable> : Base
> ...
>
You are correct. Fixed in svn.
> Second, the example overload.cpp includes a as_param.hpp which no more exists.
>
Fixed. It should be param.hpp.
> But my problem is that I need an overload with 1 and 2 parameters:
>
> Test t;
> any<
> mpl::vector<
> foo<_self, int>,
> foo<_self, int, double>,
> boost::type_erasure::copy_constructible<>
> >
> > x (t);
> x.foo(1); // calls foo(int)
> x.foo(1,1.0); // calls foo(int, double)
>
> I don't get this to compile, the second foo cannot be found, I suppose
> the first one hides the second.
>
Yep. You need two more specializations.
>
> Here my failed attempt (well, one of them ;-) ):
>
> template<class T, class U, class V=void, class Enable=void>
> struct foo
> {};
>
> <snip>
>
> namespace boost {
> namespace type_erasure {
>
> template<class T, class U, class Base, class Enable>
> struct concept_interface< ::foo<T, U,void>, Base, T, Enable>;
>
This specialization (a) will be used for one argument
as the first instance of foo.
> template<class T, class U, class V, class Base>
> struct concept_interface< ::foo<T, U,V>, Base, T, typename
> Base::_fun_defined>;
>
This specialization (b) will be used for two arguments
as the second and subsequent instances of foo.
The order in which sibling concepts appear is unspecified.
In this case what is actually happening is that
foo<_self, int, double> is added first, and neither
specialization (a) nor specialization (b) matches.
What you need to add are the following:
template<class T, class U, class V, class Base, class Enable>
struct concept_interface< ::foo<T, U,V>, Base, T, Enable>;
template<class T, class U, class V, class Base, class Enable>
struct concept_interface< ::foo<T, U,void>, Base, T, typename
Base::_fun_defined>;
> }
> }
>
> <snip>
>
> int main()
> {
> Test t;
> any<
> mpl::vector<
> foo<_self, int>,
> foo<_self, int, double>,
> boost::type_erasure::copy_constructible<>
> >
> > x (t);
> x.foo(1); // calls foo(int)
> x.foo(1,1.0); // calls foo(int, double)
> return 0;
> }
>
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