1. Trang chủ
  2. » Công Nghệ Thông Tin

A tour of c++ (2nd edition) (c++ in depth series)

255 15 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Nội dung

A tour of c++ (2nd edition) (c++ in depth series) In A Tour of C++, Second Edition, Bjarne Stroustrup, the creator of C++, describes what constitutes modern C++. This concise, selfcontained guide covers most major language features and the major standardlibrary components―not, of course, in great depth, but to a level that gives programmers a meaningful overview of the language, some key examples, and practical help in getting started. Stroustrup presents the C++ features in the context of the programming styles they support, such as objectoriented and generic programming. His tour is remarkably comprehensive. Coverage begins with the basics, then ranges widely through more advanced topics, including many that are new in C++17, such as move semantics, uniform initialization, lambda expressions, improved containers, random numbers, and concurrency. The tour even covers some extensions being made for C++20, such as concepts and modules, and ends with a discussion of the design and evolution of C++. This guide does not aim to teach you how to program (for that, see Stroustrup’s Programming: Principles and Practice Using C++, Second Edition), nor will it be the only resource you’ll need for C++ mastery (for that, see Stroustrup’s The C++ Programming Language, Fourth Edition, and recommended online sources). If, however, you are a C or C++ programmer wanting greater familiarity with the current C++ language, or a programmer versed in another language wishing to gain an accurate picture of the nature and benefits of modern C++, you can’t find a shorter or simpler introduction than this tour provides.

A Tour of C++ Second Edition C++ In-Depth Series Bjarne Stroustrup, Series Editor Visit informit.com/series/indepth for a complete list of available publications T he C++ In-Depth Series is a collection of concise and focused books that provide real-world programmers with reliable information about the C++ programming language Selected by the designer and original implementor of C++, Bjarne Stroustrup, and written by carefully chosen experts in the field, each book in this series presents either a single topic, at a technical level appropriate to that topic, or a fast-paced overview, for a quick understanding of broader language features In either case, the series’ practical approach is designed to lift professionals (and aspiring professionals) to the next level of programming skill or knowledge Make sure to connect with us! informit.com/socialconnect A Tour of C++ Second Edition Bjarne Stroustrup Boston • Columbus • New York • San Francisco • Amsterdam • Cape Town Dubai • London • Madrid • Milan • Munich • Paris • Montreal • Toronto • Delhi • Mexico City São Paulo • Sydney • Hong Kong • Seoul • Singapore • Taipei • Tokyo Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks Where those designations appear in this book, and the publisher was aware of a trademark claim, the designations have been printed with initial capital letters or in all capitals The author and publisher have taken care in the preparation of this book, but make no expressed or implied warranty of any kind and assume no responsibility for errors or omissions No liability is assumed for incidental or consequential damages in connection with or arising out of the use of the information or programs contained herein For information about buying this title in bulk quantities, or for special sales opportunities (which may include electronic versions; custom cover designs; and content particular to your business, training goals, marketing focus, or branding interests), please contact our corporate sales department at corpsales@pearsoned.com or (800) 382-3419 For government sales inquiries, please contact governmentsales@pearsoned.com For questions about sales outside the U.S., please contact intlcs@pearson.com Visit us on the Web: informit.com/aw Library of Congress Control Number: 2018941627 Copyright © 2018 by Pearson Education, Inc All rights reserved This publication is protected by copyright, and permission must be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise For information regarding permissions, request forms and the appropriate contacts within the Pearson Education Global Rights & Permissions Department, please visit www.pearsoned.com/permissions/ This book was typeset in Times and Helvetica by the author ISBN-13: 978-0-13-499783-4 ISBN-10: 0-13-499783-2 Third printing, March 2019 19 Contents Preface xi The Basics 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 1.10 Introduction Programs Functions Types, Variables, and Arithmetic Scope and Lifetime Constants Pointers, Arrays, and References 11 Tests 14 Mapping to Hardware 16 Advice 18 User-Defined Types 2.1 2.2 2.3 2.4 2.5 2.6 Introduction 21 Structures 22 Classes 23 Unions 25 Enumerations 26 Advice 27 21 vi Contents Modularity 3.1 3.2 3.3 3.4 3.5 3.6 3.7 29 Introduction 29 Separate Compilation 30 Modules (C++20) 32 Namespaces 34 Error Handling 35 Function Arguments and Return Values 36 Advice 46 Classes 47 4.1 4.2 4.3 4.4 4.5 4.6 Introduction 47 Concrete Types 48 Abstract Types 54 Virtual Functions 56 Class Hierarchies 57 Advice 63 Essential Operations 5.1 5.2 5.3 5.4 5.5 Introduction 65 Copy and Move 68 Resource Management 72 Conventional Operations 74 Advice 77 Templates 6.1 6.2 6.3 6.4 6.5 79 Introduction 79 Parameterized Types 79 Parameterized Operations 84 Template Mechanisms 89 Advice 92 Concepts and Generic Programming 7.1 7.2 7.3 7.4 7.5 7.6 65 Introduction 93 Concepts 94 Generic Programming 98 Variadic Templates 100 Template Compilation Model 104 Advice 104 93 vii Library Overview 8.1 8.2 8.3 8.4 Introduction 107 Standard-Library Components 108 Standard-Library Headers and Namespace 109 Advice 110 Strings and Regular Expressions 9.1 9.2 9.3 9.4 9.5 111 Introduction 111 Strings 111 String Views 114 Regular Expressions 116 Advice 122 10 Input and Output 10.1 10.2 10.3 10.4 10.5 10.6 10.7 10.8 10.9 10.10 10.11 107 123 Introduction 123 Output 123 Input 125 I/O State 127 I/O of User-Defined Types 128 Formatting 129 File Streams 130 String Streams 130 C-style I/O 131 File System 132 Advice 136 11 Containers 137 11.1 Introduction 137 11.2 vector 138 11.3 list 142 11.4 map 144 11.5 unordered_map 144 11.6 Container Overview 146 11.7 Advice 148 12 Algorithms 12.1 12.2 12.3 149 Introduction 149 Use of Iterators 150 Iterator Types 153 viii Contents 12.4 12.5 12.6 12.7 12.8 12.9 12.10 Stream Iterators 154 Predicates 155 Algorithm Overview 156 Concepts (C++20) 157 Container Algorithms 160 Parallel Algorithms 161 Advice 161 13 Utilities 13.1 13.2 13.3 13.4 13.5 13.6 13.7 13.8 13.9 13.10 163 Introduction 163 Resource Management 164 Range Checking: span 168 Specialized Containers 170 Alternatives 174 Allocators 178 Time 179 Function Adaption 180 Type Functions 181 Advice 185 14 Numerics 14.1 14.2 14.3 14.4 14.5 14.6 14.7 14.8 187 Introduction 187 Mathematical Functions 188 Numerical Algorithms 189 Complex Numbers 190 Random Numbers 191 Vector Arithmetic 192 Numeric Limits 193 Advice 193 15 Concurrency 15.1 Introduction 195 15.2 Tasks and threads 196 15.3 Passing Arguments 197 15.4 Returning Results 198 15.5 Sharing Data 199 15.6 Waiting for Events 200 15.7 Communicating Tasks 202 15.8 Advice 205 195 ix 16 History and Compatibility 207 16.1 History 207 16.2 C++ Feature Evolution 214 16.3 C/C++ Compatibility 218 16.4 Bibliography 222 16.5 Advice 225 Index 227

Ngày đăng: 21/01/2024, 15:35