Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Coding Experience Cpp vs Csharp - meetup app os...

Coding Experience Cpp vs Csharp - meetup app osaka@9

2025/3/29 meetup app osaka@9
「C++とC#の書き心地」遥佐保

Akiko Kawai

March 29, 2025
Tweet

More Decks by Akiko Kawai

Other Decks in Programming

Transcript

  1. // print C++23 std::println( "Hello, {} world! ", " C++23

    "); C++ C# printライブラリが やっときた
  2. 三方比較は無い // IcomparableのCompareTo()で実現 // Null合体演算子 var name = txt ??

    “Default”; // Null条件演算子 int? len = dog?.Name?.Length; // Null合体代入演算子 list ??= new List<string>(); // 三方比較演算子での比較 C++23 auto result = a <=> b; // optional C++17 auto name = txt.value_or("Default"); // expected C++23 auto len = dog .and_then([](auto& c){ return c.Name;} ) .and_then([](auto& n){ return std::expected<int, std::error_code>(n.length());}); // optional if ( !list.has_value()){ list = std::vector<std::string>();} C++ C#
  3. // 遅延評価の実体化 // 遅延評価の実体化 // パターンマッチング C++23未採用 auto enhanced =

    [](int x, int y){ return inspect(x) { > 0 if (y > 0) => x + y, _ => 0 };}; C++ C#
  4. C++ C#では public static Complex operator +(Complex a, Complex b)

    => new Complex(a.first + b. first, a.second + b. second); など個別に実装が必要