Boost logo

Boost :

From: Beman Dawes (beman_at_[hidden])
Date: 2000-07-27 11:47:50


The library contributors at www.boost.org have been tormented by VC++ 6.0,
particularly the lack of partial template specialization. So there is a lot
of interest in 7.0 (or whatever MS is calling it!)

I would appreciate it if any readers with the pre-beta could try to compile
and run the program below, and let me know what happens. It works fine on
Borland and Metrowerks compilers, but of course fails to compile on VC++
6.0 sp3.

I'll report the results on the boost mailing list. If you wish, I'll
credit you with the results, but otherwise will keep your name
confidential.

Thanks!

--Beman

---- cut here ----

// Does your compiler support partial specialization?

#include <iostream>
using std::cout;

// Examples from the ISO standard section 14.5.4
// modified to add constructor for reporting.

template<class T1, class T2, int I>
     class A { public: A(){cout<<"1 ";} }; // #1
template<class T, int I>
     class A<T, T*, I> { public: A(){cout<<"2 ";} }; // #2
template<class T1, class T2, int I>
     class A<T1*, T2, I> { public: A(){cout<<"3 ";} }; // #3
template<class T>
     class A<int, T*, 5> { public: A(){cout<<"4 ";} }; // #4
template<class T1, class T2, int I>
     class A<T1, T2*, I> { public: A(){cout<<"5 ";} }; // #5

// "The first declaration declares the primary (unspecialized)
// class template. The second and subsequent declarations
// declare partial specializations of the primary template."

int main()
{

// 14.5.4.1 gives these examples. Output should be "1 2 3 4 5 "

     A<int, int, 1> a1; // uses #1
     A<int, int*, 1> a2; // uses #2, T is int, I is 1
     A<int*, int, 2> a5a; // should use #3 (added by BGD)
     A<int, char*, 5> a3; // uses #4, T is char
     A<int, char*, 1> a4; // uses #5, T1 is int, T2 is char, I is 1

// If the following line is uncommented, the compiler should
// report an error, according to 14.5.4.1

// A<int*, int*, 2> a5; // ambiguous: matches #3 and #5

     return 0;
}
---- cut here ----


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk