Skip to Content
Effective Modern C++ ―C++11/14プログラムを進化させる42項目
book

Effective Modern C++ ―C++11/14プログラムを進化させる42項目

by Scott Meyers, 千住 治郎
September 2015
Intermediate to advanced
364 pages
10h 33m
Japanese
O'Reilly Japan, Inc.
Content preview from Effective Modern C++ ―C++11/14プログラムを進化させる42項目
項目 42:要素の挿入の代わりに直接配置を検討する
309
重複が理由でコンテナが新規の値を拒否することがまずない
コンテナが重複を認める場合か、または追加する要素がほぼすべてで一意となる場合である。
この場合、直接配置関数は一般に値がすでにコンテナ内に存在するかを判断するため、コン
テナ内の要素と比較用に新規の値を持つノードを作成する動作が重要となる。追加する値が
コンテナ内に存在していなければ、ノードは期待通り追加されるが、すでにコンテナ内に存
在する場合は、エラーとなりノードを破棄する。このノード作成/破棄のコストが無駄にな
る。直接配置関数の場合は挿入関数の場合よりもこの無駄、ノード作成/破棄の回数が多い。
本項目で先に挙げた例を再度示しますが、これらはいずれも上記の条件を満たしており、同等機
能の push_back よりも高速に動作します。
vs.emplace_back("xyzzy"); // construct new value at end of
// container; don't pass the type in
// container; don't use container
// rejecting duplicates
コンテナ末尾に新規の値をコンストラクトする。
コンテナ要素の型は渡さない。
重複を認めないコンテナは使用しない。
vs.emplace_back(50, 'x'); // ditto 同上
直接配置関数を用いるか否かを判断する際に覚えておくと良い点があと
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

C++ High Performance - Second Edition

C++ High Performance - Second Edition

Björn Andrist, Viktor Sehr

Publisher Resources

ISBN: 9784873117362Other