The C++ Standard Library, 2nd Edition PDF.The C++ Standard Library, 2nd Edition PDF.This page intentionally left blankwww.allitebooks.comThe c++ Standard libraryA Tutorial and referenceSecond editionNicolai m. josuttisAAddison-WesleyUpper Saddle river,NJ· Boston· Indianapolis· San franciscoNew York Toronto montreal● London● Munich● Paris· MadridCapetown· Sydney Tokyo· Singapore· Mexico Citywww.allitebooks.comMany of the designations used by manufacturers and sellers to distinguish their products are claimedas trademarks. Where those designations appear in this book, and the publisher was aware of atrademark claim, the designations have been printed with initial capital letters or in all capitalsThe author and publisher have taken care in the preparation of this book but make no expressed orimplied warranty of any kind and assume no responsibility for errors or omissions. No liability isassumed for incidental or consequential damages in connection with or arising out of the use of theinformation or programs contained hereinThe publisher offers excellent discounts on this book when ordered in quantity for bulk purchases orspecial sales, which may include electronic versions and/or custom covers and content particular toyour business, training goals, marketing focus, and branding interests. For more information, pleasecontact:U.S. Corporate and government sales(800)382-3419corpsales@pearsontechgroup.comFor sales outside the united States, please contactInternational salesinternational@pearson.comVisit us on the web informit. com/awLibrary of Congress Cataloging-in-Publication dataJosuttis. Nicolai mThe C++ standard library: a tutorial and reference/Nicolai M. Josuttis.---2nd edcmIncludes bibliographical references and indexisbn 978-0-321-62321-8(hardcover: alk. paper)1. C++( Computer program language)I. TitleQA76.73C153J692012005.133-dc232011045071Copyright 2012 Pearson Education, IncThis book was typeset by the author using the ltex document processing systemAll rights reserved. Printed in the United States of America. This publication is protected by copy-right, and permission must be obtained from the publisher prior to any prohibited reproductionstorage in a retrieval system, or transmission in any form or by any means, electronic, mechanicalphotocopying, recording, or likewise. To obtain permission to use material from this work, pleasesubmit a written request to Pearson Education, Inc, Permissions Department, One Lake Street,Upper Saddle river, New Jersey 07458, or you may fax your request to(201)236-3290ISBN-13:978-0-321-62321-8ISBN-100-321-62321-5Text printed in the United States on recycled paper at Edwards Brothers in Ann Arbor, MichiganFirst printing, March 2012www.allitebooks.comTo those who carefor people and mankindwww.allitebooks.comThis page intentionally left blankwww.allitebooks.comContentsPreface to the second editionAcknowledgments for the second EditionPreface to the first editionXXVAcknowledgments for the first editionXXVI1 About This book1. 1 Why This book1.2 Before Reading This Book1.3 Style and Structure of the Book1. 4 How to read This book1. 5 State of the art1.6 Example Code and Additional Information1.7 Feedback2 Introduction to C++ and the Standard library2.1 History of the C++ Standards2455577892.1.1 Common Questions about the c++11 Standard2.1.2 Compatibility between C++98 and C++112.2 Complexity and big-O notation103 New Language Features133.1 New C++l1 Language Features133.1.1 Important minor Syntax cleanups133.1.2 Automatic Type Deduction with auto143.1.3 Uniform Initialization and Initializer lists153.1.4 Range-Based for Loops173.1.5 Move Semantics and Rvalue references19www.allitebooks.comContents3.1.6 New String literals233.1.7 Keyword noexcept243. 1. 8 Keyword constexpr263. 1.9 New Template Features263.1.10 Lambdas283.1.11 Keyword decltype3.1.12 New Function Declaration Syntax3.1.13 Scoped Enumerations323. 1. 14 New Fundamental Data Types333.2 Old"New?" Language features333.2.1 Explicit Initialization for Fundamental Types373.2.2 Definition of main o374 General Concept4.1 Namespace std394.2 Header files404.3 Error and Exception Handling414.3.1 Standard Exception Classes414.3.2 Members of Exception Classes444.3.3 Passing Exceptions with Class exception_ptr524.3.4 Throwing Standard Exceptions534.3.5 Deriving from Standard Exception Classes544.4 Callable objects4.5 Concurrency and Multithreading554.6 Allocators575 Utilities5.1 Pairs and tuples5.1.1 Pairs...5.1.2 Tuples5.1.3 I/O for Tuples745.1.4 Conversions between tuples and pairs755.2 Smart Pointers765.2.1 Class shared_ptr765.2.2 Class weak_ptr845.2. 3 Misusing Shared Pointers895. 2. 4 Shared and Weak pointers in Detail25.2.5 Class unique_ptr98www.allitebooks.comContents5.2.6 Class unique ptr in detail.1105.2.7 Class auto_ptr1135.2. 8 Final words on smart pointers1145.3 Numeric Limits1155. 4 Type Traits and Type Utilities1225.4.1 Purpose of Type Traits12254.2Tyype Traits in Detail1255.4.3 Reference Wrappers1325.4.4 Function Type Wrappers1335.5 Auxiliary Functions1345.5.1 Processing the minimum and maximum1345.5.2 Swapping two values1365.5.3 Supplementary comparison operators1385.6 Compile-Time Fractional Arithmetic with Class ratio<>.1405.7 Clocks and Timers..1435.7.1 Overview of the Chrono library1435.7.2 Durations1445.7.3 Clocks and Timepoints1495.7.4 Date and Time Functions by C and POsIX1575.7.5 Blocking with Timers1605.8 Header Files , , and 16l5.8.1 Definitions in 1615.8.2 Definitions in 1625.8.3 Definitions in 1636 The Standard Template Library1656. 1 STL Components1656.2 Containers1676.2.1 Sequence Containers1696.2.2 Associative Containers1776.2.3 Unordered Containers1806.2.4 Associative arrays.1856.2.5 Other Containers.1876.2.6 Container Adapters1886.3 Iterators1886.3.1 Further Examples of Using Associative and Unordered Containers1936.3.2 Iterator Categories..198www.allitebooks.com