100% found this document useful (2 votes)
88 views

Download ebooks file C++17 Standard Library Quick Reference, 2nd Edition: A Pocket Guide to Data Structures, Algorithms, and Functions Peter Van Weert all chapters

Data

Uploaded by

bogazkochs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (2 votes)
88 views

Download ebooks file C++17 Standard Library Quick Reference, 2nd Edition: A Pocket Guide to Data Structures, Algorithms, and Functions Peter Van Weert all chapters

Data

Uploaded by

bogazkochs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 40

Get ebook downloads in full at ebookmeta.

com

C++17 Standard Library Quick Reference, 2nd


Edition: A Pocket Guide to Data Structures,
Algorithms, and Functions Peter Van Weert

https://ebookmeta.com/product/c17-standard-library-quick-
reference-2nd-edition-a-pocket-guide-to-data-structures-
algorithms-and-functions-peter-van-weert/

OR CLICK BUTTON

DOWNLOAD NOW

Explore and download more ebook at https://ebookmeta.com


Recommended digital products (PDF, EPUB, MOBI) that
you can download immediately if you are interested.

C# 10 Quick Syntax Reference: A Pocket Guide to the


Language, APIs, and Library Mikael Olsson

https://ebookmeta.com/product/c-10-quick-syntax-reference-a-pocket-
guide-to-the-language-apis-and-library-mikael-olsson/

ebookmeta.com

C# 8 Quick Syntax Reference, 3rd Edition: A Pocket Guide


to the Language, APIs, and Library Mikael Olsson

https://ebookmeta.com/product/c-8-quick-syntax-reference-3rd-edition-
a-pocket-guide-to-the-language-apis-and-library-mikael-olsson/

ebookmeta.com

R Quick Syntax Reference, 2nd Edition: A Pocket Guide to


the Language, APIs and Library Margot Tollefson

https://ebookmeta.com/product/r-quick-syntax-reference-2nd-edition-a-
pocket-guide-to-the-language-apis-and-library-margot-tollefson/

ebookmeta.com

The Toxicology of Essential and Nonessential Metals 1st


Edition Nichole Coleman

https://ebookmeta.com/product/the-toxicology-of-essential-and-
nonessential-metals-1st-edition-nichole-coleman/

ebookmeta.com
Client consultant model services agreement 5th Edition
International Federation Of Consulting Engineers.

https://ebookmeta.com/product/client-consultant-model-services-
agreement-5th-edition-international-federation-of-consulting-
engineers/
ebookmeta.com

The Story of the Western Wing Shi-Fu Wang

https://ebookmeta.com/product/the-story-of-the-western-wing-shi-fu-
wang/

ebookmeta.com

Falling from Grace Downward Mobility in the Age of


Affluence Katherine S. Newman

https://ebookmeta.com/product/falling-from-grace-downward-mobility-in-
the-age-of-affluence-katherine-s-newman/

ebookmeta.com

Turnover Vegas Aces The Quarterback Book 4 1st Edition


Lisa Suzanne

https://ebookmeta.com/product/turnover-vegas-aces-the-quarterback-
book-4-1st-edition-lisa-suzanne/

ebookmeta.com

Pragmatics A Resource Book for Students 4th Edition Joan


Cutting Kenneth Fordyce

https://ebookmeta.com/product/pragmatics-a-resource-book-for-
students-4th-edition-joan-cutting-kenneth-fordyce/

ebookmeta.com
The Anti-Oligarchy Constitution : Reconstructing the
Economic Foundations of American Democracy 1st Edition
Joseph Fishkin
https://ebookmeta.com/product/the-anti-oligarchy-constitution-
reconstructing-the-economic-foundations-of-american-democracy-1st-
edition-joseph-fishkin/
ebookmeta.com
C++17 Standard
Library Quick
Reference
A Pocket Guide to Data Structures,
Algorithms, and Functions

Second Edition

Peter Van Weert
Marc Gregoire

www.allitebooks.com
C++17 Standard
Library Quick
Reference
A Pocket Guide to Data Structures,
Algorithms, and Functions

Second Edition

Peter Van Weert


Marc Gregoire

www.allitebooks.com
C++17 Standard Library Quick Reference: A Pocket Guide to Data
Structures, Algorithms, and Functions
Peter Van Weert Marc Gregoire
Kessel-Lo, Belgium Meldert, Belgium
ISBN-13 (pbk): 978-1-4842-4922-2 ISBN-13 (electronic): 978-1-4842-4923-9
https://doi.org/10.1007/978-1-4842-4923-9

Copyright © 2019 by Peter Van Weert and Marc Gregoire


