forked from ifsmirnov/jngen
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Very basic getopt. Fixed random graphs generation.
- Loading branch information
Showing
2 changed files
with
91 additions
and
18 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#pragma once | ||
|
||
#include "common.h" | ||
|
||
#include <bits/stdc++.h> | ||
|
||
namespace impl { | ||
|
||
namespace detail { | ||
|
||
template<typename T> | ||
void readVariable(T& var, const std::string& value) { | ||
std::istringstream ss(value); | ||
ss >> var; | ||
|
||
ensure(ss, "Failed to parse a value from a command line argument"); | ||
} | ||
|
||
typedef std::vector<std::string>::const_iterator OptionIterator; | ||
|
||
void getopts(OptionIterator) | ||
{ } | ||
|
||
template<typename T, typename ... Args> | ||
void getopts(OptionIterator iter, T& var, Args& ...args) { | ||
readVariable(var, *iter); | ||
getopts(++iter, args...); | ||
} | ||
|
||
} // namespace detail | ||
|
||
template<typename ... Args> | ||
void getopts(const std::vector<std::string>& options, Args& ...args) { | ||
ensure(options.size() >= sizeof...(args), "Too few command-line arguments"); | ||
detail::getopts(options.cbegin(), args...); | ||
} | ||
|
||
template<typename ... Args> | ||
void getopts(int argc, char *argv[], Args& ...args) { | ||
return getopts(std::vector<std::string>(argv + 1, argv + argc), args...); | ||
} | ||
|
||
} // namespace impl | ||
|
||
using impl::getopts; |