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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,243dc2fb696a49cd X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!proxad.net!news.cs.univ-paris8.fr!news.zanker.org!newsfeed00.sul.t-online.de!newsmm00.sul.t-online.de!t-online.de!news.t-online.com!not-for-mail From: Martin Krischik Newsgroups: comp.lang.ada Subject: Re: Ada Popularity: Comparison of Ada/Charles with C++ STL (and Perl) Date: Sun, 26 Sep 2004 17:35:06 +0200 Organization: AdaCL Message-ID: <3750337.aJMmIeXcav@linux1.krischik.com> References: <1777528.JKnUEYTOM6@linux1.krischik.com> <1ec946d1.0409230820.455ad242@posting.google.com> <3673998.bj16mkkOu2@linux1.krischik.com> <1700922.2nPlMsa4Ny@linux1.krischik.com> Reply-To: krischik@users.sourceforge.net Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit X-Trace: news.t-online.com 1096214034 01 13247 sIAjXN71YQfvSnSC 040926 15:53:54 X-Complaints-To: usenet-abuse@t-online.de X-ID: bMI22mZlreuafr5I+1WpyAAM94L0-ly+VUjkiNyjKe-4JkXGRdlP0y User-Agent: KNode/0.8.0 Xref: g2news1.google.com comp.lang.ada:4217 Date: 2004-09-26T17:35:06+02:00 List-Id: Hi, Robert Kawulak wrote: > >> In 99.99% of all cases I don't need strings on user defined types. I need >> base_string. I can see that I one day might need >> base_string, but I have not until now. They made all that funky >> design which I just never need. > > And the best thing is that if you don't need it, you don't have to use > it. Yet still there is this 0.01% of cases when this approach is extremely > useful because of its flexibility. E.g. when you want a class of > case-insensitive strings - you just reuse the basic string template like > this: > //class defining character traits > class my_char_traits: public std::char_traits > { > //here you just redefine simple comparison > //functions like eq() to be case-insensitive > }; > > //case-insensitive string class > typedef std::basic_string cis_string; > >> Would have been so easy, so usefull but it would not have been a >> template. The "all is template" religion got in there way. > > Actually you might not even know that std::string is a typedef of > template instantiation and still use it as if nothing had happened. I know that. And I was wondering why. >> And just for the record: atio is a C function - you need the overhead of >> convertion the std::string into a char* and std::strstream seem quite >> heavy >> weight for just a simple task of convertion a string from and to an int. > > Actually, the overhead of conversion is virtually none (at least in > Stlport implementation). You just call std::string::c_str() which just > returns a pointer to the data, and which is also inlined. >From what I read about std::string strings do not need to be '\0' terminated and std::string::c_str() will add a terminator if needed. Thats unlike std::string::data() which does not add a '\0'. Well on the other side std::string::c_str() is const. This all leaves me wonder how actually works. And if I ever need to work again if I had a Euro for every call where std::string::data() and std::string::c_str() have been mixed up. > If you need string-to-int conversion and vice-versa, then it's the job > of std::stringstream (std::strstream is obsolete...) - there's a very easy > way to do this: Interesting. I did not know that. Well tomorrow I look if Microsoft does know as well. > /********************************************/ > > #include > using std::string; > > #include > typedef std::ostringstream oss; > typedef std::istringstream iss; > > int i = 4; > string MyString("2"); > > > > //step-by-step: > > void f() { > > //instead of std::string::fromInt(int) > oss MyOutputStream; > MyOutputStream << i; > MyString = MyOutputStream.str(); > > //instead of std::string::toInt() > iss MyInputStream; > MyInputStream.str(MyString); > MyInputStream >> i; > > } //f() Well, nice. But are you shure you don't leak memory here. I remember there was something about ownership and the str() function. > //same things as one-liners: Please DON'T. This is comp.lang.ada after all. Three liners are quite OK. > C++ is not that evil, you just have to switch your mind to a different > way of thinking to understand it well... ;-) It *is* difficult, but once > you feel it, it gives you a lot of abilities. Please don't understand me > wrong - I don't claim I'm some kind of C++ guru, and the following is just > my general opinion, not an answer for your particular post. Why I think > many people think of C++ as so dangerous and letting you easily shoot your > foot is that unfortunately not many people know it as well as they should > to use it properly. Well I use C++ for 15 years now. And now I am here at c.l.a. Don't you think there is a reason for that? I think I never ever get use to the fact that the following one liner is not an error - and usually only reported at highest warning level. static unsigned Wrong = -1; Not only that you can shoot yourself in the foot with C++ (You can do that with Ada as well) but the weapon is allways loaded (that is, cannot be unloaded), has no safety lever, and the trigger is allwas taut. And of corse it is a snipers hair trigger going off at the slightest touch. So no matter how experienced you are, you are allways in danger of shooting your food of. With Regards Martin -- mailto://krischik@users.sourceforge.net http://www.ada.krischik.com