This work is subject to copyright. All rights are reserved by the Publisher, whether the whole
or part of the material is concerned, specifically the rights of translation, reprinting, reuse of
illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical
way, and transmission or information storage and retrieval, electronic adaptation, computer
software, or by similar or dissimilar methodology now known or hereafter developed.
Trademarked names, logos, and images may appear in this book. Rather than use a trademark
symbol with every occurrence of a trademarked name, logo, or image we use the names, logos,
and images only in an editorial fashion and to the benefit of the trademark owner, with no inten-
tion of infringement of the trademark.
The use in this publication of trade names, trademarks, service marks, and similar terms, even if
they are not identified as such, is not to be taken as an expression of opinion as to whether or not
they are subject to proprietary rights.
While the advice and information in this book are believed to be true and accurate at the date of
publication, neither the authors nor the editors nor the publisher can accept any legal responsibil-
ity for any errors or omissions that may be made. The publisher makes no warranty, express or
implied, with respect to the material contained herein.
Managing Director, Apress Media LLC: Welmoed Spahr
Acquisitions Editor: Steve Anglin
Development Editor: Matthew Moodie
Coordinating Editor: Mark Powers
Cover designed by eStudioCalamar
Cover image designed by Freepik (www.freepik.com)
Distributed to the book trade worldwide by Springer Science+Business Media New York,
233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505,
e-mail orders-ny@springer-sbm.com, or visit www.springeronline.com. Apress Media, LLC is
a California LLC and the sole member (owner) is Springer Science + Business Media Finance Inc
(SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation.
For information on translations, please e-mail editorial@apress.com; for reprint, paperback, or
audio rights, please email bookpermissions@springernature.com.
Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook ver-
sions and licenses are also available for most titles. For more information, reference our Print and
eBook Bulk Sales web page at http://www.apress.com/bulk-sales.
Any source code or other supplementary material referenced by the author in this book is available
to readers on GitHub via the book's product page, located at www.apress.com/9781484249222.
For more detailed information, please visit http://www.apress.com/source-code.
Printed on acid-free paper

www.allitebooks.com
Dedicated to my parents and my brother,
who are always there for me.
Their support and patience helped me
in finishing this book.
—Marc Gregoire

In loving memory of Jeroen.


Your enthusiasm and courage will forever remain
an inspiration to us all.
—Peter Van Weert

www.allitebooks.com
Contents

About the Authors���������������������������������������������������������������������������� xv


About the Technical Reviewer������������������������������������������������������� xvii
Introduction������������������������������������������������������������������������������������ xix

■■  Chapter 1: Numerics and Math������������������������������������������������������ 1


Common Mathematical Functions��������������������������������������������� <cmath> 1
Basic Functions�������������������������������������������������������������������������������������������������������� 1
Exponential and Logarithmic Functions������������������������������������������������������������������� 2
Power Functions������������������������������������������������������������������������������������������������������� 2
Trigonometric and Hyperbolic Functions������������������������������������������������������������������ 3
Integral Rounding of Floating-Point Numbers���������������������������������������������������������� 3
Floating-Point Manipulation Functions��������������������������������������������������������������������� 3
Classification and Comparison Functions����������������������������������������������������������������� 4
gcd/lcm C++17 ������������������������������������������������������������������������������������� <numeric> 4
Error Handling����������������������������������������������������������������������������������������������������������� 5

Special Mathematical Functions C++17 ������������������������������������ <cmath> 5


Bessel Functions������������������������������������������������������������������������������������������������������ 6
Polynomials�������������������������������������������������������������������������������������������������������������� 7
Elliptic Integrals�������������������������������������������������������������������������������������������������������� 7
Exponential Integrals������������������������������������������������������������������������������������������������ 8
Error Functions��������������������������������������������������������������������������������������������������������� 8
Gamma Functions����������������������������������������������������������������������������������������������������� 8

www.allitebooks.com
■ Contents

Beta Functions���������������������������������������������������������������������������������������������������������� 9
Zeta Functions���������������������������������������������������������������������������������������������������������� 9
Minimum, Maximum, and Clamping����������������������������������� <algorithm> 9
Fixed-Width Integer Types���������������������������������������������������� <cstdint> 10
Arithmetic Type Properties����������������������������������������������������� <limits> 11
Complex Numbers���������������������������������������������������������������� <complex> 13
Compile-Time Rational Numbers��������������������������������������������� <ratio> 14
Random Numbers������������������������������������������������������������������ <random> 15
Random Number Generators���������������������������������������������������������������������������������� 15
Random Number Distributions������������������������������������������������������������������������������� 18

Numeric Arrays������������������������������������������������������������������� <valarray> 23


std::slice����������������������������������������������������������������������������������������������������������������� 24
std::gslice��������������������������������������������������������������������������������������������������������������� 25
std::mask_array������������������������������������������������������������������������������������������������������ 26
std::indirect_array�������������������������������������������������������������������������������������������������� 27

■■  Chapter 2: General Utilities���������������������������������������������������������� 29


Moving, Forwarding, Swapping���������������������������������������������<utility> 29
Moving�������������������������������������������������������������������������������������������������������������������� 29
Forwarding������������������������������������������������������������������������������������������������������������� 31
Swapping and Exchanging������������������������������������������������������������������������������������� 32

Pairs and Tuples������������������������������������������������������������������������������������ 33


Pairs��������������������������������������������������������������������������������������������������� <utility> 33
Tuples����������������������������������������������������������������������������������������������������� <tuple> 34

std::byte C++17 ��������������������������������������������������������������������� <cstddef> 35


Relational Operators������������������������������������������������������������� <utility> 36
Smart Pointers����������������������������������������������������������������������� <memory> 36
Exclusive Ownership Pointers�������������������������������������������������������������������������������� 36
Shared Ownership Pointers������������������������������������������������������������������������������������ 39

vi
■ Contents

Function Objects������������������������������������������������������������� <functional> 42


Reference Wrappers����������������������������������������������������������������������������������������������� 43
Predefined Functors����������������������������������������������������������������������������������������������� 43
Binding Function Arguments���������������������������������������������������������������������������������� 44
Negating a Callable C++17 ������������������������������������������������������������������������������������� 45

Generic Function Wrappers������������������������������������������������������������������������������������ 45


Functors for Class Members����������������������������������������������������������������������������������� 46

Initializer Lists������������������������������������������������������� <initializer_list> 47


Vocabulary Types C++17 ����������������������������������������������������������������������� 48

std::optional�������������������������������������������������������������������������������������� <optional> 48
std::variant������������������������������������������������������������������������������������������ <variant> 50
std::any��������������������������������������������������������������������������������������������������������<any> 55

Date and Time Utilities����������������������������������������������������������� <chrono> 56


Durations���������������������������������������������������������������������������������������������������������������� 57
Time Points������������������������������������������������������������������������������������������������������������� 58
Clocks��������������������������������������������������������������������������������������������������������������������� 59
C-Style Date and Time Utilities��������������������������������������������������������������� <ctime> 60

Type Utilities����������������������������������������������������������������������������������������� 62
Runtime Type Identification������������������������������������� <typeinfo>, <typeindex> 62
Type Traits�����������������������������������������������������������������������������������<type_traits> 63
Type Operations���������������������������������������������������������������������������������� <utility> 70

Generic Utilities������������������������������������������������������������������������������������� 71
std::invoke C++17 ������������������������������������������������������������������������� <functional> 71
std::addressof��������������������������������������������������������������������������������������� <memory> 72

vii
■ Contents

■■  Chapter 3: Containers������������������������������������������������������������������ 73


Iterators������������������������������������������������������������������������������ <iterator> 73
Iterator Tags������������������������������������������������������������������������������������������������������������ 74
Non-member Functions to Get Iterators����������������������������������������������������������������� 75
Non-member Operations on Iterators��������������������������������������������������������������������� 76
Sequential Containers��������������������������������������������������������������������������� 76
std::vector��������������������������������������������������������������������������������������������� <vector> 76
std::deque����������������������������������������������������������������������������������������������� <deque> 83
std::array������������������������������������������������������������������������������������������������ <array> 84
std::list and std::forward_list��������������������������������������<list>, <forward_list> 84
Sequential Containers Reference��������������������������������������������������������������������������� 86

std::bitset������������������������������������������������������������������������������� <bitset> 89
Complexity�������������������������������������������������������������������������������������������������������������� 90
Reference��������������������������������������������������������������������������������������������������������������� 90

Container Adaptors������������������������������������������������������������������������������� 91
std::queue����������������������������������������������������������������������������������������������� <queue> 91
std::priority_queue��������������������������������������������������������������������������������� <queue> 91
std::stack������������������������������������������������������������������������������������������������ <stack> 92
Example������������������������������������������������������������������������������������������������������������������ 92
Reference��������������������������������������������������������������������������������������������������������������� 93

Ordered Associative Containers������������������������������������������������������������ 93


std::map�������������������������������������������������������������������������������������������������������<map> 94
Inserting in a Map��������������������������������������������������������������������������������������������������� 95
std::multimap����������������������������������������������������������������������������������������������<map> 98
std::set and std::multiset�����������������������������������������������������������������������������<set> 98
Order of Elements��������������������������������������������������������������������������������������������������� 98
Searching��������������������������������������������������������������������������������������������������������������� 99
Moving Nodes Between Containers C++17 ���������������������������������������������������������� 100

Merging Containers C++17 ����������������������������������������������������������������������������������� 100

viii
■ Contents

Complexity������������������������������������������������������������������������������������������������������������ 101
Reference������������������������������������������������������������������������������������������������������������� 101

Unordered Associative Containers.......................................................


......................................................<unordered_map>, <unordered_set> 103
Hash Map�������������������������������������������������������������������������������������������������������������� 104
Template Type Parameters����������������������������������������������������������������������������������� 104
Hash Functions����������������������������������������������������������������������������������������������������� 104
Complexity������������������������������������������������������������������������������������������������������������ 106
Reference������������������������������������������������������������������������������������������������������������� 106

Allocators����������������������������������������������������������������������������� <memory> 108


Polymorphic Allocators C++17 ������������������������������������������<memory_resource> 108
Allocators for Multilevel Containers��������������������������������<scoped_allocator> 111

■■  Chapter 4: Algorithms���������������������������������������������������������������� 113


Input and Output Iterators������������������������������������������������������������������� 113
General Guidelines������������������������������������������������������������������������������ 114
Algorithm Arguments�������������������������������������������������������������������������������������������� 114

Terminology���������������������������������������������������������������������������������������� 115
Algorithms���������������������������������������������������������������������� <algorithm> 115
Applying a Function to a Range���������������������������������������������������������������������������� 115
Checking for the Presence of Elements���������������������������������������������������������������� 117
Finding Elements�������������������������������������������������������������������������������������������������� 117
Finding Min/Max Elements����������������������������������������������������������������������������������� 118
Binary Search������������������������������������������������������������������������������������������������������� 119
Subsequence Search�������������������������������������������������������������������������������������������� 120
Sequence Comparison������������������������������������������������������������������������������������������ 121
Generating Sequences������������������������������������������������������������������������������������������ 122
Copy, Move, Swap������������������������������������������������������������������������������������������������� 123
Removing and Replacing�������������������������������������������������������������������������������������� 124
Reversing and Rotating���������������������������������������������������������������������������������������� 125

ix
■ Contents

Partitioning����������������������������������������������������������������������������������������������������������� 126
Sorting������������������������������������������������������������������������������������������������������������������ 127
Sampling and Shuffling���������������������������������������������������������������������������������������� 128
Operations on Sorted Ranges������������������������������������������������������������������������������� 129
Permutation���������������������������������������������������������������������������������������������������������� 130
Heaps�������������������������������������������������������������������������������������������������������������������� 131

Numeric Algorithms������������������������������������������������������������<numeric> 132


Reductions������������������������������������������������������������������������������������������������������������ 132
Inner Products������������������������������������������������������������������������������������������������������ 133
Prefix Sums���������������������������������������������������������������������������������������������������������� 134
Element Differences��������������������������������������������������������������������������������������������� 135

Algorithms for Uninitialized Memory����������������������������������� <memory> 135


Parallel Algorithms C++17 ���������������������������������������������� <execution> 136
Parallel Execution������������������������������������������������������������������������������������������������� 137
Parallel Unsequenced Execution�������������������������������������������������������������������������� 138

Iterator Adaptors��������������������������������������������������������������� <iterator> 138


■■  Chapter 5: Input/Output������������������������������������������������������������� 141
Input/Output with Streams����������������������������������������������������������������� 141
Helper Types����������������������������������������������������������������������������������������������<ios> 142
Formatting Methods (std::ios_base)����������������������������������������������������������<ios> 143
I/O Manipulators������������������������������������������������������������������� <ios>, <iomanip> 145
Example���������������������������������������������������������������������������������������������������������������� 146
std::ios�������������������������������������������������������������������������������������������������������<ios> 147
std::ostream������������������������������������������������������������������������������������� <ostream> 149
std::istream�������������������������������������������������������������������������������������� <istream> 151
std::iostream������������������������������������������������������������������������������������� <istream> 153

x
■ Contents

String Streams��������������������������������������������������������������������<sstream> 153


Example���������������������������������������������������������������������������������������������������������������� 154

File Streams������������������������������������������������������������������������<fstream> 155


Example���������������������������������������������������������������������������������������������������������������� 156

Streaming Custom Types�������������������������������������������������������������������� 156


Custom << and >> Operators������������������������������������������������������������������������������ 156
Custom I/O Manipulators������������������������������������������������������������������������� <ios> 157

Stream Iterators���������������������������������������������������������������� <iterator> 160


std::ostream_iterator�������������������������������������������������������������������������������������������� 160
std::istream_iterator��������������������������������������������������������������������������������������������� 160

Stream Buffers���������������������������������������������������������������� <streambuf> 161


File Systems������������������������������������������������������������������� <filesystem> 162
Files, Paths, and Pathnames��������������������������������������������������������������������������������� 162
Error Reporting����������������������������������������������������������������������������������������������������� 163
The path Class������������������������������������������������������������������������������������������������������ 164
File Links�������������������������������������������������������������������������������������������������������������� 168
Path Normalization����������������������������������������������������������������������������������������������� 169
The Current Working Directory����������������������������������������������������������������������������� 170
Absolute and Relative Paths��������������������������������������������������������������������������������� 170
Comparing Paths�������������������������������������������������������������������������������������������������� 172
File Status������������������������������������������������������������������������������������������������������������� 172
Creating, Copying, Deleting, and Renaming���������������������������������������������������������� 176
File Sizes and Free Space������������������������������������������������������������������������������������ 177
Directory Listing��������������������������������������������������������������������������������������������������� 178

C-Style File Utilities������������������������������������������������������������� <cstdio> 180


C-Style Output and Input����������������������������������������������������� <cstdio> 181
std::printf() Family������������������������������������������������������������������������������������������������ 181
std::scanf() Family������������������������������������������������������������������������������������������������ 185

xi
■ Contents

■■  Chapter 6: Characters and Strings��������������������������������������������� 189


Strings��������������������������������������������������������������������������������� <string> 189
Searching in Strings��������������������������������������������������������������������������������������������� 190
Modifying Strings������������������������������������������������������������������������������������������������� 191
Constructing Strings��������������������������������������������������������������������������������������������� 192
String Length�������������������������������������������������������������������������������������������������������� 192
Copying (Sub)Strings�������������������������������������������������������������������������������������������� 193
Comparing Strings������������������������������������������������������������������������������������������������ 193

String Views C++17 ����������������������������������������������������� <string_view> 194


Character Classification�������������������������������������� <cctype>, <cwctype> 195
Character-Encoding Conversion������������������������� <locale>, <codecvt> 197
Localization�������������������������������������������������������������������������� <locale> 200
Locale Names������������������������������������������������������������������������������������������������������� 200
The Global Locale������������������������������������������������������������������������������������������������� 201
Basic std::locale Members����������������������������������������������������������������������������������� 202
Locale Facets�������������������������������������������������������������������������������������������������������� 202
Combining and Customizing Locales�������������������������������������������������������������������� 210
C Locales������������������������������������������������������������������������������������������ <clocale> 213

Regular Expressions�������������������������������������������������������������� <regex> 214


The ECMAScript Regular Expression Grammar���������������������������������������������������� 214
Regular Expression Objects���������������������������������������������������������������������������������� 216
Matching and Searching Patterns������������������������������������������������������������������������ 218
Match Iterators����������������������������������������������������������������������������������������������������� 221
Replacing Patterns����������������������������������������������������������������������������������������������� 223

Numeric Conversions�������������������������������������������������������������������������� 226


Convenient Conversion Functions������������������������������������������������������ <string> 227
High-Performance Conversion Functions C++17 ���������������������������� <charconv> 229

xii
■ Contents

■■  Chapter 7: Concurrency������������������������������������������������������������� 231


Threads�������������������������������������������������������������������������������� <thread> 231
Launching a New Thread�������������������������������������������������������������������������������������� 231
A Thread’s Lifetime����������������������������������������������������������������������������������������������� 232
Thread Identifiers������������������������������������������������������������������������������������������������� 232
Utility Functions���������������������������������������������������������������������������������������������������� 233
Exceptions������������������������������������������������������������������������������������������������������������ 233

Futures��������������������������������������������������������������������������������� <future> 234


Return Objects������������������������������������������������������������������������������������������������������ 234
Providers�������������������������������������������������������������������������������������������������������������� 235
Exceptions������������������������������������������������������������������������������������������������������������ 237

Mutual Exclusion������������������������������������������������������������������� <mutex> 238


Mutexes and Locks����������������������������������������������������������������������������������������������� 238
Mutex Types���������������������������������������������������������������������������������������������������������� 239
Lock Types������������������������������������������������������������������������������������������������������������ 241
Locking Multiple Mutexes������������������������������������������������������������������������������������� 244
Exceptions������������������������������������������������������������������������������������������������������������ 244

Calling a Function Once��������������������������������������������������������� <mutex> 245


Condition Variables������������������������������������������<condition_variable> 246
Waiting for a Condition����������������������������������������������������������������������������������������� 246
Notification����������������������������������������������������������������������������������������������������������� 247
Exceptions������������������������������������������������������������������������������������������������������������ 248

L1 Data Cache Line Size C++17 �������������������������������������������������<new> 248


Synchronization���������������������������������������������������������������������������������� 249
Atomic Operations��������������������������������������������������������������� <atomic> 250
Atomic Variables��������������������������������������������������������������������������������������������������� 250
Atomic Flags��������������������������������������������������������������������������������������������������������� 255
Non-member Functions and Macros�������������������������������������������������������������������� 255
Fences������������������������������������������������������������������������������������������������������������������ 255

xiii
■ Contents

■■  Chapter 8: Diagnostics��������������������������������������������������������������� 257


Assertions���������������������������������������������������������������������������<cassert> 257
Exceptions������������������������������������������������� <exception>, <stdexcept> 258
Exception Pointers���������������������������������������������������������� <exception> 259
Nested Exceptions���������������������������������������������������������� <exception> 260
System Errors������������������������������������������������������������ <system_error> 262
std::error_category����������������������������������������������������������������������������������������������� 263
std::error_code����������������������������������������������������������������������������������������������������� 263
std::error_condition���������������������������������������������������������������������������������������������� 264

C Error Numbers�������������������������������������������������������������������<cerrno> 264


Failure Handling�������������������������������������������������������������� <exception> 265
std::uncaught_exceptions() C++17 ����������������������������������������������������������������������� 265

std::terminate()����������������������������������������������������������������������������������������������������� 266

■■  Appendix: Standard Library Headers����������������������������������������� 271


Numerics and Math (Chapter 1)���������������������������������������������������������������������������� 271
General Utilities (Chapter 2)���������������������������������������������������������������������������������� 272
Containers (Chapter 3)������������������������������������������������������������������������������������������ 273
Algorithms (Chapter 4)������������������������������������������������������������������������������������������ 274
Input/Output (Chapter 5)��������������������������������������������������������������������������������������� 274
Characters and Strings (Chapter 6)���������������������������������������������������������������������� 275
Concurrency (Chapter 7)��������������������������������������������������������������������������������������� 276
Diagnostics (Chapter 8)���������������������������������������������������������������������������������������� 277
The C Standard Library����������������������������������������������������������������������������������������� 277

Index���������������������������������������������������������������������������������������������� 279

xiv
About the Authors

Peter Van Weert is a Belgian software engineer and


C++ expert, mainly experienced in large-scale desktop
application development. He is passionate about
coding, algorithms, and data structures.
Peter received his master of science in computer
science summa cum laude with congratulations of the
Board of Examiners from the University of Leuven. In
2010, he completed his PhD thesis in Leuven at the
research group for declarative languages and artificial
intelligence. During his doctoral studies, he was a
teaching assistant for courses on software analysis
and design, object-oriented programming (Java), and
declarative programming (Prolog and Haskell).
After graduating, Peter joined Nikon Metrology to work on industrial metrology
software for high-precision 3D laser scanning and point cloud–based inspection. At
Nikon, he learned to handle large C++ code bases and gained further proficiency in all
aspects of the software development process—skills that serve him well today at Medicim,
the software R&D center for dental companies Nobel Biocare, Ormco, and KaVo Kerr.
At Medicim, Peter contributes to their next-generation digital platform for dentists,
orthodontists, and oral surgeons that offers patient data acquisition from a wide range of
hardware, diagnostic functionality, implant planning, and prosthetic design.
In his spare time, Peter writes books on C++ and is a regular speaker at and board
member of the Belgian C++ Users Group.

Marc Gregoire is a software architect from Belgium.


He graduated from the University of Leuven, Belgium,
with a degree in “Burgerlijk ingenieur in de computer
wetenschappen” (equivalent to a master of science in
engineering in computer science). The year after, he
received an advanced master’s degree in artificial
intelligence, cum laude, at the same university. After
his studies, Marc started working for a software
consultancy company called Ordina Belgium. As a
consultant, he worked for Siemens and Nokia Siemens
Networks on critical 2G and 3G software running on
Solaris for telecom operators. This required working in
international teams stretching from South America and
the United States to Europe, the Middle East, Africa,
and Asia. Now, Marc is a software architect at Nikon

xv
Other documents randomly have
different content
"They belong as much to Mr. Vanderput as to us, you know. Is Mr.
Vanderput here to-day?"
"To be sure. He is to be at the burial-feast; and Miss Gertrude----."
"Gertrude! Is Gertrude here?" cried Christian, sitting up with a jerk
which alarmed his attendant for the consequences. "O, if she will
stay the whole day, it will be as good as the pastor having come
back."
"She crossed from Saardam on purpose. She will tell you about
the angels, if any body can; for she lives in heaven as much as the
pastor himself, they say."
"She is an angel herself," quietly observed Gertrude's little adorer.
Katrina went on with her list.
"Then there is Fransje Slyk and her father. He looks as if he knew
what a funeral should be, and as grave as if he had been own
brother to the departed. I cannot say as much for Fransje."
"I had rather have Fransje's behaviour than her father's, though I
do not much like her," said Christian. "Mr. Slyk always glances round
to see how other people are looking, before he settles his face
completely."
"Well; you will see how he looks to-day. These are all who will stay
till evening, I believe, except Mr. Visscher."
"Mr. Visscher! What is he to stay for? I suppose Heins wants to
talk to him about this new cargo that came too late. O, Kaatje, I
never can bear to look through the trees at that ship again. I saw the
white sails in the moonlight all that night when I lay watching what
was going on, and heard Heins's step in and out, and my mother's
voice when she thought nobody heard her; and I could not catch a
breath of my father's voice, though I listened till the rustle of my head
on the pillow startled me. And then my mother came in, looking so
that I thought my father was better; but she came to tell me that I
should never hear his voice any more. But O, if she knew how often I
have heard it since! how glad I should be to leave off hearing it when
I am alone----."
Poor Christian wept so as not to be comforted till his beloved
friend Gertrude came to hear what he had to say about those whom
he believed to be her kindred angels.
Heins was missed from the company soon after the less familiar
guests had departed, and left the intimate friends of the family to
complete the offices of condolence. Heins was as soon weary of
constraint as most people, which made it the more surprising that he
imposed on himself so much more of it than was necessary. All knew
pretty well what Heins was, though he was perpetually striving to
seem something else; and his painful efforts were just so much
labour in vain. Every body knew this morning, through all the
attempts to feel grief by which he tried to cheat himself and others,
that his father's death was quite as much a relief as a sorrow to him;
and that, while he wore a face of abstraction, he was longing for
some opportunity of getting out upon the quay to learn tidings of the
ships and cargoes of which he was now in fact master. The fact was
that Heins was as much bent on being rich as his father had been,
but he wanted to make greater haste to be so, and to enjoy free
scope for a trial of his more liberal commercial notions. For this free
scope, he must yet wait; for his partner, Mr. Vanderput, was as
steady a man of business, though a less prejudiced one, than the
senior Snoek had been; and then there was Mrs. Snoek. She was
not permitted, by the customs of the country, to meddle in affairs
relating to commerce; but she knew her maternal duty too well not to
keep an eye on the disposal of the capital which included the
fortunes of her younger children. It was to be apprehended that she
would be ready with objections whenever a particularly grand
enterprize should demand the union of all the resources of the firm.
Some liberty had, however, been gained through the obstinacy of the
fever which would not yield to French brandy and Oriental spices;
and there were many eyes upon Heins already, to watch how he
would set out on his commercial career.
Some of these eyes followed him from his mother's door to the
quay, and back again, when he had concluded his inquiries among
the captains. It was remarked that there was, during the latter transit,
a gloom in his countenance which was no mockery.
On his re-appearance in his mother's parlour, the cause was soon
told, first to his partner, next to his mother, and then (as there were
none but intimate friends) to all present. The result of the
communication was an outcry against the English, as very
troublesome neighbours, while the widow's first thought was of
thankfulness that her husband had died without hearing news which
would have caused him great trouble of mind. Heins appealed to all
who understood the state of Dutch commerce, whether Great Britain
had not done mischief enough long ago, by prohibiting the
importation of bulky goods by any ships but those which belonged to
the exporting or importing country.
"That prohibition was evidently aimed at us Dutch," observed
Vanderput. "We were carriers to half the world, till Great Britain
chose that we should no longer carry for her. She might punish
herself in that manner, and welcome, if she could do so without
punishing us; but it is a serious grievance,--difficult as it now is to
find an investment for our capital,--to be obliged to lay by any of our
shipping as useless."
"We did all we could," said Heins piteously. "Since we could not
carry the produce of the East and West into the ports of Great Britain
for sale, we brought it here, that the British captains might not have
far to go for it. But it seems that Great Britain is jealous of this; for
there is a new prohibition (if the report be true) against importing any
bulky produce purchased anywhere but in the country where it is
produced."
"I hope this is too bad to be true," observed Visscher.
"Nothing is too bad to be attempted by a jealous country against
one which has been particularly successful in commerce," observed
Snoek. "The tonnage of this country is more than half that of all
Europe; and Great Britain thinks it time to lower our superiority.
Whether she will gain by doing so, time will show."
"I think Great Britain is very illnatured and very mean," observed
Christian, who had generally something to say on every subject that
was discussed in his presence. "I think I shall call her Little Britain,
from this time. But, Heins, what will you do with all the things you
have bought, as you told me, in Asia and America, and in France
and Italy? You must send back your cinnamon to Ceylon, and----O,
but I forgot that other people may buy them, though the English will
not. But I hope you have not bought too much for the present
number of your customers. There is another large ship coming from
one of the American islands, I heard----."
He was checked by the remembrance of who it was that told him
this. Heins related, with a deep sigh, which might be given to the
memory of either the ship or its owner, that the vessel had been
wrecked, and was now at the bottom of the sea. This was the other
piece of bad news he had to tell. At least two-thirds of his hearers
asked after the crew, while the rest inquired for the cargo. The cargo
was lost, except a small portion, which had been preserved with
difficulty. The crew had been picked up, only one sailor-boy being
missing. It was from two of them who had found their way home that
Heins had received the tidings of his misfortune.
"One sailor-boy!" repeated Christian. "Do you know how he was
lost? Was he blown from the yards, do you think? Or was he washed
overboard? or did he go down with the ship?"
Heins did not know any particulars of the sailor-boy. But where?
But how? But when did this happen?
It happened where many shipwrecks had happened before, and
many would again, and in the same manner. The vessel had struck
on the Eddystone rock on a stormy night. This was another nuisance
for which the Dutch were indebted to the English. This fatal rock----.
"Did the English make the Eddystone rock?" little Roselyn
inquired, in a low voice, of the pastor. "I thought it was God that
broke up the fountains of the deeps, and fixed the everlasting hills."
Her wiser brother Christian enlightened her.
"God made this rock; but perhaps he made it so that it might be of
use to us, instead of doing us harm, if the English would make the
best use of it. Is not that what Heins means, M. Aymond?"
M. Aymond believed that what Mr. Vanderput had just said was
true; that the English were about to build a light-house on this
dangerous rock, which might thus be made to guide ships into a
British harbour, instead of causing them to perish. He trusted that it
would appear that Heins was mistaken in saying that many more
ships would be lost on that rock; and he hoped that men would learn
in time to make all God's works instruments of blessing to their race.
Christian carried on the speculation.
"And then, perhaps, man's works may not perish by accident
before they are worn out, as this ship did. But yet this was what
happened with one of God's works too,--that sailor-boy. He perished
before he was worn out. But why do people ever wear out, M.
Aymond? Whether a person is drowned at fifteen or dies worn out at
eighty, does not much signify, if God could make them live a
thousand years. Only think of a person living a thousand years, M.
Aymond! He would see cities grow as we see ant-hills rise, while the
sea roared against the dykes as it did at the beginning. He would
see the stars move so often that he would know them all in their
places. He would know almost everything. O! why do not men live a
thousand years? and why does God let a young sailor-boy be lost?"
Gertrude whispered, "All the days of Methuselah were nine
hundred, sixty and nine years; and he died."
"Yes," added the pastor, gravely meeting the kindling eyes of
Christian; "death comes sooner or later; and whether it came soon or
late would be all in all if we were to live no more. But as man's life is
never to end----"
"Ah! I see. If his life is never to end, it does not signify so much
when he passes out of one kind of life into another. I was going to
ask why there should be any death at all. If I made a world, I would---
-"
Christian had talked too eagerly, and now was prevented by his
cough from speaking any more at present. When he recovered his
voice, the pastor turned his attention from the lost sailor-boy to the
lost ship, asking whether it had not answered its purpose in making
several voyages; whether the skill and toil of the artificers had not
been repaid. Christian thought not; and he went on to exhibit as
much as he could of the worked up knowledge and labour which had
in this instance been engulphed by the waves. He seemed so much
irritated, however, by his imperfection in the knowledge of ship-
building, that Gertrude proposed that he should pay her a visit at
Saardam, where he might look down from a window upon the dock-
yard, and witness nearly the whole process without being moved
from his couch. She almost repented the proposal when she saw the
poor boy's rapture; but, happily, no one perceived any objection to
the plan. The little voyage of seven miles could be made perfectly
easy to invalids; and it was quite certain that Christian would be
happy with Gertrude, if anywhere. Heins and the pastor contended
for the charge of Christian, and old Mr. Slyk, the most punctilious of
mourners, allowed that such an indulgence might,--especially with a
view to increased knowledge,--be extended to a sufferer like
Christian, within the days of strict mourning, provided the mother and
the younger children staid at home. Luc clenched his fist on hearing
this, and Roselyn pouted; but their jealousy of their brother soon
vanished when his dreaded pain came on, and they were put out of
the room by their mother, as usual, that they might not become
hardened to the expressions of agony which they could not relieve.
They were heartily glad when the day was nearly over;--when
there was an end of going from the melancholy burial feast in one
room, into the apartment where Gertrude was describing to the now
passive Christian spectacles which they were not to see, and
pleasures which were held to be incompatible with the mourning of
which they already required to be reminded. They were not,
however, allowed to retire in this state of forgetfulness of the
occasion. The pastor's closing prayer, the solemn looks of the
servants, and their mother's silent tears when she laid her hand
upon their heads, left them no disposition for complaint as they stole
away to their beds.
Chapter II.
AN EXCURSION.

"One, two, three,--five of you going with me to Saardam!" cried


Christian, as he saw Heins and the pastor follow the children and
Katrina into the boat: the children who, in Mr. Slyk's absence, had
prevailed on their mother's good nature to let them go with their
brothers. "And Mr. Visscher is coming before the afternoon. What a
party to belong to me!"
It was very natural that Christian should overrate his own
importance, passing his life, as he did, in a little circle where every
one was eager to give him pleasure: but never was he more
mistaken than in supposing that he was any thing more than a
convenient pretence to some of his friends for visiting Saardam.
There was an attraction there which would have taken two of them
thither every day, if as good an excuse had offered as that of which
they now took advantage. Heins felt that at Saardam resided one
who would make as perfect a wife for a rich Amsterdam merchant as
could be imagined, if she had but a little more gaiety. She was pretty;
she was amiable; she was rich; and she and his mother would suit
admirably; and the children were fond of her. The pastor's feelings
about Gertrude are less easily described; but they tended to the
same object as those of Heins. These two were aware of each
other's intentions; but there was as little enmity in their rivalship as
there was present satisfaction in their pursuit. Aymond was perfectly
convinced that Gertrude could never love Heins; but he was nearly
as certain that she did not yet love himself: and Heins found that he
made no progress in the lady's good graces, while he trusted that his
friendly hints to her brother would prevent her throwing herself away
upon a poor refugee minister of religion, whose tender conscience
had already led him into adversity, and who could therefore never be
trusted to keep out of it in future.
"What a party of you to take care of me!" repeated Christian, in
great glee, when he began to enjoy the easy motion of the boat, and
to perceive that his deadly enemy, the fog, was clearing away before
the bright June sunshine. "Look, pastor, look at Amsterdam! Is there
a city in the world like Amsterdam, I wonder? How the spires, and
the highest houses stand up out of the mist, like a little city floating in
the air, or sailing in a cloud. O, Heins!--Kaatje, do ask Heins which
bells those are. I am sure I never heard such sweet bells before."
They were the bells of St. Nicholas Church, which Christian heard
almost every day of his life. Christian would hardly believe they were
the same.
"They clatter and jangle so as to make my head ache very often;
but these might send one to sleep, if it were not much pleasanter to
lie awake and listen to them.--Everything is light coloured here to
what it is at home,--as if silver had been shed over it. The sky is not
bright blue, as it is between the limes, but grey; and the water
gleams as if the moon was hanging just over it; and it is not muddy
under the boat as it is below our bridge; and I dare say there is never
any bad smell, and nobody need be afraid of ague. I wish we could
stop, that I might fish. There must be plenty of fine fish in such water
as this."
When reminded of Saardam dock-yards, however, he had no
further wish for delay. From this moment to the time of landing,
Katrina's good-nature was taxed to turn him incessantly, that he
might see, now the forest of masts at Amsterdam, and the dark hulls
resting upon the grey water, and then the gaily-painted wooden
houses of Saardam, with their pointed gables turned some one way
and some another, each with its weather-cock; and all looking like
baby-houses amidst the vast piles of timber from which the dock-
yards were supplied.
Christian's delight was in no wise diminished when he was
established on his couch at the promised window, whence he could
overlook one of the busiest parts of the dock-yard. He had no
attention to spare for the tidings of wonder which Roselyn brought,
from one quarter of an hour to another, when she had fairly gained
her point of being allowed to find her way about as she pleased. Now
she drew near to whisper that she was sure there was to be a very
good dinner, as twice the quantity of turf was burning in the kitchen
that was ever used at home, and such a number of bright pots upon
the fire that it was inconceivable what could be in them. She had
tried to find out, but they were all close covered, and the servants
were so busy and so quiet that she was afraid to ask. Better wait and
see, Christian pronounced; so off ran Roselyn in another direction,
whence she soon returned with more wonders. The garden,--
Christian must see the garden. It was little larger than the room he
was sitting in; but it had walks, and grottos, and a rivulet; and the
rivulet had a paved bed of pebbles, and the walks were made of
cockle-shells, and the borders of red and blue and green glass; and
the wall which enclosed the whole, was chequered with blue and
white bricks. Moreover, there was a better garden some way off, with
tulips as fine as could be seen any where within five leagues of
Amsterdam. Fond of tulips and good dinners as Christian was, all
this interested him less than what was passing before his eyes. He
wanted to be left in peace to make his observations, till his beloved
Gertrude could come and answer his questions.
When she appeared, Heins was at her heels. He could never
understand that it was disagreeable to her to be followed, which ever
way she turned; and attributed her gravity of countenance to the
religious bent she had taken, which was a most desirable quality in a
wife. Christian wished, with all his heart, that Heins would keep
away, that Gertrude and he might be as happy together as they
always were when there was no one by to whom she curtsied and
spoke with formality.
"Does not this hammering tire you?" she asked.
"You had better let me carry you into the inner room," said Heins.
"It is as quiet there as on the water."
"O, no, no," cried Christian. "I have not seen half that I want; and I
am very glad that they are at work so nearly under the window,
because I can watch what they are doing. They were hauling up that
great beam when I came, and now look how nicely they have fitted it
into its place. But I want to know who some of these people are. You
see that short man, smoking, with the rule in his hand, and a great
roll of papers peeping out of his breeches pocket."
"Yes; that is a master-builder. You will see that he is never long out
of sight of his men."
"You might have known him for the master-builder, and these
shipwrights for his men," observed Heins.
"I guessed who he was: but there is another who looks something
like a master too, though he is dressed like a sailor. He is a very idle
man, I think. He has stood there all this time, with his arms folded,
making the men laugh, and the master too, sometimes. Once he
took up a mallet that another man had laid down; and a strong blow
he gave with it: but he soon left off, and the master did not seem to
scold him at all."
"Nobody scolds Master Peter. Nobody asks him to do more work
than he likes; but he does a great deal; and hard work too. He likes
joking quite as well as working; and these men are fond of having
him among them, for he lightens their labour, and is very good-
natured."
This hint was enough for Luc, who came into the apartment just in
time to hear it. He found his way to another window which also
looked into the yard, and began to call, at first cautiously, and then
more loudly, "Master Peter! Master Peter!"
Master Peter did not hear till the party at the window heard also;
and when he turned, Gertrude was leaning out to ascertain which of
her household was making overtures of acquaintance. Luc's head
had already disappeared; so that Master Peter could not but
suppose that it was Gertrude who had greeted him. He laid his hand
on his breast, and, with a gesture of courtesy, advanced directly
beneath the window. The lady explained that some young visitors
had made free with his good-nature; and he immediately asked if
they would like to come down and view the dock-yard. At the close of
his speech, he turned to the master, as if suddenly recollecting that
he ought to ask permission to admit visitors. The master exerted
himself to intermit his puffs of smoke, while he desired Master Peter
to do as he chose.
"O, let me go! let me go!" cried Christian, in answer to Heins's
doubts whether it would not be causing too much trouble to gratify
the boy's wish.
Gertrude soon settled the affair by taking hold of one side of
Christian's little chair, and making Katrina take the other. She would
not relinquish her grasp in favour of Heins, who followed her out,
officiously pressing his help; she reserved that favour for Master
Peter, who met the party at the gate of the yard, and immediately
seeing the state of the case, took the boy in his arms, and promised
to show him whatever he wished to see. Those who knew Christian
thought this a large promise; and Heins was very instructive as to the
degree in which it should be accepted.
The boy himself, as he looked around him, scarcely knew where
and how to begin his inquiries. Vessels in every stage of progress,
from the bare-ribbed skeleton to the full-rigged merchant ship, ready
for launching, met his eye in every direction. The carpenters' yards
resounded with the blows of the mallet; the rope-walks looked
tempting; and he also wanted to be carried among the stacks of
timber which seemed to him too huge to have been piled up by
human strength.
"Where can all this wood have come from?" was his natural
exclamation.
"Some of it came from my country," replied Master Peter. "You see
that pile of tall pine-trees laid one upon another as high as the Stadt-
house. Those are masts for the ships we are building; and they
come out of the woods of my country. They came as part of a cargo,
and some of them will go back as part of a ship that carries a cargo."
"And where will it go next?"
"It will come back again with hemp to make such ropes as those,
and pitch and tar to smear the timbers with, and canvass for the
sails, and many things besides that your people want for use, and
your merchants for sale,--tallow, and oils, and hides, and furs."
"But do not you want the hemp, and pitch, and canvass for your
own ships? Or have you enough for both yourselves and us?"
Master Peter was sorry to say that very few ships had yet been
built in his country. He hoped there would soon be more. But his
countrymen must still manage to have enough of the produce of their
woods and wilds for themselves and the Dutch, as they could not do
without many things which the Dutch merchants were accustomed to
bring them in exchange; silks and jewels, for the ladies; wine, spice,
and fruit, for their tables: gold and silver to make money of; and
pewter vessels and steel utensils for their kitchens."
"But you can fetch these things for yourselves when you have
ships," argued Christian.
"We can fetch them, but we must have something ready to give in
payment for them."
Heins disputed whether any other country could compete with the
United Provinces in fetching commodities from all parts of the globe.
He treated with solemn ridicule Master Peter's hopes of what might
be achieved by fleets which were not yet in existence, and pointed
out, with a very insulting air of superiority, the resources of his own
country.--To say nothing of the half-finished navy which was before
their eyes, there was a forest of masts just within sight, which he
defied any port in the world to rival. There were ships of his own and
his partner's bringing iron, copper, and the materials of war from
Sweden and Norway; grain and flax-seed from the Baltic; books,
wines, and timber from Germany; coal from England; spice, fruits,
and cottons from the regions of the east; and gold and silver from the
west.
All very true, Master Peter allowed; but all this need not prevent
his country from fetching and carrying as much as she could,
whether it might prove more convenient to furnish herself with all that
she wanted from the ports of Holland, or to go round the world to
purchase each commodity in its native region. In answer to Heins's
boast of the commerce of the United Provinces, Peter begged to
remind him that it was now past its greatest glory. It had perceptibly
declined for more than twenty years.--Heins insisted that the
shipping of the United Provinces nearly equalled that of the whole of
the rest of Europe.--True again; but it was pretty certain that Dutch
prosperity would not advance much beyond the point it had now
reached, while that of other countries might rapidly overtake it. The
Dutch had so much wealth that they now found difficulty in making
profitable use of it in their own country; and by lending it to
foreigners, they helped those foreigners to become rivals to
themselves. Such was the result of Master Peter's observation in the
course of his travels,--travels which he hoped to extend to England,
where he might chance to meet Dutch capital in another form. He
understood that the Dutch had not only deposited forty millions of
their wealth in the English funds, but had lent large sums to
individuals; thus investing money in a rival country for the sake of the
higher interest which could be obtained there.
Christian thought this very unpatriotic. If it was true, also, as he
had been told by his mother, that Heins and Mr. Vanderput sold no
goods abroad, but brought a great many to sell at home, he thought
the firm very wrong indeed. If they chose to spend Dutch money in
the countries of their rivals and their enemies, they ought at least to
take care that their rivals spent as much money among them.
Heins replied that this was the concern of the exporting merchants
who had the use of the ships to carry out Dutch produce, which were
to return with foreign commodities.
"You should look well to them," persisted Christian; "for I do not
believe they bring in half so much money as you send out. I never
see such a thing as a Spanish dollar, or an English guinea, unless a
traveller has come to Amsterdam to spend it; and how we have so
many ducats, and guilders, and stivers left, after the number you
send away, is more than I can tell."
Heins replied mysteriously that his partner and he seldom sent
away any money; which made Christian very angry, certain as he
was of what his mother had told him of Heins being an importing
merchant.
"How can you tease the boy?" inquired Master Peter. And he
asked Christian if he really supposed that everything that was
bought, all the world over, was bought with gold and silver? If he
would only consider the quantity of coin that would have been
collected in the States by this time if all their produce had been thus
paid for, he would see how troublesome such a method of commerce
would be.
But some of this money would go away again, Christian observed,
as long as the States bought as well as sold. However, he perceived
that while there was mutual exchange, it must save much trouble to
exchange the goods against one another, as far as they would go,
and pay only the balance in money. But this balance, when large,
must be a very sad thing for the country that had to pay it.
"Do you think the country would become liable to pay it," asked
Master Peter, "if it had no advantage in return? Do you think your
brother would run up heavy bills with the French wine-growers, if he
did not hope to make profit of their wines? When my country has as
many ships as I wish her to have, I shall encourage my merchants
to--I mean, I hope my countrymen will--make very large purchases
from foreign countries."
"But if Heins sends away a ship load of guilders," remonstrated
Christian, "the States will be so much the poorer, however much
wine may come in return; because the wine will be drunk in
Amsterdam, and paid for with more guilders. And then Heins will
send out these guilders again, I suppose, and not care how little
money there is left in the country, so long as his own pocket is filled."
Heins smiled condescendingly, and promised Christian that when
he grew older he should know better what he was talking about. How
should the boy know better, unless his questions were answered?
asked Gertrude, who came with Katrina to relieve Master Peter of his
charge. But the good-natured sailor took his seat on a piece of
timber, saying that the little man should have his questions properly
attended to;--questions the very same as had been asked by many a
taller, if not a wiser man. Christian did not like to be called "little
man," but forgave the expression in consideration of his questions
being thought manly. Peter told him that many kings having feared
for their kingdoms what Christian feared for the States,--that they
would be emptied of money,--had passed laws to prohibit money
being sent out of the country. They had not remembered, any more
than Christian, that other countries must buy also; so that Heins's
neighbours would be taking money from abroad, while Heins was
sending it out,--supposing that it actually went in the shape of
guilders.
"But how do we know that they will buy?" asked Christian. "If they
do not choose to buy--what then?"
"They always do choose it, and must choose it, since they cannot
get what they want in any other way. The people in the mine-
countries,--in South America,--have more gold and silver than they
know what to do with; and no linen, no cloth, no knives and pots and
kettles, no one of many articles that they consider necessary to their
comfort. Now, would not it be very foolish in their governors to
prevent their sending out their spare gold in exchange for what they
must otherwise do without?"
Yes: but Christian thought the case of mining countries peculiar.
No where else, he supposed, was precious metal superabundant. If
it were indeed,----But perhaps the truest sign of there being too
much of it was the wish of the people to send it away. What would
Master Peter do if he was a ruler?
Master Peter's nation being in great want of gold and silver, he
should wish his people to send out as much tallow and timber as
they could sell; but if he ruled in Holland, where there was more
precious metal than was wanted, he would encourage the Dutch to
send out velvets and brandy, for the sake of bringing back, not
money, but wealth in some more useful form. In either case, it would
be for the sake of what was brought back that he should be anxious
to have the produce of the country exported.
Of course, Christian observed, there could be little good in sending
property away unless for the sake of what it brought back. He, for his
part, should have no particular wish to dispose of his show-box at
the next fair, if he was to have only an apple in exchange; but he
should be glad to sell it for the model of a ship which he much
desired to have. In the latter case, he should be much pleased; but
his pleasure would be, not in parting with his show-box, but in
gaining the model.
"Well, my dear boy," said Heins, "that will do. We are not children
who want to have every thing explained by a wise little man like
you."
"Those kings were not children that Master Peter was speaking
of," observed Christian; "and yet they seemed to want to have it
explained that they might as well part with their gold as with anything
else, since the thing that signified most was whether they got
anything better in exchange."
"You have quite changed your opinion," said Gertrude. "An hour
ago, you thought it a very sad thing to part with gold."
"Yes; because I thought gold was somehow more valuable than
anything else; that it had a value of its own. But, if there is any one
country where gold is of little use, it seems as if it was much like
other goods;--fit to be changed away when one has too much of it,
and got back again when one wants it."
"Then it is time," said Gertrude, "that merchants, and those who
rule them, should leave off being very glad when money is imported
rather than goods, and very sorry when it is exported."
"They may feel sure," Heins observed, "that they will soon have an
opportunity of getting more money, if they want it. No one thing is
bought and sold so often as money; and they may be as confident
that some will soon fall in their way as that there would always be
blue cloth in the market, if every trader in the world bought and sold
blue cloth."
Christian saw yet another consequence from what Master Peter
had told him. If gold was very cheap in Peru and very dear in Russia,
and if furs and hemp were very cheap in Russia and very dear in
Peru, it would do as much good to the one country as to the other to
exchange them, while it could do nobody any harm. At this grand
discovery the boy was so delighted that he ran the risk of bringing on
his pain by the start which he made to put his face opposite to
Master Peter's. It was very mortifying to hear once more Heins's
compassionate laugh, while he asked whether everybody did not
know this before. Did not his mother send abroad the butter which it
cost very little to make at the farm, and cause her household to eat
salt butter of foreign preparation?
"I never could make that out; and Kaatje never could tell me,"
exclaimed Christian. "We none of us like the salt butter so well; and it
costs more to buy than our own fresh butter to make; and yet we
must all eat salt butter."
"Because my mother can sell every kop of her butter abroad for
more than she pays for the best salt butter that is brought in. You
know there is no butter to equal the Dutch."
"Nor anything else, by your own account, Mr. Heins," replied
Master Peter, laughing. "There is nothing to be found abroad equal
to what you have at home. A pretty honest boast this for a large
importer! What say you to your corn?"
"That our difficulty in producing it has proved the loftiness of Dutch
genius, and the abundance of Dutch resources. Nature has placed
us in a barren district, where we have not the less multiplied and
prospered, through our own talents and virtues, by which we have
been supplied from abroad with that which Providence had forbidden
to us."
"If Providence forbade us to have corn," said Christian aside to
Gertrude, "how is it that we have corn? It seems to me that it is very
like Providence's having made the Eddystone Rock a dangerous
place. Men have been reminded to make it a useful beacon; and our
people at home have been obliged to begin a trade in corn; which
trade has made them rich; so that they are better off, perhaps, than if
they had had the most fertile fields in the world."
Gertrude smiled, and said she believed this was the method by
which Providence taught men to help one another, and showed them
how. After this, Christian heard no more of the argument going on
about the extent to which the Dutch traders had successfully carried
their principles of exporting goods that were cheap, and importing
those which were dear. He was pondering the uses of adversity,--of
the few kinds of adversity which had particularly struck him.--What
was there in the storms of the Zee,--what was there in the clay soil of
Luc's garden, where no hyacinths would grow,--what was there in
the French king's ravaging wars,--what was there in his own horrible
pain, to show men how to help one another? In his own case, one
side of the question was easily answered. At this moment, while his
weary head was resting on Master Peter's breast, wondering at the
depth of voice which vibrated from within, he felt that his infirmities
allured the wise and the strong to help and comfort him; but how
wars stimulated men to aid as well as destroy one another--much
more, how he could be of service to any body, were subjects for
much deeper meditation. Just when he had an impression that he
had arrived near the solution, he unconsciously lost the thread of his
argument; and when his companions, some time afterwards, would
have asked his opinion of what was last said, they found that he was
happily asleep on the bosom of his new friend.
The hut in which Master Peter had taken up his abode being just
at hand, he insisted on laying the boy on his own bed, while he took
his frugal workman's meal. Gertrude, who said she could see the
dock-yards any day of her life, remained with Christian, while her
guests continued their survey of the curiosities of the place.
When they returned to the house to dinner, they found that the
other expected guest, Aalbert Visscher, had arrived, and was making
himself very agreeable to Christian;--probably more so than to
Gertrude; since his discourse was of pleasures whose number and
variety could scarcely be approved by such steady and self-denying
persons as the Vanderputs. Gay were the tales of the snipe-shooting
and skaiting of last winter; of the sailing and fishing matches of the
spring; and of the wagers of fancy pipes and rare tobacco which yet
remained to be decided by the arrival or non-arrival of expected
ships by a certain day. Gertrude rose and offered to show Christian
the curious time-piece he had inquired for;--the time-piece whose
hours were struck on porcelain cups by a silver hammer. It was
almost the first time Gertrude was ever known to break voluntarily
the modest silence of a Dutchwoman in company; much more to
interrupt the conversation of another; and Christian looked up
surprised.
"My poor boy," exclaimed Aalbert, "I beg your pardon. I only
thought of amusing you, and I am afraid I have hurt you."
"O, because I cannot shoot and skait and swim? It does not hurt
me, indeed, or I am sure I should be very unhappy; for I hear of
something every day that I shall never be able to do."
"Christian likes to hear of other people's pleasures, whether he
can join in them or not," observed Gertrude. "But he can lay wagers,
and may be all the more easily tempted to do so from having fewer
amusements than you, Mr. Visscher."
"And you do not approve of laying wagers, my sober lady," replied
Aalbert.
"It is God who appoints the winds, and makes a path in the deep
waters for the blessings he brings us," replied Gertrude; "and I think
it scarcely becomes us to sport with the uncertainty with which He is
pleased to try our faith, and make matter for gambling of His secret
counsels."
The pastor enforced the impiety. Vanderput thought all gambling
vicious; and Heins proved to Christian that in him it would be
peculiarly atrocious, since, as he could never hope to earn any
money, his speculations must be at the risk of others. Christian
ingenuously admitted all this, but was not the less in a hurry to ask
for more tales of adventure from the gay bill-broker, as soon as the
pastor's long grace was over. Nothing more was said of wagers; nor
was it necessary, so ample were Aalbert's other resources of
amusement,--or, as the pastor expressed it, of dissipation. Aymond's
countenance wore a deeper gravity every moment as he saw the
eagerness with which the children listened, the indolent satisfaction
with which Vanderput let his guests be thus entertained, and the
interest with which even Gertrude appeared to be beguiled. Heins
also perceived this interest; and thought it time to be exerting himself
to rival it. He took advantage of every long puff with which his
adversary regaled himself, to draw attention upon his own gaieties.
For every wild-duck, he had a story of a tulip; for every marvellous
bagging of snipe, he had an unheard-of draught of herrings. If
Aalbert had made a humorous bargain at the last Rotterdam fair, he
had made an excessively acute one. If the bill-broker had met with a
ducking in Haerlem lake, the importer had been within an ace of
running aground in the Zuyder Zee. There was a remarkable parallel
between their fortunes if Gertrude would but perceive it. What she
was most ready to perceive, however, was that the conversation
grew very tiresome after Heins had taken it up; and she was not
sorry when the boatmen sent in word that it was time the party were
afloat, if they meant to reach Amsterdam before the gates were
closed.
The prudent guests were in haste to be gone. It was true that, by
paying a stiver each, they might gain admittance any time within an
hour from the first closing of the gates; but where was the use of
paying a stiver, if it could be as well avoided?
As it was bad for Christian's cough to be on the water in the
evening, he was left behind to enjoy one more survey of the dock-
yard,--one more chance of intercourse with his dear Master Peter.
He sacrificed something, he knew, in not seeing the congregation of
dark masts springing from the silver mist, and not feeling the awe of
penetrating the fog where unknown obstacles might be concealed.
He remembered something of the night-call of the boatmen,
alternating with the splash of their oars, as they approached the
crowded harbour; and he would have liked to hear it again. But
Gertrude was at hand to hearken to and join in his vesper prayer,
and to sing him to sleep with any hymn he chose.
"My pain has not come to-day, nor yesterday, nor the day before,"
said he, as he lay down. "I do not think it will come yet. O, Gertrude,
suppose it should never come any more!"
"And if not," said Gertrude, with a pitying smile, "what then?"
"Why, then I think I should like to live a thousand years, like the
man we were fancying the other day. But, perhaps, I might want next
to be able to walk, and then to have no more coughing (for I am very
tired of coughing sometimes). So I dare say it is best----"
"It is always best to make ourselves as happy as it pleases God to
give us power to be, my dear boy; and I think you do this very well
for a little lad."
As she stooped to kiss his forehead, Christian whispered that she
very often helped to make him happy. "But," said he, "you think my
pain will certainly come again?"
Gertrude could not tell. She recommended thinking as little about it
as possible. If he thought about God, and what the gospel promises,
he would be happy at the time, and best prepared, if his pain should
seize him.
"Whenever I think of Jesus Christ, Gertrude, it makes me long to
have lived when he lived. If he had cured me, as he cured so many, I
would never have denied him, or gone away without thanking him.
Do you really believe anybody ever did that?"
Gertrude was afraid it was too true; but suggested some
palliations; and hinted that there were ways of testifying
faithlessness or discipleship to Jesus even now, when he was
present only in his gospel.
His spirit pillowed upon this truth, Christian fell asleep, and
dreamed that he met Jesus on a shore, which would have been that
of the Zuyder Zee, only that there were mountains; and that Jesus
bade him walk, and that he not only walked, but flew up to the very
top of the highest mountain, where he met Gertrude, and told her
what had happened; and that she sang his favourite hymn; and that,
though they seemed alone, many voices came to sing it with her
from every side.

You might also like