From 1745167085697145565
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,3b5faa9aaea18095
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 2003-09-23 11:54:25 PST
Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!kibo.news.demon.net!mutlu.news.demon.net!demon!mail2news.demon.co.uk!devnull
From: Christian.Theis@nospam.cern.ch ("Chris Theis")
Newsgroups: comp.std.c++
Subject: Re: Problem with function template overload resolution
Date: Tue, 23 Sep 2003 18:54:23 +0000 (UTC)
Organization: CERN
Lines: 124
Approved: fjh@cs.mu.oz.au (Fergus Henderson , moderator of comp.std.c++)
Message-ID: <bkos2l$8t1$1@sunnews.cern.ch>
References: <4e6fccc6.0309162227.1aa4bda7@posting.google.com> <3F6E975F.8050300@grad.hr>
X-Trace: mail2news.demon.co.uk 1064343263 26865 10.0.0.1 (23 Sep 2003 18:54:23 GMT)
X-Complaints-To: abuse@demon.net
NNTP-Posting-Date: Tue, 23 Sep 2003 18:54:23 +0000 (UTC)
X-Received: from mulga.cs.mu.oz.au ([128.250.1.22])
	by news.demon.co.uk with esmtp (Exim 4.12)
	id 1A1sIo-0006zA-00
	for mail2news@news.news.demon.net; Tue, 23 Sep 2003 18:54:22 +0000
X-Received: from localhost (localhost [[UNIX: localhost]]) by mulga.cs.mu.OZ.AU
	id EAA04361; Wed, 24 Sep 2003 04:54:20 +1000 (EST)
X-Authentication-Warning: mulga.cs.mu.OZ.AU: fjh set sender to devnull@stump.algebra.com using -f
X-Path: comp-std-cpp-robomod!not-for-mail
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
X-Delivered-To: std-c++@ucar.edu
X-Newsgroups: comp.std.c++
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
X-Spam-Status: No, hits=0.7 required=5.0
	tests=HTML_00_10,PRIORITY_NO_NAME,QUOTED_EMAIL_TEXT,REFERENCES
	version=2.55
X-Spam-Checker-Version: SpamAssassin 2.55 (1.174.2.19-2003-05-19-exp)
Xref: archiver1.google.com comp.std.c++:20837


"Kresimir Fresl" <fresl@grad.hr> wrote in message
news:3F6E975F.8050300@grad.hr...
>
> Joerg Walter wrote:
>
> > I've already tried to discuss the following two programs on
> > comp.lang.c++.moderated. Kresimir Fresl's test case
> >
> > ----------
> > #include <iostream>
> >
> > template<typename A, typename T>
> > struct result {};
> >
> > template<typename T>
> > struct arg1 {
> >    typedef T value_type;
> > };
> > template<typename T>
> > struct arg2 {
> >    typedef T value_type;
> > };
> >
> > template<typename A>
> > result<A, typename A::value_type> foo(A const& a) {
> >    std::cout << "foo<A>" << std::endl;
> >    return result<A, typename A::value_type>();
> > }
> > template<typename R, typename A>
> > R foo(A const& a) {
> >    std::cout << "foo<R, A>" << std::endl;
> >    return R();
> > }
> >
> > int main() {
> >    arg1<int> s1;
> >    arg2<int> s2;
> >
> >    foo(s2);    // OK
> >
> >    foo<arg1<int>, arg2<int> >(s2);  // OK
> >    foo<arg2<int>, arg2<int> >(s2);  // OK
> >
> >    foo<arg1<int> >(s2);    // OK
> >    foo<arg2<int> >(s2);    // Ambigous?
> > }
> >
> > ----------
> >
> > is accepted by GCC 3.3.1, a program run results in
> >
> > foo<A>
> > foo<R, A>
> > foo<R, A>
> > foo<R, A>
> > foo<R, A>
> >
> > ICC 7.1 and MSVC 7.1 reject this code.
>
> And Comeau C/C++ 4.3.0.1, too.
>
> Some time ago (in January) I asked Comeau's support team about
> it. Here is their reply:
> ================================================================
> [...] We suspect your case
> is ill-formed but still need to go through that Standard more
> thoroughly on it before saying so for certain, and we also want
> to double check it is not impacted by any pending defect report.
> ================================================================
>
> But they never said `so for certain', and, if `so', why.
>
> Regards,
>
> Kresimir Fresl
>
>
> PS. I also tried 4.3.3 beta online:
>
>     http://www.comeaucomputing.com/tryitout/
>

According to the Standard (chapter about type deduction for partial
specialized templates) there is no such thing as partial specialization for
functions (yet). The closest thing you can get your hands on to is
overloading. Thanks to A. Alexandrescu here is a neat idea which puts this
into action:

template <typename T>
struct CType2Type {
  typedef T OriginalType;
};

template< class T, class U>
T* Create( const U& Argument, CType2Type<T> )
{
  return new T( Argument );
}

template<class U>
CMyObj* Create( const U& Argument, CType2Type<CMyObj>)
{
  return new CMyObj( Argument );
}

CMyOtherObj* = Create( "test", CType2Type<CMyOtherObj>() );     // calling
generic version
CMyObj* = Create( "test", CType2Type<CMyObj>() );                      //
calling "specialized" version


The honor of this idea & example go to Andrei, a real template guru!

HTH
Chris


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]



