autoは変数に対してテンプレートに類似した型推論を使用します。通常のautoは、宣言時にauto&、const auto&、auto&&のように明示的に指定しない限り、通常は参照や最上位のconstを脱落(drop)させます。decltype(expr)は宣言された型や式の型をより厳密に取得します。括弧なしの識別子式は宣言された型を返し、それ以外のlvalue式はT&、xvalueはT&&、prvalueはTを生成します。decltype(auto)はdecltypeの規則に沿って推論し、参照を保持する必要がある戻り値の型などでよく利用されます。テンプレート引数推論はautoと類似していますが、T、T&、const T&、T&&などの仮引数の形式に依存し、独自の規則を持ちます。波括弧による初期化子はよく見られる違いの一つであり、auto x = {1, 2}はstd::initializer_list<int>と推論されますが、通常のテンプレート仮引数では、仮引数がinitializer_listやその他の適切な型を期待していない限り、単独の波括弧初期化子からTを推論することは一般にできません。
int x = 1;
const int cx = 2;
int& rx = x;
auto a = rx; // int, copy of x
auto b = cx; // int, top-level const dropped
const auto& c = cx; // const int&, reference preserved by declaration
a = 10; // does not change x
9Rule of Zero、Rule of Three、Rule of Five の内容と、それぞれがどのような場合に適用されるかを説明してください。
Rule of Zero: カスタムのデストラクタ、コピー操作、ムーブ操作を宣言しないクラスを優先し、`std::string`、`std::vector`、`std::unique_ptr`、ファイル/ソケットのラッパーなどの RAII (Resource Acquisition Is Initialization) メンバーにリソース管理を委ねます。Rule of Three: クラスがリソースを手動で管理し、カスタムのデストラクタ、コピーコンストラクタ、またはコピー代入演算子を必要とする場合、適切なコピーと所有権の振る舞いを定義するために通常これら3つすべてを定義する必要があります。Rule of Five: C++11 以降では、そのような型はムーブコンストラクタとムーブ代入演算子の定義も検討すべきです。ほとんどのアプリケーションの型には Rule of Zero を適用します。型がリソースを直接所有している場合や、自明でない所有権や寿命のセマンティクスを持つ場合には Rule of Three または Rule of Five を適用します。
#include <iostream>
struct S {
int x;
};
int main() {
int a; // default-initialized: indeterminate value
int b{}; // value/list-initialized: zero
S s{}; // aggregate/value initialization: s.x is zero
std::cout << b << ' ' << s.x << '\n';
(void)a; // reading a would be undefined behavior
}
1. Expand: add new nullable column user_display_name.
2. Deploy compatible code: write both name and user_display_name; read new if present, else old.
3. Backfill: copy name -> user_display_name in small batches.
4. Validate: compare counts/checksums/null rates and monitor errors.
5. Switch: read only user_display_name after confidence.
6. Contract: stop writing old name, then drop old column in a later release.
ReadPolicy EVENTUAL(max_staleness=2s):
choose healthy replica with lag <= 2s; else primary or error depending on SLA
ReadPolicy READ_YOUR_WRITES(session_lsn):
choose replica only if replay_lsn >= session_lsn;
otherwise wait briefly or route to primary
ReadPolicy STRONG:
route to primary