www.digitalmars.com         C & C++   DMDScript  

c++.beta - class template partial specialization

reply Christof Meerwald <cmeerw web.de> writes:
Hi,

#include <typeinfo>
#include <stdio.h>

template<class T>
struct A
{
  static void f()
  {
    printf("%08x %s\n", &A::f, typeid(A).name());
  }
};

template<class T>
struct A<const T>
{
  static void f()
  {
    printf("const: %08x %s\n", &A::f, typeid(A).name());
  }
};

int main()
{
  A<int & const>::f();
  A<int &>::f();
  A<int & volatile>::f();
  A<int & const volatile>::f();

  return 0;
}


The output depends on the order of template instantiations, but I guess 
the primary class template should always be used in this example.


bye, Christof

-- 
http://cmeerw.org                                 JID: cmeerw jabber.at
mailto cmeerw at web.de
Aug 22 2003
parent Christof Meerwald <cmeerw web.de> writes:
On Fri, 22 Aug 2003 17:45:07 +0000 (UTC), Christof Meerwald wrote:
   A<int & const>::f();
   A<int &>::f();
   A<int & volatile>::f();
   A<int & const volatile>::f();

This one was probably ill-formed, see 8.3.2 References [dcl.ref]: "Cv-qualified references are ill-formed except when the cv-qualifiers are introduced through the use of a typedef (7.1.3) or of a template type argument (14.3), in which case the cv-qualifiers are ignored." But this one should be ok (and it should always choose the primary template): #include <typeinfo> #include <stdio.h> template<class T> struct A { static void f() { printf("%08x %s\n", &A::f, typeid(A).name()); } }; template<class T> struct A<const T> { static void f() { printf("const: %08x %s\n", &A::f, typeid(A).name()); } }; template<class T> struct B { static void f() { A<T const>::f(); A<T>::f(); A<T volatile>::f(); A<T const volatile>::f(); } }; typedef int &intref; int main() { A<intref const>::f(); A<intref>::f(); A<intref volatile>::f(); A<intref const volatile>::f(); B<int &>::f(); return 0; } bye, Christof -- http://cmeerw.org JID: cmeerw jabber.at mailto cmeerw at web.de ...and what have you contributed to the Net?
Sep 06 2003