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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 11232c,59ec73856b699922 X-Google-Attributes: gid11232c,public X-Google-Thread: f43e6,899fc98b2883af4a X-Google-Attributes: gidf43e6,public X-Google-Thread: fdb77,5f529c91be2ac930 X-Google-Attributes: gidfdb77,public X-Google-Thread: 1108a1,59ec73856b699922 X-Google-Attributes: gid1108a1,public X-Google-Thread: 103376,583275b6950bf4e6 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-05-21 06:57:15 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!headwall.stanford.edu!newsfeed.news2me.com!newsfeed2.earthlink.net!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!newsread2.prod.itd.earthlink.net.POSTED!not-for-mail Newsgroups: comp.lang.java.advocacy,comp.object,comp.lang.ada,misc.misc,comp.software-eng From: The Ghost In The Machine Subject: Re: Quality systems (Was: Using Ada for device drivers? (Was: the Ada mandate, and why it collapsed and died)) References: <9fa75d42.0304230424.10612b1a@posting.google.com> <9fa75d42.0305091549.48b9c5d9@posting.google.com> <7507f79d.0305121629.5b8b7369@posting.google.com> <9fa75d42.0305130543.60381450@posting.google.com> <254c16a.0305140549.3a87281b@posting.google.com> <9fa75d42.0305141747.5680c577@posting.google.com> <254c16a.0305160425.3bb89749@posting.google.com> <1053091306.979352@master.nyc.kbcfp.com> <7vaddj8k3d.fsf@vlinux.voxelvision.no> <7v65o78gtv.fsf@vlinux.voxelvision.no> <5ddnp-a63.ln1@lexi2.athghost7038suus.net> <1053436685.260636@master.nyc.kbcfp.com> X-face: "i;@/WO(?;[KC9sW;wG/4@H[_VFFH4?QHJ#O(?m}7fQMrJ,]0THA'\|e-EPG_>56Mi}_RRhBS'a2}u_7jm)0_+'=$V#E2r4#IQE/d)yMv3_4@hl<)mA&*tDN/ User-Agent: slrn/0.9.7.4 (Linux) Message-ID: Date: Wed, 21 May 2003 13:57:32 GMT NNTP-Posting-Host: 165.247.200.74 X-Complaints-To: abuse@earthlink.net X-Trace: newsread2.prod.itd.earthlink.net 1053525452 165.247.200.74 (Wed, 21 May 2003 06:57:32 PDT) NNTP-Posting-Date: Wed, 21 May 2003 06:57:32 PDT Organization: EarthLink Inc. -- http://www.EarthLink.net Xref: archiver1.google.com comp.lang.java.advocacy:64330 comp.object:63800 comp.lang.ada:37583 misc.misc:14332 comp.software-eng:19328 Date: 2003-05-21T13:57:32+00:00 List-Id: In comp.lang.java.advocacy, Hyman Rosen wrote on Tue, 20 May 2003 09:18:05 -0400 <1053436685.260636@master.nyc.kbcfp.com>: > The Ghost In The Machine wrote: >> A for_each() construct in C++/STL is highly preferable anyway. > > Only if you include some third-party stuff, like Boost's > Lambda Library. The problem with for_each and its ilk is > that you must supply a functor, and without this library > or something similar, that functor has to be defined out > of line, distant from the point where it is used. Using > LL, it's much simpler, and then for_each is OK. Not familiar with that particular library, or for that matter lambda expressions (although I've heard of them), but you're probably right, and certainly Java's construct helps a lot there. (It's the closest thing to a lambda expression -- which AIUI can be construed as an unnamed function -- that Java has.) > >> for_each(a,a+sizeof(a)/sizeof(a[0]),f); > > As I said in the other post, it's much better to define > begin and end function templates for arrays. Then do > for_each(begin(a), end(a), f); I must have missed that, but yes, that would be much cleaner. > You could also define begin and end for the other > container types and use uniform syntax: > template typename T::iterator > begin(std::vector &v) { return v.begin(); } > template typename T::const_iterator > begin(std::vector const &v) { return v.begin(); } > The problem is that if one defines #define begin(a) (a) #define end(a) ((a) + sizeof(a)/sizeof((a)[0])) one now cannot use templates. The C++ preprocessor is muy stupido. :-) One could try template A * begin(A * start, int s) { return start; } template A * end(A * start, int s) { return start + n / sizeof(A); } which would require constructs such as for_each(begin(a,sizeof(a)), end(a,sizeof(a)), f) Your other templates would of course require a second argument, which would simply be discarded, for the sake of consistency. It's not the prettiest of solutions, but C++ is not the prettiest of languages with respect to array handling. If one can afford the multinode copy, one might use a vector<> instead. (Note that sizeof(vector<>) is a constant. My brain hurts.) -- #191, ewill3@earthlink.net It's still legal to go .sigless.