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項目
項目 3decltype を理解する
17
resetV({ 1, 2, 3 }); // error! can't deduce type
// for { 1, 2, 3 }
エラー! { 1, 2, 3 } の型を推論できない
重要ポイント
auto の型推論は通常はテンプレートのそれと同様だが、auto では波括弧で囲んだ初期化子
std::initializer_list と想定する点が異なる。
関数の戻り型やラムダ式の仮引数での auto はテンプレートの型推論と同じ動作となり、auto
の型推論とは異なる。
項目 3decltype を理解する
decltype はまったくおかしな代物です。名前や式を与えるとその型を教えてくれます。通常は
予想通りの型を教えてくれますが、頭をかきむしったり、確認のために仕様やオンライン上の Q&A
サイトを探しまくらなければならないような結果を返すこともあります。
まずは一般的な例から始めましょう。すんなり受け入れられるありふれた例です。テンプレート、
auto の型推論の動作とは対照的に(項目 1 および項目 2 を参照)、decltype は、通常は、与えられ
た名前や式の正確な型をそのまま返します。
const int i = 0; // decltype(i) is const int
decltype(i) const int
bool f(const Widget& w); // decltype(w) is const Widget& ...
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