Fix passing a const array to parse (#258)
Fixes #257. The input array is not modified, so we can declare this as `char const* const*`.
This commit is contained in:
parent
4b63c333a8
commit
3ef9fddc7b
@ -1325,7 +1325,7 @@ namespace cxxopts
|
|||||||
}
|
}
|
||||||
|
|
||||||
ParseResult
|
ParseResult
|
||||||
parse(int argc, const char** argv);
|
parse(int argc, const char* const* argv);
|
||||||
|
|
||||||
bool
|
bool
|
||||||
consume_positional(const std::string& a, PositionalListIterator& next);
|
consume_positional(const std::string& a, PositionalListIterator& next);
|
||||||
@ -1334,7 +1334,7 @@ namespace cxxopts
|
|||||||
checked_parse_arg
|
checked_parse_arg
|
||||||
(
|
(
|
||||||
int argc,
|
int argc,
|
||||||
const char* argv[],
|
const char* const* argv,
|
||||||
int& current,
|
int& current,
|
||||||
const std::shared_ptr<OptionDetails>& value,
|
const std::shared_ptr<OptionDetails>& value,
|
||||||
const std::string& name
|
const std::string& name
|
||||||
@ -1412,7 +1412,7 @@ namespace cxxopts
|
|||||||
}
|
}
|
||||||
|
|
||||||
ParseResult
|
ParseResult
|
||||||
parse(int argc, const char** argv);
|
parse(int argc, const char* const* argv);
|
||||||
|
|
||||||
OptionAdder
|
OptionAdder
|
||||||
add_options(std::string group = "");
|
add_options(std::string group = "");
|
||||||
@ -1772,7 +1772,7 @@ void
|
|||||||
OptionParser::checked_parse_arg
|
OptionParser::checked_parse_arg
|
||||||
(
|
(
|
||||||
int argc,
|
int argc,
|
||||||
const char* argv[],
|
const char* const* argv,
|
||||||
int& current,
|
int& current,
|
||||||
const std::shared_ptr<OptionDetails>& value,
|
const std::shared_ptr<OptionDetails>& value,
|
||||||
const std::string& name
|
const std::string& name
|
||||||
@ -1865,7 +1865,7 @@ Options::parse_positional(std::initializer_list<std::string> options)
|
|||||||
|
|
||||||
inline
|
inline
|
||||||
ParseResult
|
ParseResult
|
||||||
Options::parse(int argc, const char** argv)
|
Options::parse(int argc, const char* const* argv)
|
||||||
{
|
{
|
||||||
OptionParser parser(*m_options, m_positional, m_allow_unrecognised);
|
OptionParser parser(*m_options, m_positional, m_allow_unrecognised);
|
||||||
|
|
||||||
@ -1873,7 +1873,7 @@ Options::parse(int argc, const char** argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline ParseResult
|
inline ParseResult
|
||||||
OptionParser::parse(int argc, const char** argv)
|
OptionParser::parse(int argc, const char* const* argv)
|
||||||
{
|
{
|
||||||
int current = 1;
|
int current = 1;
|
||||||
bool consume_remaining = false;
|
bool consume_remaining = false;
|
||||||
|
|||||||
@ -773,3 +773,9 @@ TEST_CASE("Option add with add_option(string, Option)", "[options]") {
|
|||||||
CHECK(result["aggregate"].as<int>() == 4);
|
CHECK(result["aggregate"].as<int>() == 4);
|
||||||
CHECK(result["test"].as<int>() == 5);
|
CHECK(result["test"].as<int>() == 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Const array", "[const]") {
|
||||||
|
const char* const option_list[] = {"empty", "options"};
|
||||||
|
cxxopts::Options options("Empty options", " - test constness");
|
||||||
|
auto result = options.parse(2, option_list);
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user