Created
April 8, 2018 02:16
-
-
Save DataKinds/0f426b6e3a4294c9fd0a39c2e062dda9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template<std::vector<std::string>* arg, std::string_view* flag, std::function<void()>* f> | |
struct CommandLineLambda { | |
//returns whether or not the argument was called | |
static inline bool runArg() { | |
auto iter = std::find(arg->begin(), arg->end(), *flag); | |
if (iter != arg->end()) { | |
(*f)(); | |
return true; | |
} | |
return false; | |
} | |
}; | |
template<std::vector<std::string>* arg, std::string_view* flag, std::optional<std::string>* var> | |
struct CommandLineOptional { | |
//returns the success of parsing the argument | |
static inline bool runArg() { | |
auto iter = std::find(arg->begin(), arg->end(), *flag); | |
if (iter != arg->end()) { | |
if ( | |
iter == std::prev(arg->end()) || | |
std::next(iter)->front() == '-' | |
) { | |
printf("No argument supplied to %s\n", "-a"); | |
return false; | |
} else { | |
(*var) = *(std::next(iter)); | |
} | |
} | |
return true; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment