7 ポイント 投稿者 opal58 2023-03-05 | まだコメントはありません。 | WhatsAppで共有

ISO C++委員会の議長である Herb Sutter による提案

I want to keep writing code in C++... just "nicer"

既存の C++ と完全に互換性のある新しい構文(syntax)で、より簡潔かつ安全にツール化できるかを探るプロジェクト

主要コンパイラ(MSVC、GCC、Clang)の C++20 以上で動作

// 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 { /*...*/ }  

まだコメントはありません。

まだコメントはありません。