Commit ffe5b29e1f187d3acfe2b02bc3bebc43408dac66

Authored by Christoph Bachhuber
Committed by Henry Schreiner
1 parent 828e09e5

Add cstdint and std::prefix to its symbols (#409)

* Add cstdint and std::prefix to its symbols

* Use int64_t in std::
README.md
... ... @@ -217,7 +217,7 @@ app.add_flag(option_name,
217 217 help_string="")
218 218  
219 219 app.add_flag_function(option_name,
220   - function <void(int64_t count)>,
  220 + function <void(std::int64_t count)>,
221 221 help_string="")
222 222  
223 223 app.add_flag_callback(option_name,function<void(void)>,help_string="")
... ...
include/CLI/App.hpp
... ... @@ -4,6 +4,7 @@
4 4 // file LICENSE or https://github.com/CLIUtils/CLI11 for details.
5 5  
6 6 #include <algorithm>
  7 +#include <cstdint>
7 8 #include <functional>
8 9 #include <iostream>
9 10 #include <iterator>
... ... @@ -759,8 +760,9 @@ class App {
759 760 }
760 761  
761 762 /// Vector version to capture multiple flags.
762   - template <typename T,
763   - enable_if_t<!std::is_assignable<std::function<void(int64_t)>, T>::value, detail::enabler> = detail::dummy>
  763 + template <
  764 + typename T,
  765 + enable_if_t<!std::is_assignable<std::function<void(std::int64_t)>, T>::value, detail::enabler> = detail::dummy>
764 766 Option *add_flag(std::string flag_name,
765 767 std::vector<T> &flag_results, ///< A vector of values with the flag results
766 768 std::string flag_description = "") {
... ... @@ -795,11 +797,11 @@ class App {
795 797  
796 798 /// Add option for callback with an integer value
797 799 Option *add_flag_function(std::string flag_name,
798   - std::function<void(int64_t)> function, ///< A function to call, void(int)
  800 + std::function<void(std::int64_t)> function, ///< A function to call, void(int)
799 801 std::string flag_description = "") {
800 802  
801 803 CLI::callback_t fun = [function](const CLI::results_t &res) {
802   - int64_t flag_count = 0;
  804 + std::int64_t flag_count = 0;
803 805 detail::sum_flag_vector(res, flag_count);
804 806 function(flag_count);
805 807 return true;
... ... @@ -811,7 +813,7 @@ class App {
811 813 #ifdef CLI11_CPP14
812 814 /// Add option for callback (C++14 or better only)
813 815 Option *add_flag(std::string flag_name,
814   - std::function<void(int64_t)> function, ///< A function to call, void(int64_t)
  816 + std::function<void(std::int64_t)> function, ///< A function to call, void(std::int64_t)
815 817 std::string flag_description = "") {
816 818 return add_flag_function(std::move(flag_name), std::move(function), std::move(flag_description));
817 819 }
... ...
include/CLI/TypeTools.hpp
... ... @@ -548,7 +548,7 @@ inline std::string type_name() {
548 548 // Lexical cast
549 549  
550 550 /// Convert a flag into an integer value typically binary flags
551   -inline int64_t to_flag_value(std::string val) {
  551 +inline std::int64_t to_flag_value(std::string val) {
552 552 static const std::string trueString("true");
553 553 static const std::string falseString("false");
554 554 if(val == trueString) {
... ... @@ -558,10 +558,10 @@ inline int64_t to_flag_value(std::string val) {
558 558 return -1;
559 559 }
560 560 val = detail::to_lower(val);
561   - int64_t ret;
  561 + std::int64_t ret;
562 562 if(val.size() == 1) {
563 563 if(val[0] >= '1' && val[0] <= '9') {
564   - return (static_cast<int64_t>(val[0]) - '0');
  564 + return (static_cast<std::int64_t>(val[0]) - '0');
565 565 }
566 566 switch(val[0]) {
567 567 case '0':
... ... @@ -972,7 +972,7 @@ bool lexical_conversion(const std::vector&lt;std ::string&gt; &amp;strings, T &amp;output) {
972 972 template <typename T,
973 973 enable_if_t<std::is_integral<T>::value && std::is_unsigned<T>::value, detail::enabler> = detail::dummy>
974 974 void sum_flag_vector(const std::vector<std::string> &flags, T &output) {
975   - int64_t count{0};
  975 + std::int64_t count{0};
976 976 for(auto &flag : flags) {
977 977 count += detail::to_flag_value(flag);
978 978 }
... ... @@ -987,7 +987,7 @@ void sum_flag_vector(const std::vector&lt;std::string&gt; &amp;flags, T &amp;output) {
987 987 template <typename T,
988 988 enable_if_t<std::is_integral<T>::value && std::is_signed<T>::value, detail::enabler> = detail::dummy>
989 989 void sum_flag_vector(const std::vector<std::string> &flags, T &output) {
990   - int64_t count{0};
  990 + std::int64_t count{0};
991 991 for(auto &flag : flags) {
992 992 count += detail::to_flag_value(flag);
993 993 }
... ...
include/CLI/Validators.hpp
... ... @@ -8,6 +8,7 @@
8 8 #include "CLI/TypeTools.hpp"
9 9  
10 10 #include <cmath>
  11 +#include <cstdint>
11 12 #include <functional>
12 13 #include <iostream>
13 14 #include <limits>
... ... @@ -1043,7 +1044,7 @@ class AsNumberWithUnit : public Validator {
1043 1044 /// "2 EiB" => 2^61 // Units up to exibyte are supported
1044 1045 class AsSizeValue : public AsNumberWithUnit {
1045 1046 public:
1046   - using result_t = uint64_t;
  1047 + using result_t = std::uint64_t;
1047 1048  
1048 1049 /// If kb_is_1000 is true,
1049 1050 /// interpret 'kb', 'k' as 1000 and 'kib', 'ki' as 1024
... ...
tests/AppTest.cpp
1 1 #include "app_helper.hpp"
2 2 #include <complex>
  3 +#include <cstdint>
3 4 #include <cstdlib>
4 5  
5 6 #include "gmock/gmock.h"
... ... @@ -1431,9 +1432,9 @@ TEST_F(TApp, RequiredFlags) {
1431 1432  
1432 1433 TEST_F(TApp, CallbackFlags) {
1433 1434  
1434   - int64_t value = 0;
  1435 + std::int64_t value = 0;
1435 1436  
1436   - auto func = [&value](int64_t x) { value = x; };
  1437 + auto func = [&value](std::int64_t x) { value = x; };
1437 1438  
1438 1439 app.add_flag_function("-v", func);
1439 1440  
... ... @@ -1473,9 +1474,9 @@ TEST_F(TApp, CallbackBoolFlags) {
1473 1474 }
1474 1475  
1475 1476 TEST_F(TApp, CallbackFlagsFalse) {
1476   - int64_t value = 0;
  1477 + std::int64_t value = 0;
1477 1478  
1478   - auto func = [&value](int64_t x) { value = x; };
  1479 + auto func = [&value](std::int64_t x) { value = x; };
1479 1480  
1480 1481 app.add_flag_function("-v,-f{false},--val,--fval{false}", func);
1481 1482  
... ... @@ -1502,9 +1503,9 @@ TEST_F(TApp, CallbackFlagsFalse) {
1502 1503 }
1503 1504  
1504 1505 TEST_F(TApp, CallbackFlagsFalseShortcut) {
1505   - int64_t value = 0;
  1506 + std::int64_t value = 0;
1506 1507  
1507   - auto func = [&value](int64_t x) { value = x; };
  1508 + auto func = [&value](std::int64_t x) { value = x; };
1508 1509  
1509 1510 app.add_flag_function("-v,!-f,--val,!--fval", func);
1510 1511  
... ... @@ -1533,9 +1534,9 @@ TEST_F(TApp, CallbackFlagsFalseShortcut) {
1533 1534 #if __cplusplus >= 201402L || _MSC_VER >= 1900
1534 1535 TEST_F(TApp, CallbackFlagsAuto) {
1535 1536  
1536   - int64_t value = 0;
  1537 + std::int64_t value = 0;
1537 1538  
1538   - auto func = [&value](int64_t x) { value = x; };
  1539 + auto func = [&value](std::int64_t x) { value = x; };
1539 1540  
1540 1541 app.add_flag("-v", func);
1541 1542  
... ... @@ -2562,8 +2563,8 @@ TEST_F(TApp, EmptyOptionFail) {
2562 2563 }
2563 2564  
2564 2565 TEST_F(TApp, BeforeRequirements) {
2565   - app.add_flag_function("-a", [](int64_t) { throw CLI::Success(); });
2566   - app.add_flag_function("-b", [](int64_t) { throw CLI::CallForHelp(); });
  2566 + app.add_flag_function("-a", [](std::int64_t) { throw CLI::Success(); });
  2567 + app.add_flag_function("-b", [](std::int64_t) { throw CLI::CallForHelp(); });
2567 2568  
2568 2569 args = {"extra"};
2569 2570 EXPECT_THROW(run(), CLI::ExtrasError);
... ...
tests/HelpersTest.cpp
... ... @@ -1013,7 +1013,7 @@ TEST(Types, LexicalCastEnum) {
1013 1013 EXPECT_EQ(output, v5);
1014 1014  
1015 1015 EXPECT_FALSE(CLI::detail::lexical_cast("invalid", output));
1016   - enum class t2 : uint64_t { enum1 = 65, enum2 = 45667, enum3 = 9999999999999 };
  1016 + enum class t2 : std::uint64_t { enum1 = 65, enum2 = 45667, enum3 = 9999999999999 };
1017 1017 t2 output2;
1018 1018 EXPECT_TRUE(CLI::detail::lexical_cast("65", output2));
1019 1019 EXPECT_EQ(output2, t2::enum1);
... ...
tests/NewParseTest.cpp
1 1 #include "app_helper.hpp"
2 2 #include "gmock/gmock.h"
3 3 #include <complex>
  4 +#include <cstdint>
4 5  
5 6 using ::testing::HasSubstr;
6 7  
... ... @@ -499,12 +500,12 @@ template &lt;class X&gt; class AobjWrapper {
499 500 X val_{};
500 501 };
501 502  
502   -static_assert(std::is_assignable<AobjWrapper<uint16_t> &, uint16_t>::value,
  503 +static_assert(std::is_assignable<AobjWrapper<std::uint16_t> &, std::uint16_t>::value,
503 504 "AobjWrapper not assignable like it should be ");
504 505  
505 506 TEST_F(TApp, uint16Wrapper) {
506   - AobjWrapper<uint16_t> sWrapper;
507   - app.add_option<AobjWrapper<uint16_t>, uint16_t>("-v", sWrapper);
  507 + AobjWrapper<std::uint16_t> sWrapper;
  508 + app.add_option<AobjWrapper<std::uint16_t>, std::uint16_t>("-v", sWrapper);
508 509 args = {"-v", "9"};
509 510  
510 511 run();
... ...
tests/OptionalTest.cpp
  1 +#include <cstdint>
1 2 #include <cstdlib>
2 3 #include <iostream>
3 4  
... ... @@ -132,7 +133,7 @@ TEST_F(TApp, BoostOptionalTestZarg) {
132 133 }
133 134  
134 135 TEST_F(TApp, BoostOptionalint64Test) {
135   - boost::optional<int64_t> opt;
  136 + boost::optional<std::int64_t> opt;
136 137 app.add_option("-c,--count", opt);
137 138 run();
138 139 EXPECT_FALSE(opt);
... ...
tests/TransformTest.cpp
1 1 #include "app_helper.hpp"
2 2  
3 3 #include <array>
  4 +#include <cstdint>
4 5 #include <unordered_map>
5 6  
6 7 #if defined(CLI11_CPP17)
... ... @@ -43,7 +44,7 @@ TEST_F(TApp, SimpleNumericalTransform) {
43 44 }
44 45  
45 46 TEST_F(TApp, EnumTransform) {
46   - enum class test : int16_t { val1 = 3, val2 = 4, val3 = 17 };
  47 + enum class test : std::int16_t { val1 = 3, val2 = 4, val3 = 17 };
47 48 test value;
48 49 auto opt = app.add_option("-s", value)
49 50 ->transform(CLI::Transformer(
... ... @@ -68,11 +69,11 @@ TEST_F(TApp, EnumTransform) {
68 69 // transformer doesn't do any checking so this still works
69 70 args = {"-s", "5"};
70 71 run();
71   - EXPECT_EQ(static_cast<int16_t>(value), int16_t(5));
  72 + EXPECT_EQ(static_cast<std::int16_t>(value), std::int16_t(5));
72 73 }
73 74  
74 75 TEST_F(TApp, EnumCheckedTransform) {
75   - enum class test : int16_t { val1 = 3, val2 = 4, val3 = 17 };
  76 + enum class test : std::int16_t { val1 = 3, val2 = 4, val3 = 17 };
76 77 test value;
77 78 auto opt = app.add_option("-s", value)
78 79 ->transform(CLI::CheckedTransformer(
... ... @@ -104,7 +105,7 @@ TEST_F(TApp, EnumCheckedTransform) {
104 105  
105 106 // from jzakrzewski Issue #330
106 107 TEST_F(TApp, EnumCheckedDefualtTransform) {
107   - enum class existing : int16_t { abort, overwrite, remove };
  108 + enum class existing : std::int16_t { abort, overwrite, remove };
108 109 app.add_option("--existing", "What to do if file already exists in the destination")
109 110 ->transform(
110 111 CLI::CheckedTransformer(std::unordered_map<std::string, existing>{{"abort", existing::abort},
... ... @@ -122,7 +123,7 @@ TEST_F(TApp, EnumCheckedDefualtTransform) {
122 123  
123 124 // test from https://github.com/CLIUtils/CLI11/issues/369 [Jakub Zakrzewski](https://github.com/jzakrzewski)
124 125 TEST_F(TApp, EnumCheckedDefaultTransformCallback) {
125   - enum class existing : int16_t { abort, overwrite, remove };
  126 + enum class existing : std::int16_t { abort, overwrite, remove };
126 127 auto cmd = std::make_shared<CLI::App>("deploys the repository somewhere", "deploy");
127 128 cmd->add_option("--existing", "What to do if file already exists in the destination")
128 129 ->transform(
... ... @@ -223,7 +224,7 @@ TEST_F(TApp, SimpleNumericalTransformFnconstexprArray) {
223 224 #endif
224 225  
225 226 TEST_F(TApp, EnumTransformFn) {
226   - enum class test : int16_t { val1 = 3, val2 = 4, val3 = 17 };
  227 + enum class test : std::int16_t { val1 = 3, val2 = 4, val3 = 17 };
227 228 test value;
228 229 auto opt = app.add_option("-s", value)
229 230 ->transform(CLI::Transformer(
... ... @@ -249,7 +250,7 @@ TEST_F(TApp, EnumTransformFn) {
249 250 }
250 251  
251 252 TEST_F(TApp, EnumTransformFnMap) {
252   - enum class test : int16_t { val1 = 3, val2 = 4, val3 = 17 };
  253 + enum class test : std::int16_t { val1 = 3, val2 = 4, val3 = 17 };
253 254 std::map<std::string, test> map{{"val1", test::val1}, {"val2", test::val2}, {"val3", test::val3}};
254 255 test value;
255 256 auto opt = app.add_option("-s", value)->transform(CLI::Transformer(map, CLI::ignore_case, CLI::ignore_underscore));
... ... @@ -272,7 +273,7 @@ TEST_F(TApp, EnumTransformFnMap) {
272 273 }
273 274  
274 275 TEST_F(TApp, EnumTransformFnPtrMap) {
275   - enum class test : int16_t { val1 = 3, val2 = 4, val3 = 17, val4 = 37 };
  276 + enum class test : std::int16_t { val1 = 3, val2 = 4, val3 = 17, val4 = 37 };
276 277 std::map<std::string, test> map{{"val1", test::val1}, {"val2", test::val2}, {"val3", test::val3}};
277 278 test value;
278 279 auto opt = app.add_option("-s", value)->transform(CLI::Transformer(&map, CLI::ignore_case, CLI::ignore_underscore));
... ... @@ -299,7 +300,7 @@ TEST_F(TApp, EnumTransformFnPtrMap) {
299 300 }
300 301  
301 302 TEST_F(TApp, EnumTransformFnSharedPtrMap) {
302   - enum class test : int16_t { val1 = 3, val2 = 4, val3 = 17, val4 = 37 };
  303 + enum class test : std::int16_t { val1 = 3, val2 = 4, val3 = 17, val4 = 37 };
303 304 auto map = std::make_shared<std::unordered_map<std::string, test>>();
304 305 auto &mp = *map;
305 306 mp["val1"] = test::val1;
... ... @@ -698,7 +699,7 @@ TEST_F(TApp, NumberWithUnitBadInput) {
698 699 TEST_F(TApp, NumberWithUnitIntOverflow) {
699 700 std::map<std::string, int> mapping{{"a", 1000000}, {"b", 100}, {"c", 101}};
700 701  
701   - int32_t value;
  702 + std::int32_t value;
702 703 app.add_option("-n", value)->transform(CLI::AsNumberWithUnit(mapping));
703 704  
704 705 args = {"-n", "1000 a"};
... ... @@ -738,7 +739,7 @@ TEST_F(TApp, NumberWithUnitFloatOverflow) {
738 739 }
739 740  
740 741 TEST_F(TApp, AsSizeValue1000_1024) {
741   - uint64_t value;
  742 + std::uint64_t value;
742 743 app.add_option("-s", value)->transform(CLI::AsSizeValue(true));
743 744  
744 745 args = {"-s", "10240"};
... ... @@ -749,8 +750,8 @@ TEST_F(TApp, AsSizeValue1000_1024) {
749 750 run();
750 751 EXPECT_EQ(value, 1u);
751 752  
752   - uint64_t k_value = 1000u;
753   - uint64_t ki_value = 1024u;
  753 + std::uint64_t k_value = 1000u;
  754 + std::uint64_t ki_value = 1024u;
754 755 args = {"-s", "1k"};
755 756 run();
756 757 EXPECT_EQ(value, k_value);
... ... @@ -844,7 +845,7 @@ TEST_F(TApp, AsSizeValue1000_1024) {
844 845 }
845 846  
846 847 TEST_F(TApp, AsSizeValue1024) {
847   - uint64_t value;
  848 + std::uint64_t value;
848 849 app.add_option("-s", value)->transform(CLI::AsSizeValue(false));
849 850  
850 851 args = {"-s", "10240"};
... ... @@ -855,7 +856,7 @@ TEST_F(TApp, AsSizeValue1024) {
855 856 run();
856 857 EXPECT_EQ(value, 1u);
857 858  
858   - uint64_t ki_value = 1024u;
  859 + std::uint64_t ki_value = 1024u;
859 860 args = {"-s", "1k"};
860 861 run();
861 862 EXPECT_EQ(value, ki_value);
... ...