From -6426197525817552067
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,e3e6d7e8b0bba763
X-Google-Attributes: gidf78e5,public
Path: g2news1.google.com!news2.google.com!newsfeed2.dallas1.level3.net!news.level3.com!newsfeed.mathworks.com!kibo.news.demon.net!mutlu.news.demon.net!demon!mail2news.demon.co.uk!devnull
From: tom_usenet@hotmail.com (tom_usenet)
Newsgroups: comp.std.c++
Subject: Re: function template overloading and name lookup
Date: Fri, 4 Jun 2004 16:10:32 +0000 (UTC)
Organization: [posted via Easynet UK]
Lines: 74
Approved: fjh@cs.mu.oz.au (Fergus Henderson , moderator of comp.std.c++)
Message-ID: <mnj0c0tm8t11h7iltfcvoq2n2rh6466gqs@4ax.com>
References: <40bdb74c$0$31680$afc38c87@news.optusnet.com.au>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
X-Trace: mail2news.demon.co.uk 1086365433 5347 10.0.0.1 (4 Jun 2004 16:10:33 GMT)
X-Complaints-To: abuse@demon.net
NNTP-Posting-Date: Fri, 4 Jun 2004 16:10:33 +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 1BWHH6-0001O6-00
	for mail2news@news.news.demon.net; Fri, 04 Jun 2004 16:10:32 +0000
X-Received: from mulga.cs.mu.OZ.AU (localhost [127.0.0.1]) by mulga.cs.mu.OZ.AU with ESMTP
	id i54GAUJ8028520; Sat, 5 Jun 2004 02:10:30 +1000 (EST)
X-Received: (from fjh@localhost)
	by mulga.cs.mu.OZ.AU (8.12.10+Sun/8.12.9/Submit) id i54GAUWO028511;
	Sat, 5 Jun 2004 02:10:30 +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-Newsreader: Forte Free Agent 2.0/32.646
X-Spam-Checker-Version: SpamAssassin 2.60-mulga_r1 (1.212-2003-09-23-exp) on 
	mulga.cs.mu.OZ.AU
X-Spam-Status: No, hits=-2.7 required=5.2 tests=AWL,BAYES_00,
	FORGED_HOTMAIL_RCVD2 autolearn=ham version=2.60-mulga_r1
Xref: g2news1.google.com comp.std.c++:645

On Thu, 3 Jun 2004 17:25:13 +0000 (UTC), nesotto@cs.auc.dk ("Thorsten
Ottosen") wrote:

>Hi All,
>
>Consider the small program below. What would you expect the output to be?
>
>#include <iostream>
>#include <deque>
>
>namespace foo
>{
>    template< class T >
>    inline void bar( T )
>    {
>        std::cout << " bar.T";
>    }
>
>    template< class T >
>    inline void use_bar( T t )
>    {
>        foo::bar( t );
>    }
>
>    template<>
>    inline void bar<int>( int i )
>    {
>        std::cout << " bar.Int";
>    }
>
>    template< class T, class A >
>    inline void bar( std::deque<T,A> d )
>    {
>        std::cout << " bar.Deque";
>    }
>}
>
>
>
>int main()
>{
>    using namespace foo;
>    use_bar( char() );

Will print bar.T, for obvious reasons.

>    use_bar( int() );

Will print bar.Int. This is less obvious. But because the explicit
specialization bar<int> has been declared before the point of
instantiation of bar<int>, (which is right after "main") it is fine.
This follows from 14.6.4.1/1 (for point of instantiation) and 14.7.3/6
for information about the declaration of the specialization having to
precede the use of it.

>    use_bar( std::deque<int>() );

Will print bar.T. This is because foo::bar is a non-dependent name,
and therefore is looked up at the point of definition, where the deque
overload is not visible.

(hastily checks with Comeau C++ and GCC 3.4 - both agree!)

Tom
-- 
C++ FAQ: http://www.parashift.com/c++-faq-lite/
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html

---
[ 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                       ]



