Re: class composition
On 01/24/11 16:31, er wrote:
Hi,
Is there a way to define A such that if B is defined like this
struct tag1{};
struct tag2{};
struct B : A<tag1, int>, A<tag2, double>{};
then
typedef B::F<tag1>::type v1_ // v1_ == int;
typedef B::F<tag2>::type v2_; // v2_ == double
By analogy, the above is feasible for a member function, say f,
template<typename Tag, typename T> struct A{
T f(Tag){ return T(); }
};
struct B : A<tag1, int>, A<tag2, double>
{
typedef A<tag1, int> a1_; using a1_::f;
typedef A<tag2, double> a2_; using a2_::f;
};
Yes. This technigue of overloading a function within
a class with a tag in order to select a the function in an
inheritance hierarchy was used here:
http://svn.boost.org/svn/boost/sandbox/variadic_templates/boost/composite_storage/layout/operators_one_of_maybe.hpp
The overloaded function was the static:
boost::composite_storage::layout::operators<one_of_maybe,,,,>::
push_back<HeadLayout,TailComponent>::inject(index_part,...)
Although inject is static instead of a member function, I think
it would work for member functions also. The tag in the
above call is the index_part.
HTH.
Larry