#include <cstdlib>
#include <iostream>
#include <string>
std::string getCommandLineOption(const std::string& commandLine, const std::string& option)
{
return commandLine + option;
}
template<typename F>
auto
getCommandLineOption(const std::string& commandLine, const std::string& option, F f)
-> decltype(f(getCommandLineOption(commandLine, option).c_str()))
{
auto result = getCommandLineOption(commandLine, option);
return result.empty() ? decltype(f(result.c_str())){} : f(result.c_str());
}
int main()
{
int serialport = getCommandLineOption("4", "2", atoi);
std::cout << serialport << std::endl;
return 0;
}
I2luY2x1ZGUgPGNzdGRsaWI+CiNpbmNsdWRlIDxpb3N0cmVhbT4KI2luY2x1ZGUgPHN0cmluZz4KCnN0ZDo6c3RyaW5nIGdldENvbW1hbmRMaW5lT3B0aW9uKGNvbnN0IHN0ZDo6c3RyaW5nJiBjb21tYW5kTGluZSwgY29uc3Qgc3RkOjpzdHJpbmcmIG9wdGlvbikKewogICAgcmV0dXJuIGNvbW1hbmRMaW5lICsgb3B0aW9uOwp9Cgp0ZW1wbGF0ZTx0eXBlbmFtZSBGPgphdXRvCmdldENvbW1hbmRMaW5lT3B0aW9uKGNvbnN0IHN0ZDo6c3RyaW5nJiBjb21tYW5kTGluZSwgY29uc3Qgc3RkOjpzdHJpbmcmIG9wdGlvbiwgRiBmKQotPiBkZWNsdHlwZShmKGdldENvbW1hbmRMaW5lT3B0aW9uKGNvbW1hbmRMaW5lLCBvcHRpb24pLmNfc3RyKCkpKQp7CiAgICBhdXRvIHJlc3VsdCA9IGdldENvbW1hbmRMaW5lT3B0aW9uKGNvbW1hbmRMaW5lLCBvcHRpb24pOwogICAgcmV0dXJuIHJlc3VsdC5lbXB0eSgpID8gZGVjbHR5cGUoZihyZXN1bHQuY19zdHIoKSkpe30gOiBmKHJlc3VsdC5jX3N0cigpKTsKfQoKaW50IG1haW4oKQp7CiAgICBpbnQgc2VyaWFscG9ydCA9IGdldENvbW1hbmRMaW5lT3B0aW9uKCI0IiwgIjIiLCBhdG9pKTsKICAgIHN0ZDo6Y291dCA8PCBzZXJpYWxwb3J0IDw8IHN0ZDo6ZW5kbDsKCiAgICByZXR1cm4gMDsKfQo=