Move Semantics & Rule of Zero ကိုsyntax ထက် object lifetime, ownership, borrowing, invalidation နဲ့exception safety contract အဖြစ်နားလည်ပါ။ Resource ကိုraw new/delete ဖြင့်မပိုင်ဆိုင်ဘဲRAII value types နဲ့smart pointers သုံးပြီးdangling access နဲ့double release ကိုdesign အဆင့်ကကာကွယ်ပါ။
ပိုပြီးနားလည်ထားရမယ့် အချက်
Move Semantics & Rule of Zero ကိုsyntax ထက် object lifetime, ownership, borrowing, invalidation နဲ့exception safety contract အဖြစ်နားလည်ပါ။ Resource ကိုraw new/delete ဖြင့်မပိုင်ဆိုင်ဘဲRAII value types နဲ့smart pointers သုံးပြီးdangling access နဲ့double release ကိုdesign အဆင့်ကကာကွယ်ပါ။
လက်တွေ့မှာ ဘယ်လိုအသုံးချမလဲ
Move Semantics & Rule of Zero example ကိုempty, boundary, invalid နဲ့failure cases ဖြင့်စမ်းပြီး `-std=c++23 -Wall -Wextra -Wpedantic` နဲ့build ပါ။ Lifetime-sensitive code ကိုAddressSanitizer/UndefinedBehaviorSanitizer ဖြင့်ထပ်စစ်ပါ။
ဒီသင်ခန်းစာပြီးရင်
#include <iostream>
#include <string>
#include <utility>
int main() {
std::string source = "C++";
std::string target = std::move(source);
std::cout << target << '\n';
}C++ကိုယ်တိုင်စမ်းကြည့်ရန်
Move Semantics & Rule of Zero example ကိုempty, boundary, invalid နဲ့failure cases ဖြင့်စမ်းပြီး `-std=c++23 -Wall -Wextra -Wpedantic` နဲ့build ပါ။ Lifetime-sensitive code ကိုAddressSanitizer/UndefinedBehaviorSanitizer ဖြင့်ထပ်စစ်ပါ။
Memory/Safety သတိပေးချက်
Output တစ်ကြိမ်မှန်ရုံဖြင့် lifetime, bounds, ownership နဲ့undefined behavior အားလုံးမှန်ပြီဟုယူဆခြင်း။
C++ Core Guidelines — Standard C++ Foundation