Learn C++ by Example: Covers Versions 11 to 23 (Final Release) 1 / converted Edition Frances Buontempo download
Learn C++ by Example: Covers Versions 11 to 23 (Final Release) 1 / converted Edition Frances Buontempo download
https://textbookfull.com/product/learn-c-by-example-covers-
versions-11-to-23-final-release-1-converted-edition-frances-
buontempo/
https://textbookfull.com/product/primary-mathematics-
textbook-2b-jennifer-hoerst/
https://textbookfull.com/product/handbook-of-macroeconomics-
volume-2a-2b-set-1st-edition-john-b-taylor/
https://textbookfull.com/product/deep-dive-into-power-automate-
learn-by-example-1st-edition-mishra/
https://textbookfull.com/product/blender-3d-printing-by-example-
learn-to-use-blender-s-modeling-tools-for-3d-printing-by-
creating-4-projects-1st-edition-vicky-somma/
Genetic Algorithms and Machine Learning for Programmers
Create AI Models and Evolve Solutions 1st Edition
Frances Buontempo
https://textbookfull.com/product/genetic-algorithms-and-machine-
learning-for-programmers-create-ai-models-and-evolve-
solutions-1st-edition-frances-buontempo/
https://textbookfull.com/product/ansi-c-programming-learn-ansi-c-
step-by-step-1st-edition-yashavant-kanetkar/
https://textbookfull.com/product/unity-2018-by-example-learn-
about-game-and-virtual-reality-development-by-creating-five-
engaging-projects-second-edition-alan-thorn/
https://textbookfull.com/product/javafx-9-by-example-dea/
https://textbookfull.com/product/blazor-webassembly-by-example-
second-edition/
inside front cover
This book uses std::cin, std::cout, std::vector, and
std::string in many places. These should be old, familiar C++
features. By counting other features from the standard namespace in
the code with this book, we can form a word cloud. The larger the
word, the more often we use it. See if you recognize any, and look
back when you have finished the book to remind yourself what you
have learned.
Learn C++ by Example
COVERS VERSIONS 11 TO 23
Frances Buontempo
To comment go to liveBook
Manning
Shelter Island
For more information on this and other Manning titles go to
www.manning.com
Copyright
ISBN: 9781633438330
dedication
To my husband, Steve Love, for supporting me and chatting about possible
examples and approaches used in this book when he wasn’t busy writing his
own.
contents
Front matter
foreword
preface
acknowledgments
about this book
about the author
about the cover illustration
1 Hello again, C++!
1.1 Why does C++ matter?
1.2 When should you use C++?
1.3 Why read this book?
1.4 How does this book teach C++?
Who this book is for
Hello, again, C++!
What you’ll learn from reading this book
8.3 Coroutines
How to make a coroutine
A coroutine function
The coroutine’s return object
RAII and the rule of zero
Filling in the promise_type
Filling in the Task type
A coroutine mind reader
foreword
C++ is an ever-improving language used in almost every
corner of computing, from embedded systems, operating
systems, browsers, games, and trading systems to the ebook
reader you may be using to read this book. A new C++
standard comes out every three years, and compiler vendors
are quick to pick up on the latest features. I’ve been writing
C++ professionally for over 20 years in the seemingly
disparate games and finance industries. I have mostly
worried about the performance of my code, which led to me
creating Compiler Explorer, and not about every little change
to the language.
—Matt Godbolt
preface
I first encountered C++ when asked to write a C++ parser to
emulate code for an embedded device on a PC back in the
1990s. I only knew C at the time, so this was a baptism by
fire. The C++ was predominantly C with classes, like many
early versions of C++ were. Over time, I learned more and
fell in love with the language. As a long-standing member of
ACCU (https://accu.org/), I volunteered to become editor of
its Overload magazine, which means I have to write an
editorial every other month, as well as encourage people to
write and collate feedback from the review team. Overload
has a mix of articles from newcomers and seasoned
professionals, covering C++ in depth, as well as broader
programming topics, so as the editor, I need to try to keep
up to date with everything. This is a challenge, and I still
have lots to learn.
I have used C++ for personal projects, and you can find
many of my talks on YouTube. I have also used C++
professionally, predominantly in investment banks and other
financial institutions. I know other languages too, and often
act as an intermediary between the quant teams writing C++
libraries and the frontend teams using them. I do understand
a lot of the under-the-hood mathematics that rocket
scientists use in their coding. To be honest, I’ve only worked
with two rocket scientists, but you can do clever things with
C++. The important part is understanding what you are
doing and knowing how to test your code.
acknowledgments
This book has been fun and challenging to write. I’ve learned
loads as I’ve tried to explain various aspects of C++. I
frequently asked others for help or ideas, while aiming to find
simple but correct ways to describe the language. Thanks to
everyone who argued with me to ensure I was correct.
Start by reading the first chapter, and then get your chosen
compiler ready. You can read the chapters in any order;
however, they build on each other to some extent, even
though each creates a self-contained project. When a feature
is used again, the first mention is signposted, so you can skip
back if you need to. Reading the chapters in order might be
easier, though, as you gradually add new approaches to your
repertoire. However you decide to read this book, do stop
and try out some code. Then play the games you created, or
play with the projects. Keep your brain in gear, ask
questions, experiment, and above all, have fun!
This book has code in all nine chapters. The code is all in the
book but can be cloned from
https://github.com/doctorlove/BootstrapCpp.git. The first
chapter is a short main function used to discuss modern
approaches in C++, while the fun and games start from
chapter 2. You will need a compiler, and
https://isocpp.org/get-started provides links to several good
free ones. Some features, such as std::format, are not
supported on all compilers, but the book calls this out, and
the source code has comments showing what to do instead.
Other resources
Each chapter mentions further resources, and these are
collated into an appendix at the end of this book, so you can
easily look back without having to keep notes.
about the author
Frances Buontempo has many years of C++ experience. She
has worked as a programmer at various companies, mostly in
London, with a focus on finance. She enjoys testing and
deleting code and tries to keep on learning. She has given
talks on C++ and more, which you can find on YouTube. She
is the editor of ACCU’s Overload magazine and will happily
consider articles from readers who want to share what they
learned from this book.
IV. TIBET.
The year 1885 witnessed the first act in the ill-advised policy—as to
its method, not its object—of the Indian Government of opening
commercial relations with Tibet. A learned Bengali pandit, versed in
Tibetan, had made two successful visits to Lhassa, where he gained
the friendship of the lamas, who invited him to come again. A fair
prospect of opening commercial relations by gradually disarming
prejudices and apprehension was thus presented. Having duly
reported his experiences to the Government of India, the babu
waited their pleasure as to further developments at Darjeeling,
where he occupied the post of Government schoolmaster. An English
civilian, making the acquaintance of the babu in that hot-weather
retreat, conceived the idea of an official mission to Lhassa, in which
the services of the babu might be utilised as guide and interpreter.
The Indian Government was averse from the enterprise on
economical if on no other grounds, but direct pressure being brought
to bear on the India Office in London, the ambitious young
statesman who then presided over its counsels is said to have
espoused the proposal and overruled the reluctant Government of
India.
Of the organisation and procedure of the mission nothing very
complimentary can be said. Instead of following the line of least
resistance, of driving in the thin end of the wedge, in accordance
with the commonplace maxims consecrated by all human
experience, the reverse process was followed in every single
particular. Sarat Chandra Das had shown the way, and the entry he
had effected could have been gradually widened by himself and
others of his own class until the obstacles to free commercial
intercourse had been overcome. The experience of a hundred years
had shown to the world the invincible prejudices of the Tibetan
rulers against foreign visitors. The babu had in his own person
conquered these prejudices by his mastery of Buddhistic lore, as well
as by his gentleness and consummate tact; but the mission, which
had its origin in the information he supplied, discarded his methods
and proceeded on military lines. Its personnel included politicals and
scientists, but no commercial agent, and as Mr Gundry has well said,
"The Under Secretary of State, while stating that the object of the
mission was to confer with the Chinese commissioners and the
Lhassa Government as to the resumption of commercial relations
between India and Tibet," added in Parliament that, "looking to the
delicate nature of the mission, it had not been thought advisable to
appoint a special commercial representative." An armed force of
some 300 men sent on a "delicate mission" which, though essentially
commercial, yet had nothing commercial in its composition! Could
anything be conceived more certain to arouse the sleeping
suspicions of the Tibetans? It was but repeating on a larger scale the
deplorable fiasco of Colonel Browne's attempted march from Burma
to China in 1875.
The first act in this little drama was performed in Peking when the
envoy, Macaulay, arrived with his staff for the ostensible purpose of
applying for a passport for Tibet. For such a purpose there was no
need to have sent a special messenger to Peking at all, as a passport
could have been much more easily obtained by the British Minister
there and transmitted by post in the ordinary course of business.
The passport could not, of course, be refused in plain terms by the
Chinese Government, but the personal demand for it gave them the
opportunity of cross-examining the intended envoy as to the objects
of his proposed mission. It may well be believed, from the self-
contradictory explanation of the mission tendered to the British
Parliament, that the envoy in Peking failed to allay the suspicions of
the Chinese Government. On the contrary, his presence intensified
them exceedingly. The sole effect of the preliminary expedition to
Peking was, in fact, to forewarn the Chinese Government, so that
they, in concert with the rulers of Tibet, should be prepared to
interpose obstacles to the advance of the mission, but in such a way
as not openly to compromise the good faith of the Chinese
Government. The journey of the envoy to Peking, therefore, sealed
the fate of his own mission, and at the same time closed Tibet
against more judicious advances in the future.
The most interesting episode in connection with this abortive effort
was the appearance of the Babu Sarat Chandra Das himself in the
Chinese capital. By sheer force of intellect he succeeded in a few
days in obtaining the confidence of the inner circle of the lamas
there. Having been brought in contact with a certain Manchu official,
the pandit showed very unobtrusively a familiarity with the more
recondite tenets of Buddhism which captivated the Manchu, whose
heart was set on improving his knowledge of the sacred mysteries.
[24] The babu could speak no Chinese, but it was not difficult among
the thousands of lamas in Peking to find a competent Tibetan
interpreter. The fame of the pandit spread rapidly among the ranks
of the priesthood, whose chiefs competed for the honour of sitting at
the feet of the Indian Gamaliel. In expounding the doctrines, while
enjoying the hospitality, of different groups of lamas, the popularity
of the pandit grew from day to day, until he was at length
constrained to take up his quarters at the great Yellow Temple,
outside the north wall of Peking, and live with the brethren. They
invested him with the yellow robe and the other ecclesiastical
insignia, and treated him altogether as one of the initiated. It
required all his acumen to prevent his status as a Buddhist lama
from clashing with his position as a subordinate of the Indian envoy,
on whom he was in attendance. He had to pay frequent visits to the
British Legation, where it would have been impossible for him to
appear in his religious vestments without exciting inconvenient
gossip, and perhaps incurring the disapproval of his superior officer.
The custom of travelling in Peking in closed carts enabled the babu
to play the double part of Jekyll and Hyde with perfect success. He
would leave the Temple as a lama, drive to a friend's rooms in the
city, where his Indian costume was kept ready, in which he
proceeded in another cab and in another character to the British
Legation, returning to reassume his yellow robes and then repair to
the Temple.
During the time when the envoy designate remained in Peking a
very high personage arrived from Tibet, and it was on his
conferences with the Chinese Court that the success of the intended
mission depended. It would be presumptuous on the part of any
foreigner to attempt to divine what passed between the delegate
from the Grand Lama and the Chinese Ministers; but were it possible
for any one to penetrate into those secret counsels, the babu was
the man to do it. There is no doubt that he did. In fact, he had
positive information that the Indian mission to Tibet would be
stopped at the instance of the Chinese Government, and that the
issue of the passport was an empty form. Such information would
naturally be unwelcome to the envoy, and the sequel seems to show
that the warning was disregarded. The expedition was organised,
fully equipped, ready for a march into Tibet. Had it proceeded it is
highly improbable that the babu would have accompanied it as
interpreter, for he could not have exonerated himself from the
imputation of bad faith towards his Tibetan hosts in acting as guide
to an armed force into a country where he had been received and
reinvited as a private guest.
What would have been the consequence of the mission proceeding
into Tibet it is, of course, impossible to say, but the circumstances of
its recall were not conducive to satisfactory relations between China
and Great Britain. Mistrusting the effectiveness of the Tibetan
opposition to the Indian mission—for the force could very likely have
made good its passage to Lhassa—the Chinese Government resorted
to diplomatic means of stopping its advance. Its never-failing
emergency man, the Inspector-General of Customs, was called
upon, and he intervened with the British Government with such good
effect that they sent orders to India to stop the Tibetan mission.
Thus the Indian Government was a second time overruled: first, in
being made to organise the mission against its will; and secondly, in
being forced to recall it when its recall involved immeasurable loss of
influence in future dealings with China. An attempt was made to
cover the retreat in a cloud of verbiage by a convention signed at
Peking in 1886, which, however, only made the case worse, in that it
was a retrograde step, virtually cancelling the right of visiting Tibet,
which had been conferred by the Chefoo convention of ten years
before. The same treaty which embodied this renunciation, perhaps
the weakest to which any British representative ever set his name,
also fostered the illusions which have been so detrimental to the
welfare of China, by promising a continuance of the tribute missions
from Burma after that country had become an integral part of the
Indian Empire.
The fruits of this diplomatic surrender were not long in showing
themselves, for it was soon followed by an invasion of British Sikkim
from the Tibetan side. This aggression of the lamas was of necessity
resisted by the Indian Government, and an unexpected opportunity
was thus offered to them of settling the whole Tibetan question by
the rapid march of a small force to Lhassa. There is good reason to
believe that this solution of the difficulty was the one which
commended itself to the practical statesmen and soldiers of India;
but their action was paralysed by the orders of the Home
Government, which continued to be ruled by influences which were
neither military nor political nor practical. Discussions between the
Indian Government and the Chinese amban or Resident at Lhassa,
professing to speak for the Tibetan Lama Government, were
protracted year after year, and seemed interminable. At last even the
Chinese themselves grew weary of the comedy, and experienced in
Tibet something of the difficulty which occasionally beset them in
China—that is to say, they were unable to exorcise the demon they
had invoked. They had stirred up the Tibetans to the point of
obstructing the Macaulay mission, but seemed really to lose control
of the force after it had been set in motion. After some years of
futile talk the statesmen of China would perhaps have hailed with
satisfaction the advance of a British force to Lhassa to cut the
Gordian knot; but they dared not, of course, give such a hint as was
conveyed to Captain Fournier, "Avancez donc,"[25] and the Indian
Government, not having the wit to divine it, had to submit to a long-
drawn-out and permanent humiliation, that was in no wise mended
by the Calcutta convention of 1890, which, professing only to settle
the existing frontiers, did not even settle them.
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
textbookfull.com