From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,703c4f68db81387d X-Google-Thread: 109fba,703c4f68db81387d X-Google-Thread: 115aec,703c4f68db81387d X-Google-Thread: f43e6,703c4f68db81387d X-Google-Attributes: gid103376,gid109fba,gid115aec,gidf43e6,public X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!news1.google.com!proxad.net!134.158.69.22.MISMATCH!in2p3.fr!oleane.net!oleane!not-for-mail From: =?ISO-8859-1?Q?Falk_Tannh=E4user?= Newsgroups: comp.lang.ada,comp.lang.c++,comp.realtime,comp.software-eng Subject: Re: Teaching new tricks to an old dog (C++ -->Ada) Date: Tue, 08 Mar 2005 14:02:52 +0100 Organization: Canon Research Centre France Message-ID: References: <4229bad9$0$1019$afc38c87@news.optusnet.com.au> <1110032222.447846.167060@g14g2000cwa.googlegroups.com> <871xau9nlh.fsf@insalien.org> <3SjWd.103128$Vf.3969241@news000.worldonline.dk> <87r7iu85lf.fsf@insalien.org> <87is4598pm.fsf@insalien.org> <1110054476.533590@athnrd02> <1110059861.560004@athnrd02> <87wtsl7jts.fsf@insalien.org> <1110264816.858853.54020@l41g2000cwc.googlegroups.com> NNTP-Posting-Host: centre.crf.canon.fr Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable X-Trace: s1.news.oleane.net 1110286972 20068 194.2.158.33 (8 Mar 2005 13:02:52 GMT) X-Complaints-To: abuse@oleane.net NNTP-Posting-Date: Tue, 8 Mar 2005 13:02:52 +0000 (UTC) User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20041217 X-Accept-Language: de, fr, pl, en, en-us In-Reply-To: <1110264816.858853.54020@l41g2000cwc.googlegroups.com> Xref: g2news1.google.com comp.lang.ada:8854 comp.lang.c++:44596 comp.realtime:1060 comp.software-eng:4612 Date: 2005-03-08T14:02:52+01:00 List-Id: Jerry Coffin wrote: > A poor idea. Just for example, consider writing a generic sorting > function. It needs to swap items that it's sorting. In well-written > C++, this will often be done with a using clause. Specifically, if the > type of items has provided its own specialized version of swap, then my= > sorting functino should use that, but otherwise it should use std::swap= > to swap them. >=20 > If I try to specify whatever_type::swap(x,y), then compilation will > fail if the type has not provided a swap function. Conversely, if I > specify std::swap(x,y), then the specialized swap function won't be > used for those types that provide one. >=20 > The solution is something like: >=20 > using namespace std; >=20 > template > void sort // ... >=20 > // ... > swap(x,y); >=20 > and now, thanks to Koenig lookup, this will refer to a swap > specifically for the type of x and y if there is one, but will use the > swap in the standard library for those (many) types that don't provide > special swapping code. I would put the "using namespace std;", or even better, just "using std::swap;" into the "sort" function, at the scope of the block from where the "swap" is called. This way, the precise purpose of the "using" declaration becomes clear to both the human reader and the compiler (because unwanted side effects due to name collisions are avoided). Furthermore, the implementer of "whatever_type" should consider to put the specialisation of "swap" into the "std" namespace, which is possible by =A7 17.4.3.1/1 of the Standard. Falk