Expanding the title: my goal (for hobby project) was to create simple, generic (customizable) and cross-platform menu class for console applications (mostly simple, text-based games). That's what I came up with:#include <functional>#include <iostream>#include <map>#include <string>class ConsoleMenu {  public:    ConsoleMenu(const std::string& message,        const std::string& invalidChoiceMessage,        const std::string& prompt,        const std::map<std::string, std::function<void()>>& commandsByChoice) :            message_(message), invalidChoiceMessage_(invalidChoiceMessage),            prompt_(prompt), commandsByChoice_(commandsByChoice) {}    void use() {      std::string userChoice;      std::cout << '\n';      // Based on https://isocpp.org/wiki/faq/input-output#istream-and-ignore {      while ((std::cout << message_) && printChoices() &&          (std::cout << prompt_) && (!(std::getline(std::cin, userChoice)) ||          !validChoice(userChoice))) {        std::cout << '\n' << invalidChoiceMessage_;        // Should there be calls to std::cin::clear and std::cin::ignore, even        // if I'm using std::getline?      }      // }      commandsByChoice_[userChoice]();    }  private:    bool printChoices() {      bool successful = false;      for (auto commandByChoice : commandsByChoice_) {        successful = static_cast<bool>(            std::cout << '[' << commandByChoice.first << ']' << '\n');      }      return successful;    }    bool validChoice(const std::string& choice) {      return commandsByChoice_.find(choice) != commandsByChoice_.end();    }    std::string message_; // label_?    std::string invalidChoiceMessage_;    std::string prompt_;    std::map<std::string, std::function<void()>> commandsByChoice_;};int main() {  bool running = true;  do {    ConsoleMenu menu(What should this program do?\n, Invalid operation; , > , {      {run, [&running] {        running = true;      }},      {stop, [&running] {        running = false;      }}    });    menu.use();  } while (running);}As you can see, while the general look of the menu is hard-coded, user can (and have to) specify the message (label) of the menu, list of choices, commands that are keyed to these choices, and even error message, and input prompt. Generic? Check!If someone would like to suggest improvement requiring C++17, please, include also some non-standard equivalent(s) with similar interface, for example from The Boost library.
Generic menu class for console applications
c++;object oriented;c++11;console;c++14