ข้อเสนอจาก Herb Sutter ประธานคณะกรรมการ ISO C++

ผมอยากเขียนโค้ดด้วย C++ ต่อไป... แค่ให้มัน "ใช้งานได้ดีขึ้น"

เป็นโปรเจกต์ที่สำรวจว่าสามารถทำให้เครื่องมือมีความกระชับและปลอดภัยขึ้นได้หรือไม่ ด้วยไวยากรณ์ (syntax) ใหม่ที่เข้ากันได้กับ C++ เดิมอย่างสมบูรณ์

ทำงานได้บน C++20 ขึ้นไปของคอมไพเลอร์หลัก (MSVC, GCC, Clang)

// Cppfront  
main: () -> int = {  
    vec: std::vector<std::string> = ("hello", "2022");  
    view: std::span = vec;  
  
    for view do :(inout str: _) = {  
        len := decorate(str);  
        println(str, len);  
    }  
}  
  
decorate: (inout thing: _) -> int = { /*...*/ }  
println: (x: _, len: _) = { /*...*/ }  
  
// Cpp  
[[nodiscard]] auto main() -> int{  
    std::vector<std::string> vec {"hello", "2022"};   
    std::span view {vec};   
  
    for ( auto&& cpp2_range = view;  auto& str : cpp2_range ) {  
        auto len {decorate(str)};   
        println(str, len);  
    }  
}  
  
[[nodiscard]] auto decorate(auto& thing) -> int { /*...*/ }  
auto println(auto const& x, auto const& len) -> void { /*...*/ }  

ยังไม่มีความคิดเห็น

ยังไม่มีความคิดเห็น