- MainFunction(F code, std::vector<std::string> args)
- : code_(std::move(code)), args_(std::make_shared<const std::vector<std::string>>(std::move(args)))
- {
- }
- void operator()() const
- {
- const int argc = args_->size();
- std::vector<std::string> args = *args_;
- if (not args.empty()) {
- char noarg[] = {'\0'};
- std::unique_ptr<char* []> argv(new char*[argc + 1]);
- for (int i = 0; i != argc; ++i)
- argv[i] = args[i].empty() ? noarg : &args[i].front();
- argv[argc] = nullptr;
- code_(argc, argv.get());
- } else
- code_(argc, nullptr);
- }
-};
-class MainStdFunction {
-private:
- void (*code_)(std::vector<std::string>);
- std::shared_ptr<const std::vector<std::string>> args_;
-
-public:
- MainStdFunction(void (*code)(std::vector<std::string>), std::vector<std::string> args)