Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #11421
| From | Edek <edek.pienkowski@gmail.com> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: nested templates and partial specialization |
| Date | 2011-11-12 16:18 +0100 |
| Organization | ATMAN - ATM S.A. |
| Message-ID | <j9m2lp$rlu$1@node2.news.atman.pl> (permalink) |
| References | (1 earlier) <8ff5cd3a-72b4-46c9-8d97-23b7ed9b9d82@k10g2000yqn.googlegroups.com> <j9ldee$5pq$1@node2.news.atman.pl> <8749ba8c-95da-46f8-a9c0-a9e44a143158@cu3g2000vbb.googlegroups.com> <j9lqmq$jnb$1@node2.news.atman.pl> <1d599554-4659-4b13-9ade-077a2c67cddf@s5g2000vbe.googlegroups.com> |
On 11/12/2011 02:07 PM, ld wrote:
> But it is not anymore a specialization for B<T> but just T, that is
> why it works. Assume that another class C<T> wants to specialize it
> too. How does it make the difference? Moreover, in this case, typename
> and class have the same meaning (not always the case though).
Yes, right, sorry.
Actually I think you are trying a member specialisation by a weird
specialisation of the class (just the method, not whole class). It
works with sfinae, but not for virtual methods, and I am not sure
about partial class specialisations.
The below uses inheritance to get the example working - I don't know
if this fits your usage, but inheritance is one way of doing such
things.
Edek
// type declaration
template <typename T, typename I>
struct E; // line 3
// abstract class
struct D {
virtual void doit() const = 0;
};
template <class T, class TT> struct helper {
void doitInternal (T const&) const;
};
// partial specialization
template <class T>
struct E<T, D> : public helper<T,D> {
virtual void doit() const;
explicit E(T = T());
T& e;
};
// simple class
struct A {
void doit() const;
int a;
};
// template class
template <typename T>
struct B {
void doit() const;
T b;
};
// specialization with class, ok
template <>
void E<A, D>::doit() const
{
e.doit();
}
template <class T>
struct helper<B<T>, D> {
void doitInternal (B<T> const&) const;
};
template <class T>
void E<T, D>::doit() const
{
doitInternal(e);
}
template <class T, class TT>
void helper<T,TT>::doitInternal(T const&) const {}
template <class T>
void helper<B<T>, D>::doitInternal(B<T> const& e) const // line 43
{
// for B<T>
e.doit();
}
int main() {
E<A, D> a;
E<B<int>, D> b;
}
Back to comp.lang.c++ | Previous | Next — Previous in thread | Find similar | Unroll thread
nested templates and partial specialization ld <laurent.deniau@gmail.com> - 2011-11-11 15:45 -0800
Re: nested templates and partial specialization ld <laurent.deniau@gmail.com> - 2011-11-11 23:41 -0800
Re: nested templates and partial specialization Edek <edek.pienkowski@gmail.com> - 2011-11-12 10:16 +0100
Re: nested templates and partial specialization ld <laurent.deniau@gmail.com> - 2011-11-12 03:33 -0800
Re: nested templates and partial specialization Edek <edek.pienkowski@gmail.com> - 2011-11-12 13:52 +0100
Re: nested templates and partial specialization ld <laurent.deniau@gmail.com> - 2011-11-12 05:03 -0800
Re: nested templates and partial specialization Edek <edek.pienkowski@gmail.com> - 2011-11-12 14:02 +0100
Re: nested templates and partial specialization ld <laurent.deniau@gmail.com> - 2011-11-12 05:07 -0800
Re: nested templates and partial specialization Edek <edek.pienkowski@gmail.com> - 2011-11-12 16:18 +0100
csiph-web