• Complain

Herb Sutter - Exceptional C++:47 Engineering Puzzles, Programming Problems and Solutions

Here you can read online Herb Sutter - Exceptional C++:47 Engineering Puzzles, Programming Problems and Solutions full text of the book (entire story) in english for free. Download pdf and epub, get meaning, cover and reviews about this ebook. year: 0, genre: Computer. Description of the work, (preface) as well as reviews are available. Best literature library LitArk.com created for fans of good reading and offers a wide selection of genres:

Romance novel Science fiction Adventure Detective Science History Home and family Prose Art Politics Computer Non-fiction Religion Business Children Humor

Choose a favorite category and find really read worthwhile books. Enjoy immersion in the world of imagination, feel the emotions of the characters or learn something new for yourself, make an fascinating discovery.

No cover
  • Book:
    Exceptional C++:47 Engineering Puzzles, Programming Problems and Solutions
  • Author:
  • Genre:
  • Year:
    0
  • Rating:
    4 / 5
  • Favourites:
    Add to favourites
  • Your mark:
    • 80
    • 1
    • 2
    • 3
    • 4
    • 5

Exceptional C++:47 Engineering Puzzles, Programming Problems and Solutions: summary, description and annotation

We offer to read an annotation, description, summary or preface (depends on what the author of the book "Exceptional C++:47 Engineering Puzzles, Programming Problems and Solutions" wrote himself). If you haven't found the necessary information about the book — write in the comments, we will try to find it.

Herb Sutter: author's other books


Who wrote Exceptional C++:47 Engineering Puzzles, Programming Problems and Solutions? Find out the surname, the name of the author of the book and a list of all author's works by series.

Exceptional C++:47 Engineering Puzzles, Programming Problems and Solutions — read online for free the complete book (whole text) full work

Below is the text of the book, divided by pages. System saving the place of the last page read, allows you to conveniently read the book "Exceptional C++:47 Engineering Puzzles, Programming Problems and Solutions" online for free, without having to search again every time where you left off. Put a bookmark, and you can go to the page where you finished reading at any time.

Light

Font size:

Reset

Interval:

Bookmark:

Make
Afterword

If you've enjoyed the puzzles and problems in this book, then I have good news for you. This is not the end, for Guru of the Week #30 was not the last GotW, nor have I stopped writing articles in various programming magazines.

Today, on the Internet, new GotW issues are being published and discussed and debated regularly on the newsgroup comp.lang.c++.moderated, and are archived at the official GotW Website at www.gotw.ca. As I write this, in June 1999, we're already up to #55. To give you a taste for what's coming, a small sampling of the new GotW issues includes fresh material on such topics as the following:

  • More information on popular themes, including the safe use of auto_ptr , namespaces, and exception-safety issues and techniques, taking the next step beyond Items 8 through 17, 31 through 34, and 37.

  • A three-part series on reference-counting and copy-on-write techniques, including unusual performance implications in multithreaded (or multithread-capable) environments, with extensive test harness code and statistical measurements. There's material here that you usually don't see discussed anywhere else.

  • Many puzzles about the safe and effective use of standard library, especially containers (like vector and map ) and the standard streams. This includes more information about how to best extend the standard library, in the spirit of Items 2 and 3.

  • A nifty game: writing a MasterMind-playing program in as few statements as possible.

And that's just a small sample. If there is enough interest in the book you're holding in your hands now, my intention is to produce another volume containing expanded and reorganized forms of the next batch of issues, again including the text of the other C++ engineering articles and columns that I'm writing for C/C++ Users Journal , and other magazines.

I hope you've enjoyed the book, and that you'll continue to let me know what interesting topics you'd like to see covered in the future; see the Website mentioned earlier for how to submit requests. Some topics you've read about herein were prompted by e-mails like these.

Thanks again to all who have expressed interest and support for GotW and this book. I hope you've found this material to be useful in your daily work, as you keep on writing faster, cleaner, and safer C++ programs.

Bibliography

Barton94: John Barton and Lee Nackman, Scientific and Engineering C++ . Addison-Wesley, 1994.

Cargill92: Tom Cargill, C++ Programming Style . Addison-Wesley, 1992.

Cargill94: Tom Cargill, "Exception Handling: A False Sense of Security." C++ Report , 9(6), Nov.Dec. 1994.

Cline95: Marshall Cline and Greg Lomow, C++ FAQs. Addison-Wesley, 1995.

Cline99: Marshall Cline, Greg Lomow, and Mike Girou, C++ FAQs, Second Edition . Addison Wesley Longman, 1999.

Coplien92: James Coplien. Advanced C++ Programming Styles and Idioms . Addison-Wesley, 1992.

Ellis90: Margaret Ellis and Bjarne Stroustrup, The Annotated C++ Reference Manual . Addison-Wesley, 1990.

Gamma95: Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides, Design Patterns: Elements of Reusable Object-Oriented Software . Addison-Wesley, 1995.

Keffer95: Thomas Keffer, Rogue Wave C++ Design, Implementation, and Style Guide . Rogue Wave Software, 1995.

Koenig97: Andrew Koenig and Barbara Moo, Ruminations on C++ . Addison Wesley Longman, 1997.

