- Would std::runtime_error benefit from having another constructor? - 4 Updates
- Output Stream Formatting - 7 Updates
- Sample code for 'Effective Modern C++' - 1 Update
- won't compile? - 1 Update
- Output Stream Formatting - 1 Update
- What do you think about my new mock library? - 1 Update
- convert to a time and compaire to see if more than a minute difference found? - 1 Update
woodbrian77@gmail.com: Apr 05 01:24PM -0700 Rather than using std::runtime_error http://www.cplusplus.com/reference/stdexcept/runtime_error/ , I use the following class. Std::runtime_error has just one constructor that takes a std::string. The following class also has a constructor that takes a std::string, and it has a constructor that takes a char const*. If I comment out the char const* constructor, the sizes of the text segments of two of my programs increase. The increases are by 1.7% and 3.6% using Clang 3.4.1. On GCC 4.9.2, the increases are 7.7% and 11.3%. So I think having that additional constructor is important. #include <exception> #include <string> #include <utility> // move class failure : public ::std::exception { ::std::string whatStr; public: explicit failure (char const* w) : whatStr(w) {} explicit failure (::std::string w) : whatStr(::std::move(w)) {} char const* what () const throw() { return whatStr.c_str(); } failure& operator<< (char const* s) { whatStr.append(s); return *this; } failure& operator<< (char* s) { whatStr.append(s); return *this; } failure& operator<< (::std::string const& s) { whatStr.append(s); return *this; } template <class T> failure& operator<< (T val) { using ::std::to_string; return *this << to_string(val); } }; Brian Ebenezer Enterprises - In G-d we trust. http://webEbenezer.net |
Ian Collins <ian-news@hotmail.com>: Apr 06 09:33AM +1200 > increases are by 1.7% and 3.6% using Clang 3.4.1. On GCC > 4.9.2, the increases are 7.7% and 11.3%. So I think having > that additional constructor is important. Relative to what? If your environment allows exceptions, a few bytes here and there are of little consequence. > public: > explicit failure (char const* w) : whatStr(w) {} > explicit failure (::std::string w) : whatStr(::std::move(w)) {} Why don't you just use a move constructor? -- Ian Collins |
"Öö Tiib" <ootiib@hot.ee>: Apr 05 02:40PM -0700 > one constructor that takes a std::string. The following > class also has a constructor that takes a std::string, > and it has a constructor that takes a char const*. To my knowledge that has changed since C++11 and now 'std::runtime_error' has two constructors, one that takes 'std::string const&' and other that takes 'char const*'. > increases are by 1.7% and 3.6% using Clang 3.4.1. On GCC > 4.9.2, the increases are 7.7% and 11.3%. So I think having > that additional constructor is important. It depends on how you use the classes. If you pass mostly string literals then 'char const*' is more fitting parameter. |
Ian Collins <ian-news@hotmail.com>: Apr 06 10:21AM +1200 嘱 Tiib wrote: > To my knowledge that has changed since C++11 and now > 'std::runtime_error' has two constructors, one that > takes 'std::string const&' and other that takes 'char const*'. It has. -- Ian Collins |
Vir Campestris <vir.campestris@invalid.invalid>: Apr 05 12:42PM +0100 On 04/04/2015 09:54, Bo Persson wrote: > On the other hand, printf fails totally and miserably for user defined > types. I tend to take a leaf out of Java's book and define a tostring method. Leaving the caMel hUmPs in random places to confuse the innocent & match local coding standards of course ;) Andy |
Melzzzzz <mel@zzzzz.com>: Apr 05 01:49PM +0200 On Sun, 05 Apr 2015 12:42:45 +0100 > method. Leaving the caMel hUmPs in random places to confuse the > innocent & match local coding standards of course ;) > Andy to_string is not bad approach ;) |
"Lőrinczy Zsigmond" <nospam@for.me>: Apr 05 02:51PM +0200 sprintf is your friend |
"Öö Tiib" <ootiib@hot.ee>: Apr 05 06:00AM -0700 On Sunday, 5 April 2015 14:49:21 UTC+3, Melzzzzz wrote: > > innocent & match local coding standards of course ;) > > Andy > to_string is not bad approach ;) It is generally good approach to use the interface of function (or "algorithm" or "utility") in std namespace when the behavior matches. Saves some time of other guy who tries to write some generic handling and has to otherwise write wrappers in style: inline std::string to_string( Foo const& foo ) { return foo.ConvertToStdString(); } |
"Öö Tiib" <ootiib@hot.ee>: Apr 05 06:18AM -0700 On Sunday, 5 April 2015 15:51:42 UTC+3, Lőrinczy Zsigmond wrote: > sprintf is your friend That leads to: A: No, 'sprintf' is security hole. 'snprintf' is safer. B: But Windows/Ms does not have 'snprintf'. A: Yes, but Windows/Ms has '_snprintf'. C: Hey, '_snprintf' is broken/not compatible with 'snprintf'. D: Why don't you guys use 'std::snprintf'? So ... to keep things short ... 'std::snprintf' is your friend. ;-) |
Luca Risolia <luca.risolia@linux-projects.org>: Apr 05 05:18PM +0200 Il 04/04/2015 00:22, MikeCopeland ha scritto: > How do I accomplish this: > printf(myStr, "%6.1f", shirtCounts[ii]*100.0/totalShirts); > with streams? Write a simple user-defined manipulator as a combination of std::fixed, std::setw and std::setprecision and use it wherever you need. |
"Öö Tiib" <ootiib@hot.ee>: Apr 05 02:04PM -0700 On Sunday, 5 April 2015 19:31:23 UTC+3, Stefan Ram wrote: > (There should be some example code on: > http://www.purl.org/stefan_ram/pub/c_faq_de > see "salfmt", in case of 403 try to use a Google referrer.) The 'va_list's are made to process the ellipsis '...' argument of C. Ellipsis argument is too loose for my taste to use at all. Lot of coding standards agree with me. It is better to use overloads, templates or variadic templates in C++ since those are lot more type safe. > >B: But Windows/Ms does not have 'snprintf'. > According to 27.9.2, C++ has snprintf. When someone is using > a language without snprintf, this language is off topic here. Is it? C++ has 'std::snprintf'. It wasn't standardized before C++11. Is discussing older standards off topic here? C++ is evolving faster than its compilers still in use so on such case we haven't much to discuss left but sausages. > >C: Hey, '_snprintf' is broken/not compatible with 'snprintf'. > They should try -D__USE_MINGW_ANSI_STDIO when using a kind > of MINGW. Lot of people can not use mingw or cygwin. They have to use msvc or icc because these make better-performing binaries for their case or have tools they need or support compatibility with other software they need. |
Bart Vandewoestyne <bart.vandewoestyne@gmail.com>: Apr 05 01:42PM -0700 Hello group, I was one of the reviewers for Scott Meyers his 'Effective Modern C++' book. During the review process, I have created lots of sample code for the material from the book. I am currently revising that sample code and uploading it to my GitHub repository https://github.com/BartVandewoestyne/Effective-Modern-Cpp I have 27 out of the 42 items online already, and hope to add the remaining 15 soon. Feel free to contribute by sending me pull requests! Comments and suggestions are also highly appreciated! I hope that this online code will help the EMC++ readers to get a hands-on feeling for the principles explained in the book. Feel free to play with this code as much as you like and spread the message! Kind regards, Bart |
SpreadTooThin <bjobrien62@gmail.com>: Apr 05 11:43AM -0700 On Friday, April 3, 2015 at 12:22:04 AM UTC-6, Ian Collins wrote: > } > -- > Ian Collins Thanks. I did not know that! :) |
ram@zedat.fu-berlin.de (Stefan Ram): Apr 05 04:31PM >A: No, 'sprintf' is security hole. 'snprintf' is safer. I use vsnprintf to obtain the size of the buffer, then allocate the buffer, and, finally, vsprintf to print to the buffer, when the size of the buffer needed is not statically known. (There should be some example code on: http://www.purl.org/stefan_ram/pub/c_faq_de see "salfmt", in case of 403 try to use a Google referrer.) >B: But Windows/Ms does not have 'snprintf'. According to 27.9.2, C++ has snprintf. When someone is using a language without snprintf, this language is off topic here. >C: Hey, '_snprintf' is broken/not compatible with 'snprintf'. They should try -D__USE_MINGW_ANSI_STDIO when using a kind of MINGW. |
DeMarcus <demarcus_at_hotmail_com@tellus.orb>: Apr 05 01:11PM +0200 >> A Hello World example is found in the wiki. >> https://github.com/unimock-cpp/unimock/wiki > I can't figure out what to do with it.... I added a step-by-step example showing how to use the mock in Unimock. Hope this clarifies its interface a bit. https://github.com/unimock-cpp/unimock/blob/master/examples/ChefRobot/Main.cc Br, Daniel |
Ian Collins <ian-news@hotmail.com>: Apr 05 12:24PM +1200 SpreadTooThin wrote: > int millisecond; > std::time_t t1; > }; How is that better than the suggestions offered? How do you calculate time differences? -- Ian Collins |
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page. To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com. |
No comments:
Post a Comment