Rogue Wave Standard C++ Library User's Guide and Reference
Total Page:16
File Type:pdf, Size:1020Kb
Rogue Wave Standard C++ Library User's Guide and Reference Rogue Wave Software Corvallis, Oregon USA Standard C++ Library User's Guide and Reference for Rogue Wave's implementation of the Standard C++ Library. Based on ANSI's Working Paper for Draft Proposed International Standard for Information Systems--Programming Language C++. April 28, 1995. User's Guide Authors: Timothy A. Budd, Randy Smithey Reference Authors: Wendi Minne, Tom Pearson, and Randy Smithey Product Team: Development: Anna Dahan, Donald Fowler, Marlene Hart, Angelika Langer, Philippe Le Mouel, Randy Smithey Quality Engineering: KevinDjang, Randall Robinson, Chun Zhang Manuals: Wendi Minne, Kristi Moore, Julie Prince,Randy Smithey Support: North Krimsley Significant contributions by: Rodney Mishima Copyright © 1995-96 Rogue Wave Software, Inc. All rights reserved. Printed in the United States of America. Part # RW81-01-2-032596 Printing Date: July 1996 Rogue Wave Software, Inc., 850 SW 35th Street, Corvallis, Oregon, 97333 USA Product Information: (541) 754-5010 (800) 487-3217 Technical Support: (541) 754-2311 FAX: (541) 757-6650 World Wide Web: http://www.roguewave.com Please have your product serial number available when calling for technical support. Table of Contents 1. Introduction .........................................................................1 1.1 What is the Standard C++ Library?............................................................. 2 1.2 Does the Standard C++ Library Differ From Other Libraries? ............... 2 1.3 What are the Effects of Non-Object-Oriented Design?............................. 3 1.4 How Should I Use the Standard C++ Library?.......................................... 5 1.5 Reading This Manual .................................................................................... 6 1.6 Conventions.................................................................................................... 6 1.7 Using the Standard Library.......................................................................... 7 1.8 Running the Tutorial Programs................................................................... 7 2. Iterators ................................................................................9 2.1 Introduction to Iterators.............................................................................. 10 2.2 Varieties of Iterators .................................................................................... 11 2.2.1 Input Iterators........................................................................................ 12 2.2.2 Output Iterators .................................................................................... 13 2.2.3 Forward Iterators .................................................................................. 14 2.2.4 Bidirectional Iterators........................................................................... 15 2.2.5 Random Access Iterators ..................................................................... 15 2.2.6 Reverse Iterators ................................................................................... 16 2.3 Stream Iterators............................................................................................ 17 2.3.1 Input Stream Iterators .......................................................................... 17 2.3.2 Output Stream Iterators ....................................................................... 18 2.4 Insert Iterators .............................................................................................. 18 2.5 Iterator Operations ...................................................................................... 20 3. Functions and Predicates.................................................21 3.1 Functions....................................................................................................... 22 3.2 Predicates...................................................................................................... 22 3.3 Function Objects........................................................................................... 23 3.4 Negators and Binders.................................................................................. 26 4. Container Classes.............................................................29 4.1 Overview....................................................................................................... 30 4.2 Selecting a Container................................................................................... 30 4.3 Memory Management Issues ..................................................................... 32 4.4 Container Types Not Found in the Standard Library ............................ 33 5. vector and vector<bool>.................................................35 5.1 The vector Data Abstraction....................................................................... 36 5.1.1 Include Files........................................................................................... 36 5.2 Vector Operations........................................................................................ 36 5.2.1 Declaration and Initialization of Vectors........................................... 37 5.2.2 Type Definitions.................................................................................... 38 5.2.3 Subscripting a Vector ........................................................................... 39 5.2.4 Extent and Size-Changing Operations............................................... 39 5.2.5 Inserting and Removing Elements ..................................................... 40 5.2.6 Iteration .................................................................................................. 42 5.2.7 Test for Inclusion .................................................................................. 42 5.2.8 Sorting and Sorted Vector Operations............................................... 42 5.2.9 Useful Generic Algorithms.................................................................. 43 5.3 Boolean Vectors............................................................................................ 44 5.4 Example Program − Sieve of Eratosthenes............................................... 45 6. list........................................................................................47 6.1 The list Data Abstraction ............................................................................ 48 6.1.1 Include files............................................................................................ 48 6.2 List Operations............................................................................................. 48 6.2.1 Declaration and Initialization of Lists................................................ 49 6.2.2 Type Definitions.................................................................................... 50 6.2.3 Placing Elements into a List ................................................................ 51 6.2.4 Removing Elements.............................................................................. 53 6.2.5 Extent and Size-Changing Operations............................................... 54 6.2.6 Access and Iteration ............................................................................. 54 6.2.7 Test for Inclusion .................................................................................. 55 6.2.8 Sorting and Sorted List Operations.................................................... 55 6.2.9 Searching Operations ........................................................................... 55 6.2.10 In Place Transformations ................................................................... 56 6.2.11 Other Operations ................................................................................ 56 6.3 Example Program − An Inventory System............................................... 57 7. deque.................................................................................59 7.1 The deque Data Abstraction....................................................................... 60 7.1.1 Include Files........................................................................................... 60 7.2 Deque Operations........................................................................................ 60 7.3 Example Program − Radix Sort.................................................................. 61 iv 8. set, multiset, and bitset......................................................65 8.1 The set Data Abstraction............................................................................. 66 8.1.1 Include Files........................................................................................... 66 8.2 set and multiset Operations ....................................................................... 66 8.2.1 Declaration and Initialization of Set................................................... 66 8.2.2 Type Definitions.................................................................................... 67 8.2.3 Insertion ................................................................................................. 68 8.2.4 Removal of Elements from a Set......................................................... 69 8.2.5 Searching and Counting ...................................................................... 69 8.2.6 Iterators .................................................................................................. 70 8.2.7 Set Operations ......................................................................................