fork download
  1. #include <cstdlib>
  2. #include <iostream>
  3. #include <string>
  4.  
  5. std::string getCommandLineOption(const std::string& commandLine, const std::string& option)
  6. {
  7. return commandLine + option;
  8. }
  9.  
  10. template<typename F>
  11. auto
  12. getCommandLineOption(const std::string& commandLine, const std::string& option, F f)
  13. -> decltype(f(getCommandLineOption(commandLine, option).c_str()))
  14. {
  15. auto result = getCommandLineOption(commandLine, option);
  16. return result.empty() ? decltype(f(result.c_str())){} : f(result.c_str());
  17. }
  18.  
  19. int main()
  20. {
  21. int serialport = getCommandLineOption("4", "2", atoi);
  22. std::cout << serialport << std::endl;
  23.  
  24. return 0;
  25. }
  26.  
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
42