20. 著者はBjarne Stroustrup氏とHerb Sutter氏
C++ Core Guidelinesって?
「The C++ Core Guidelines are a set of tried-and-true
guidelines, rules, and best practices about coding in C++」
「C++コーディングにおける実証済みのガイドラインと
ルール、そしてベストプラクティスの集合体である」
21. Q. C++ Core Guidelinesは
"More" Effective Modern C++か?
98. 悪い例
class Date { // Bad: 似たコードの繰り返しがある。
int d;
Month m;
int y;
public:
Date(int ii, Month mm, year yy)
:i{ii}, m{mm} y{yy}
{ if (!valid(i, m, y)) throw Bad_date{}; }
Date(int ii, Month mm)
:i{ii}, m{mm} y{current_year()}
{ if (!valid(i, m, y)) throw Bad_date{}; }
// ...
};
99. 良い例
class Date2 {
int d;
Month m;
int y;
public:
Date2(int ii, Month mm, year yy)
:i{ii}, m{mm} y{yy}
{ if (!valid(i, m, y)) throw Bad_date{}; }
// 他のコンストラクタを呼び出す。
Date2(int ii, Month mm)
:Date2{ii, mm, current_year()} {}
// ...
};