RE: [Boost-Users] std::swap() vs boost::swap()
From: Galante Michele [mailto:M.Galante@centrosistemi.it]
Argument-dependent lookup will ensure that any 'swap' functions in the namespaces used by 'T' will be included in the set of known swap functions, along with std::swap. Overloading and partial ordering of function templates will then take over to ensure that the appropriate swap(a, b) will be called (even if it is boost::swap).
I did not know this. I suppose this is the "Koenig lookup" that Steve mentions in his reply. I've tried this and it works with GCC 3.1 but unfortunately not with BCC 5.6 (so I think it is a Borland bug).
Yes "Koenig lookup" is "argument-dependent lookup", and sadly several compilers still do not implement it. There's a workaround for the lack of Borland's support: using std::swap; // This should have been in my example to begin with... using boost::swap; swap(x, y); Which works on GCC 3.1.1 and BCC 5.6, and I would imagine any other compiler as well. The downside is that you have to list in your "generic" function all the namespaces that it can be used with -- which then makes it not-very-generic on compilers without Koenig lookup. But it's better than nothing... -Steve
participants (1)
-
sclearyï¼ jerviswebb.com