Hacker News new | ask | show | jobs
by ddalcino 2656 days ago
Until C++2z rolls out with match support, you can roll your own. Nikolai Wuttke gave a lecture at MeetingCpp 2018 (https://www.youtube.com/watch?v=CELWr9roNno) that presents code that lets you do this:

    // Client visitor code
    match(
      thingy,
      [](const PurpleThingy& ) {std::cout << "purple thingy\n";},
      [](const LittleThingy& ) {std::cout << "little thingy\n";},
      [](const auto& ) {std::cout << "any other type\n";}
    );

Working example: https://coliru.stacked-crooked.com/a/dfed39bc7fcdfb01