From 5388689851925744162
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,44afe86040a81b68
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 1994-06-27 09:52:29 PST
Newsgroups: comp.std.c++
Path: bga.com!news.sprintlink.net!news.onramp.net!convex!cs.utexas.edu!howland.reston.ans.net!agate!msuinfo!harbinger.cc.monash.edu.au!news.cs.su.oz.au!metro!news
From: maxtal@physics.su.OZ.AU (John Max Skaller)
Subject: Re: Borland 4.0 template matching problem
Message-ID: <Cs2CtK.8Ku@ucc.su.OZ.AU>
Sender: news@ucc.su.OZ.AU
Nntp-Posting-Host: physics.su.oz.au
Organization: School of Physics, University of Sydney, Australia
References: <1994Jun22.222313.25212@cello.hpl.hp.com>
Date: Mon, 27 Jun 1994 16:08:07 GMT
Lines: 62

In article <1994Jun22.222313.25212@cello.hpl.hp.com> stepanov@cello.hpl.hp.com (Alex Stepanov) writes:
>There seems to be a problem with Borland finding a right template
>match. 

	No. There seems to a problem with the committee figuring
out what a type is. BC3.1 at least obeyed the ARM to the letter,
and as a consequence function templates were unusable.
This is NOT Borland's fault. The ARM type system is incoherent.
Not surprisingly, that means templates dont work properly.

>For example, compiling the file "test.cpp":
>> 
>> #include <sdtlib.h>
>> int main() {
>> 	int a[2];
>> 	return a == max(a, a+1);
>> }
>> 
>
>gets the following error message:
>
>> C:\TURBO>bcc test.cpp
>> Borland C++ Version 4.00 Copyright (c) 1993 Borland International
>> test.cpp:
>> Error test.cpp 4: Could not find a match for 'max(int *, int *)' in function main()
>> *** 1 errors in Compile ***
>> 
>Is there a known workaround?

	The function in BC4.0 is declared:

	T const& max(const T&, const T&);

An "exact match" interpretation requires a const T& argument.
Of course, thats ridiculous, in fact there is no expression of
reference type in the WP anymore.  I had this problem
with Borland 3.1 and gave up using function templates.
It got seriously confused, thinking there was some sort of

	'const T'

type. This is plain daft, but the committee thinks such a type exists. 
So your problem is you need to pass

	int * const

arguments to the template to match it. In BC3.1 there is a
a work-a-long-way-around:

	int *const& a = a;
	int *const& b = a+1;
	max(a,b);

because now there's an "exact match".

[BTW: I havent tried that particular example]

--
        JOHN (MAX) SKALLER,         INTERNET:maxtal@suphys.physics.su.oz.au
	Maxtal Pty Ltd,		    CSERVE:10236.1703 
        6 MacKay St ASHFIELD,	    Mem: SA IT/9/22,SC22/WG21 
        NSW 2131, AUSTRALIA	    


