From: Peter Dimov (pdimov_at_[hidden])
Date: 2001-10-18 13:27:11
From: "Jim.Hyslop" <jim.hyslop_at_[hidden]>
> Peter Dimov [SMTP:pdimov_at_[hidden]] wrote:
> > While we are on the topic:
> > The article
> > http://www.cuj.com/experts/1912/hyslop.htm
> > asserts that any_cast will work unqualified due to Koenig lookup.
> > note that it has an explicit template parameter. I'm not sure whether
> > argument dependent lookup will work in this case.
> The compiler I use doesn't support Koenig lookup, so I blush to admit it's
> one of those things I haven't bothered learning all the details about (I
> know the general idea, of course). My original code sample qualified the
> of any_cast, but Kevlin assured me Koenig lookup should work.
> I'm not clear how you see that explicit template parameters will affect
> Koenig lookup. I've checked the standard, and my reading of 3.4.2 supports
> Kevlin's (and therefore my) position.
> Let me explain my reasoning on why I think it should work:
> The name being looked up is a template function named "any_cast". The
> "argument type T in the function call" (as the standard puts it), is
> any'. The second bullet says "If T is a class type, its ... associated
> namespaces are the namespaces in which its associated classes are defined"
> which, in this case, is boost. Therefore namespace boost should be
> for a template named "any_cast".
I'm not as up-to-date with the standard as I'd have liked; that's why I said
that I'm not sure whether this will work or not.
The problem is not whether the set of associated namespaces contains
'boost'; the problem is whether an expression of the form
template-id ( expression-list opt )
will invoke Koenig lookup.
3.4.2 says: "when an unqualified name is used as the posfix-expression in a
function call (5.2.2)...". 5.2.2 doesn't tell us anything useful, but 5.1/11
has this to say: "A template-id shall be used as an unqualified-id only as
specified in 14.7.2, 14.7, and 14.5.4.)
So I believe that Comeau is right. It usually is. :-)
-- Peter Dimov Multi Media Ltd.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk