Topic: Defect Report: Koenig lookup questions


Author: Hyman Rosen <hymie@prolifics.com>
Date: 2000/03/28
Raw View
[ moderator's note: Forwarded to C++ commmittee. -sdc ]

Martin von Loewis <loewis@informatik.hu-berlin.de> writes:
> Why is that? It still is is a postfix-expression, so 3.4.2 still
> applies. 3.4.2/2 makes an exception if ordinary lookup finds a member
> declaration; it does not make an exception if it finds a block-scope
> declaration.

You're probably right. But I find this to be a defect. I would modify
3.4.1/3 to say that 3.4.2 is used if ordinary lookup fails or finds a
function name. Without this, you can get truly counter-intuitive
effects -

template <typename T>
void mysort(T array[], int n, int (*cmp)(T &, T &), void (*swap)(T &, T &))
{
 for (int i = 0; i < n; ++i)
  for (int j = i + 1; j < n; ++j)
   if (cmp(array[i], array[j]) > 0)
    swap(array[i], array[j]);
}

Suppose I use this to sort an array of std::vector<int>. If Koenig lookup
is applied to the call of swap, it will find std::swap. Surely this cannot
be the intention of the Standard.



[ 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://reality.sgi.com/austern_mti/std-c++/faq.html              ]