Thuta Learning
C++
AdvancedProgrammingbeginner

Algorithms, Ranges & Lambdas

ဒီခန်းပြီးရင် ဘာတတ်သွားမလဲ

  • Algorithms, Ranges & Lambdas ရဲ့type, lifetime နဲ့runtime behavior ကိုရှင်းပြနိုင်ရန်
  • Warnings နဲ့sanitizers သုံးပြီးfailure cases စမ်းနိုင်ရန်
  • Modern, safe C++ code ရေးနိုင်ရန်

Algorithms, Ranges & Lambdas မှာcontainer ownership, iterator/range validity, algorithm preconditions နဲ့complexity ကိုတစ်ပြိုင်နက်စဉ်းစားပါ။ Hand-written loops များအစားstandard algorithms/ranges သုံးပြီးmutation နဲ့allocation policy ကိုရှင်းလင်းပါ။

ပိုပြီးနားလည်ထားရမယ့် အချက်

Algorithms, Ranges & Lambdas မှာcontainer ownership, iterator/range validity, algorithm preconditions နဲ့complexity ကိုတစ်ပြိုင်နက်စဉ်းစားပါ။ Hand-written loops များအစားstandard algorithms/ranges သုံးပြီးmutation နဲ့allocation policy ကိုရှင်းလင်းပါ။

လက်တွေ့မှာ ဘယ်လိုအသုံးချမလဲ

Algorithms, Ranges & Lambdas example ကိုempty, boundary, invalid နဲ့failure cases ဖြင့်စမ်းပြီး `-std=c++23 -Wall -Wextra -Wpedantic` နဲ့build ပါ။ Lifetime-sensitive code ကိုAddressSanitizer/UndefinedBehaviorSanitizer ဖြင့်ထပ်စစ်ပါ။

ဒီသင်ခန်းစာပြီးရင်

cpp
#include <algorithm>
#include <iostream>
#include <vector>

int main() {
    std::vector values{5, 2, 8, 1};
    std::ranges::sort(values);
    for (int value : values) std::cout << value << ' ';
}
You should see
1 2 5 8

ကိုယ်တိုင်စမ်းကြည့်ရန်

Algorithms, Ranges & Lambdas 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 အားလုံးမှန်ပြီဟုယူဆခြင်း။

The Current ISO C++ Standard (C++23)Standard C++ Foundation

ဒီနေရာမှာ လူအများမှားတတ်တယ်

  • Output တစ်ကြိမ်မှန်ရုံဖြင့် lifetime, bounds, ownership နဲ့undefined behavior အားလုံးမှန်ပြီဟုယူဆခြင်း။
  • Raw pointer သို့iterator တစ်ခုကိုowner container/resource ပြောင်းပြီးနောက်လည်းvalid ဖြစ်နေမယ်ဟုယူဆခြင်း။

လက်တွေ့လေ့ကျင့်ခန်း

Algorithms, Ranges & Lambdas example ကိုempty, boundary, invalid နဲ့failure cases ဖြင့်စမ်းပြီး `-std=c++23 -Wall -Wextra -Wpedantic` နဲ့build ပါ။ Lifetime-sensitive code ကိုAddressSanitizer/UndefinedBehaviorSanitizer ဖြင့်ထပ်စစ်ပါ။

You'll know it worked when: 1 2 5 8