Lakos96: John Lakos, Large-Scale C++ Software Design . Addison-Wesley, 1996.

Lippman97: Stan Lippman (ed.), C++ Gems . SIGS / Cambridge University Press, 1997.

Lippman98: Stan Lippman and Jose Lajoie, C++ Primer, Third Edition . Addison Wesley Longman, 1998.

Martin95: Robert C. Martin, Designing Object-Oriented Applications Using the Booch Method . Prentice-Hall, 1995.

Martin00: Robert C. Martin (ed.), C++ Gems II . SIGS / Cambridge University Press, 2000.

Meyers96: Scott Meyers, More Effective C++ . Addison-Wesley, 1996.

Meyers98: Scott Meyers, Effective C++, Second Edition . Addison Wesley Longman, 1998.

Meyers99: Scott Meyers, Effective C++ CD . Addison Wesley Longman, 1999. (See also http://www.gotw.ca/publications/xc++/sm_effective.htm) Murray93: Robert Murray, C++ Strategies and Tactics . Addison-Wesley, 1993.

Myers97: Nathan Myers, "The Empty Base C++ Optimization." Dr. Dobb's Journal , Aug. 1997.

Stroustrup94: Bjarne Stroustrup, The Design and Evolution of C++ . Addison-Wesley, 1994.

Stroustrup97: Bjarne Stroustrup, The C++ Progamming Language, Third Edition . Addison Wesley Longman, 1997.

Sutter98: Herb Sutter, "C++ State of the Union." C++ Report , 10(1), Jan. 1998.

Sutter98(a): Herb Sutter, "Uses and Abuses of Inheritance, Part 1." C++ Report , 10(9), Oct. 1998.

Sutter99: Herb Sutter, "Uses and Abuses of Inheritance, Part 2." C++ Report , 11(1), Jan. 1999.

int main()

{

vector e; copy( istream_iterator( cin ), istream_iterator(), back_inserter( e ) ); vector::iterator first =

find( e.begin(), e.end(), "01/01/95" ); vector::iterator last =

find( e.begin(), e.end(), "12/31/95" ); *last = "12/30/95"; copy( first, last,

ostream_iterator( cout, "\n" ) ); e.insert( --e.end(), TodaysDate() ); copy( first, last,

ostream_iterator( cout, "\n" ) ); }

Solution
Picture 1 int main() { vector e; copy( istream_iterator( cin ), istream_iterator(), back_inserter( e ) );

This is fine so far. The Date class writer provided an extractor function with the signature operator>>( istream&, Date& ) , which is what istream_iterator uses to read the Date s from the cin stream. The copy() algorithm just stuffs the Dates into the vector.

vector::iterator first = find( e.begin(), e.end(), " 01/01/95 " ); vector::iterator last = find( e.begin(), e.end(), " 12/31/95 " ); *last = "12/30/95";

Error: This may be illegal, because last may be e.end() and therefore not a dereferenceable iterator.

The find() algorithm returns its second argument (the end iterator of the range) if the value is not found. In this case, if "12/31/95" is not in e , then last is equal to e.end() , which points to one-past-the-end of the container and is not a valid iterator.

copy( first, last, ostream_iterator( cout, " \n " ) );

Error: This may be illegal because [first,last) may not be a valid range; indeed, first may actually be after last .

For example, if "01/01/95" is not found in e but "12/31/95" is, then the iterator last will point to something earlier in the collection (the Date object equal to "12/31/95") than does the iterator first (one past the end). However, copy() requires that first must point to an earlier place in the same collection as last that is, [ first , last ) must be a valid range.

Unless you're using a checked version of the standard library that can detect some of these problems for you, the likely symptom if this happens will be a difficult-to-diagnose core dump during or sometime after the copy() .

e.insert( --e.end() , TodaysDate() );

First error: The expression " --e.end() " is likely to be illegal.

The reason is simple, if a little obscure: On popular implementations of the standard library, vector::iterator is often simply a Date* , and the C++ language doesn't allow you to modify temporaries of builtin type. For example, the following plain-jane code is also illegal: Date* f(); // function that returns a Date* p = --f(); // error, but could be "f() - 1"

Fortunately, we know that vector::iterator is a random-access iterator, so there's no loss of efficiency in writing this (more) correctly as: e.insert( e.end() - 1, TodaysDate() );

Second error: Now you still have the other error, which is: If e is empty, any attempt to take "the iterator before e.end() " (whether you spell that " --e.end() " or " e.end()1 ") will not be a valid iterator.

Next page
Light

Font size:

Reset

Interval:

Bookmark:

Make

Similar books «Exceptional C++:47 Engineering Puzzles, Programming Problems and Solutions»

Look at similar books to Exceptional C++:47 Engineering Puzzles, Programming Problems and Solutions. We have selected literature similar in name and meaning in the hope of providing readers with more options to find new, interesting, not yet read works.


Reviews about «Exceptional C++:47 Engineering Puzzles, Programming Problems and Solutions»

Discussion, reviews of the book Exceptional C++:47 Engineering Puzzles, Programming Problems and Solutions and just readers' own opinions. Leave your comments, write what you think about the work, its meaning or the main characters. Specify what exactly you liked and what you didn't like, and why you think so.