www.digitalmars.com         C & C++   DMDScript  

c++.beta - template class partial specialization

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

template<class T1, class T2>
struct A
{
  static const bool b = false;

  static void f()
  {
    printf("%08x %s %d\n", &A::f, typeid(A).name(), b);
  }
};

template<class T>
struct A<T, T>
{
  static const bool b = true;

  static void f()
  {
    printf("%08x %s %d\n", &A::f, typeid(A).name(), b);
  }
};


int main()
{
  A<int, int>::f();
  A<int, const int>::f();
  A<int, const int &>::f();
  A<int, int &>::f();
  A<int * const, int[2]>::f();
  A<int *, int[2]>::f();
  A<int *, int * const>::f();

  return 0;
}


And here is the output of the program if compiled with DMC:

00402120 A<int ,int > 1
00402144 A<int > 1
00402168 A<int ,int const &> 0
0040218c A<int ,int &> 1
004021b0 A<int *const ,int *const > 1
004021d4 A<int *,int *const > 1
004021d4 A<int *,int *const > 1

AFAIK, only the first one should use the specialized template, the others
should all use the unspecialized template.


Extracted from Boost's type_traits tests.


bye, Christof

-- 
http://cmeerw.org                                 JID: cmeerw jabber.at
mailto cmeerw at web.de

...and what have you contributed to the Net?
Jul 16 2003