Commit cc4914f065fc06e96e87e77f637138e716dafbe4

Authored by Jarryd Beck
1 parent 0fe1dc89

Revert "Added const to argv type for better interoperability. (#99)"

This reverts commit 0f819a5cabb611ada4c41a5208c6bf1178f804be.
include/cxxopts.hpp
@@ -1095,7 +1095,7 @@ namespace cxxopts @@ -1095,7 +1095,7 @@ namespace cxxopts
1095 ParseResult( 1095 ParseResult(
1096 const std::unordered_map<std::string, std::shared_ptr<OptionDetails>>&, 1096 const std::unordered_map<std::string, std::shared_ptr<OptionDetails>>&,
1097 std::vector<std::string>, 1097 std::vector<std::string>,
1098 - int&, const char**&); 1098 + int&, char**&);
1099 1099
1100 size_t 1100 size_t
1101 count(const std::string& o) const 1101 count(const std::string& o) const
@@ -1138,7 +1138,7 @@ namespace cxxopts @@ -1138,7 +1138,7 @@ namespace cxxopts
1138 get_option(std::shared_ptr<OptionDetails>); 1138 get_option(std::shared_ptr<OptionDetails>);
1139 1139
1140 void 1140 void
1141 - parse(int& argc, const char**& argv); 1141 + parse(int& argc, char**& argv);
1142 1142
1143 void 1143 void
1144 add_to_option(const std::string& option, const std::string& arg); 1144 add_to_option(const std::string& option, const std::string& arg);
@@ -1161,7 +1161,7 @@ namespace cxxopts @@ -1161,7 +1161,7 @@ namespace cxxopts
1161 checked_parse_arg 1161 checked_parse_arg
1162 ( 1162 (
1163 int argc, 1163 int argc,
1164 - const char* argv[], 1164 + char* argv[],
1165 int& current, 1165 int& current,
1166 std::shared_ptr<OptionDetails> value, 1166 std::shared_ptr<OptionDetails> value,
1167 const std::string& name 1167 const std::string& name
@@ -1213,7 +1213,7 @@ namespace cxxopts @@ -1213,7 +1213,7 @@ namespace cxxopts
1213 } 1213 }
1214 1214
1215 ParseResult 1215 ParseResult
1216 - parse(int& argc, const char**& argv); 1216 + parse(int& argc, char**& argv);
1217 1217
1218 OptionAdder 1218 OptionAdder
1219 add_options(std::string group = ""); 1219 add_options(std::string group = "");
@@ -1431,7 +1431,7 @@ ParseResult::ParseResult @@ -1431,7 +1431,7 @@ ParseResult::ParseResult
1431 ( 1431 (
1432 const std::unordered_map<std::string, std::shared_ptr<OptionDetails>>& options, 1432 const std::unordered_map<std::string, std::shared_ptr<OptionDetails>>& options,
1433 std::vector<std::string> positional, 1433 std::vector<std::string> positional,
1434 - int& argc, const char**& argv 1434 + int& argc, char**& argv
1435 ) 1435 )
1436 : m_options(options) 1436 : m_options(options)
1437 , m_positional(std::move(positional)) 1437 , m_positional(std::move(positional))
@@ -1532,7 +1532,7 @@ void @@ -1532,7 +1532,7 @@ void
1532 ParseResult::checked_parse_arg 1532 ParseResult::checked_parse_arg
1533 ( 1533 (
1534 int argc, 1534 int argc,
1535 - const char* argv[], 1535 + char* argv[],
1536 int& current, 1536 int& current,
1537 std::shared_ptr<OptionDetails> value, 1537 std::shared_ptr<OptionDetails> value,
1538 const std::string& name 1538 const std::string& name
@@ -1639,7 +1639,7 @@ Options::parse_positional(std::initializer_list&lt;std::string&gt; options) @@ -1639,7 +1639,7 @@ Options::parse_positional(std::initializer_list&lt;std::string&gt; options)
1639 1639
1640 inline 1640 inline
1641 ParseResult 1641 ParseResult
1642 -Options::parse(int& argc, const char**& argv) 1642 +Options::parse(int& argc, char**& argv)
1643 { 1643 {
1644 ParseResult result(m_options, m_positional, argc, argv); 1644 ParseResult result(m_options, m_positional, argc, argv);
1645 return result; 1645 return result;
@@ -1647,7 +1647,7 @@ Options::parse(int&amp; argc, const char**&amp; argv) @@ -1647,7 +1647,7 @@ Options::parse(int&amp; argc, const char**&amp; argv)
1647 1647
1648 inline 1648 inline
1649 void 1649 void
1650 -ParseResult::parse(int& argc, const char**& argv) 1650 +ParseResult::parse(int& argc, char**& argv)
1651 { 1651 {
1652 int current = 1; 1652 int current = 1;
1653 1653
src/example.cpp
@@ -26,7 +26,7 @@ THE SOFTWARE. @@ -26,7 +26,7 @@ THE SOFTWARE.
26 26
27 #include "cxxopts.hpp" 27 #include "cxxopts.hpp"
28 28
29 -int main(int argc, const char* argv[]) 29 +int main(int argc, char* argv[])
30 { 30 {
31 try 31 try
32 { 32 {
test/options.cpp
@@ -8,7 +8,7 @@ class Argv { @@ -8,7 +8,7 @@ class Argv {
8 public: 8 public:
9 9
10 Argv(std::initializer_list<const char*> args) 10 Argv(std::initializer_list<const char*> args)
11 - : m_argv(new const char*[args.size()]) 11 + : m_argv(new char*[args.size()])
12 , m_argc(args.size()) 12 , m_argc(args.size())
13 { 13 {
14 int i = 0; 14 int i = 0;
@@ -26,7 +26,7 @@ class Argv { @@ -26,7 +26,7 @@ class Argv {
26 } 26 }
27 } 27 }
28 28
29 - const char** argv() const { 29 + char** argv() const {
30 return m_argv.get(); 30 return m_argv.get();
31 } 31 }
32 32
@@ -36,8 +36,8 @@ class Argv { @@ -36,8 +36,8 @@ class Argv {
36 36
37 private: 37 private:
38 38
39 - std::vector<std::unique_ptr<const char[]>> m_args;  
40 - std::unique_ptr<const char*[]> m_argv; 39 + std::vector<std::unique_ptr<char[]>> m_args;
  40 + std::unique_ptr<char*[]> m_argv;
41 int m_argc; 41 int m_argc;
42 }; 42 };
43 43
@@ -68,7 +68,7 @@ TEST_CASE(&quot;Basic options&quot;, &quot;[options]&quot;) @@ -68,7 +68,7 @@ TEST_CASE(&quot;Basic options&quot;, &quot;[options]&quot;)
68 "--space", 68 "--space",
69 }); 69 });
70 70
71 - const char** actual_argv = argv.argv(); 71 + char** actual_argv = argv.argv();
72 auto argc = argv.argc(); 72 auto argc = argv.argc();
73 73
74 auto result = options.parse(argc, actual_argv); 74 auto result = options.parse(argc, actual_argv);
@@ -122,7 +122,7 @@ TEST_CASE(&quot;No positional&quot;, &quot;[positional]&quot;) @@ -122,7 +122,7 @@ TEST_CASE(&quot;No positional&quot;, &quot;[positional]&quot;)
122 122
123 Argv av({"tester", "a", "b", "def"}); 123 Argv av({"tester", "a", "b", "def"});
124 124
125 - const char** argv = av.argv(); 125 + char** argv = av.argv();
126 auto argc = av.argc(); 126 auto argc = av.argc();
127 auto result = options.parse(argc, argv); 127 auto result = options.parse(argc, argv);
128 128
@@ -172,7 +172,7 @@ TEST_CASE(&quot;Some positional explicit&quot;, &quot;[positional]&quot;) @@ -172,7 +172,7 @@ TEST_CASE(&quot;Some positional explicit&quot;, &quot;[positional]&quot;)
172 172
173 Argv av({"tester", "--output", "a", "b", "c", "d"}); 173 Argv av({"tester", "--output", "a", "b", "c", "d"});
174 174
175 - const char** argv = av.argv(); 175 + char** argv = av.argv();
176 auto argc = av.argc(); 176 auto argc = av.argc();
177 177
178 auto result = options.parse(argc, argv); 178 auto result = options.parse(argc, argv);
@@ -198,7 +198,7 @@ TEST_CASE(&quot;No positional with extras&quot;, &quot;[positional]&quot;) @@ -198,7 +198,7 @@ TEST_CASE(&quot;No positional with extras&quot;, &quot;[positional]&quot;)
198 198
199 Argv av({"extras", "--", "a", "b", "c", "d"}); 199 Argv av({"extras", "--", "a", "b", "c", "d"});
200 200
201 - const char** argv = av.argv(); 201 + char** argv = av.argv();
202 auto argc = av.argc(); 202 auto argc = av.argc();
203 203
204 auto old_argv = argv; 204 auto old_argv = argv;
@@ -220,7 +220,7 @@ TEST_CASE(&quot;Empty with implicit value&quot;, &quot;[implicit]&quot;) @@ -220,7 +220,7 @@ TEST_CASE(&quot;Empty with implicit value&quot;, &quot;[implicit]&quot;)
220 220
221 Argv av({"implicit", "--implicit="}); 221 Argv av({"implicit", "--implicit="});
222 222
223 - const char** argv = av.argv(); 223 + char** argv = av.argv();
224 auto argc = av.argc(); 224 auto argc = av.argc();
225 225
226 auto result = options.parse(argc, argv); 226 auto result = options.parse(argc, argv);
@@ -239,7 +239,7 @@ TEST_CASE(&quot;Default values&quot;, &quot;[default]&quot;) @@ -239,7 +239,7 @@ TEST_CASE(&quot;Default values&quot;, &quot;[default]&quot;)
239 SECTION("Sets defaults") { 239 SECTION("Sets defaults") {
240 Argv av({"implicit"}); 240 Argv av({"implicit"});
241 241
242 - const char** argv = av.argv(); 242 + char** argv = av.argv();
243 auto argc = av.argc(); 243 auto argc = av.argc();
244 244
245 auto result = options.parse(argc, argv); 245 auto result = options.parse(argc, argv);
@@ -250,7 +250,7 @@ TEST_CASE(&quot;Default values&quot;, &quot;[default]&quot;) @@ -250,7 +250,7 @@ TEST_CASE(&quot;Default values&quot;, &quot;[default]&quot;)
250 SECTION("When values provided") { 250 SECTION("When values provided") {
251 Argv av({"implicit", "--default", "5"}); 251 Argv av({"implicit", "--default", "5"});
252 252
253 - const char** argv = av.argv(); 253 + char** argv = av.argv();
254 auto argc = av.argc(); 254 auto argc = av.argc();
255 255
256 auto result = options.parse(argc, argv); 256 auto result = options.parse(argc, argv);
@@ -285,7 +285,7 @@ TEST_CASE(&quot;Integers&quot;, &quot;[options]&quot;) @@ -285,7 +285,7 @@ TEST_CASE(&quot;Integers&quot;, &quot;[options]&quot;)
285 285
286 Argv av({"ints", "--", "5", "6", "-6", "0", "0xab", "0xAf", "0x0"}); 286 Argv av({"ints", "--", "5", "6", "-6", "0", "0xab", "0xAf", "0x0"});
287 287
288 - const char** argv = av.argv(); 288 + char** argv = av.argv();
289 auto argc = av.argc(); 289 auto argc = av.argc();
290 290
291 options.parse_positional("positional"); 291 options.parse_positional("positional");
@@ -312,7 +312,7 @@ TEST_CASE(&quot;Unsigned integers&quot;, &quot;[options]&quot;) @@ -312,7 +312,7 @@ TEST_CASE(&quot;Unsigned integers&quot;, &quot;[options]&quot;)
312 312
313 Argv av({"ints", "--", "-2"}); 313 Argv av({"ints", "--", "-2"});
314 314
315 - const char** argv = av.argv(); 315 + char** argv = av.argv();
316 auto argc = av.argc(); 316 auto argc = av.argc();
317 317
318 options.parse_positional("positional"); 318 options.parse_positional("positional");
@@ -385,7 +385,7 @@ TEST_CASE(&quot;Floats&quot;, &quot;[options]&quot;) @@ -385,7 +385,7 @@ TEST_CASE(&quot;Floats&quot;, &quot;[options]&quot;)
385 385
386 Argv av({"floats", "--double", "0.5", "--", "4", "-4", "1.5e6", "-1.5e6"}); 386 Argv av({"floats", "--double", "0.5", "--", "4", "-4", "1.5e6", "-1.5e6"});
387 387
388 - const char** argv = av.argv(); 388 + char** argv = av.argv();
389 auto argc = av.argc(); 389 auto argc = av.argc();
390 390
391 options.parse_positional("positional"); 391 options.parse_positional("positional");
@@ -410,7 +410,7 @@ TEST_CASE(&quot;Invalid integers&quot;, &quot;[integer]&quot;) { @@ -410,7 +410,7 @@ TEST_CASE(&quot;Invalid integers&quot;, &quot;[integer]&quot;) {
410 410
411 Argv av({"ints", "--", "Ae"}); 411 Argv av({"ints", "--", "Ae"});
412 412
413 - const char **argv = av.argv(); 413 + char **argv = av.argv();
414 auto argc = av.argc(); 414 auto argc = av.argc();
415 415
416 options.parse_positional("positional"); 416 options.parse_positional("positional");
@@ -433,7 +433,7 @@ TEST_CASE(&quot;Booleans&quot;, &quot;[boolean]&quot;) { @@ -433,7 +433,7 @@ TEST_CASE(&quot;Booleans&quot;, &quot;[boolean]&quot;) {
433 433
434 Argv av({"booleans", "--bool=false", "--debug=true", "--timing", "extra"}); 434 Argv av({"booleans", "--bool=false", "--debug=true", "--timing", "extra"});
435 435
436 - const char** argv = av.argv(); 436 + char** argv = av.argv();
437 auto argc = av.argc(); 437 auto argc = av.argc();
438 438
439 auto result = options.parse(argc, argv); 439 auto result = options.parse(argc, argv);