-
Notifications
You must be signed in to change notification settings - Fork 362
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
std::optional makes the underlying type to be badly deduced #447
Comments
Can you try with PR #423 |
for the case I've provided this branch works. #include <CLI/CLI.hpp>
#include <optional>
#include <map>
#include <iostream>
enum class EC: uint32_t
{
ONE = 1,
TWO = 2,
};
static const std::map<const std::string,EC> ecm {
{"one", EC::ONE},
{"two", EC::TWO},
};
int main(int argc, char** argv)
{
std::optional<uint32_t> int32;
std::optional<EC> ec_opt;
CLI::App app{"test"};
app.add_option("--test", int32, "should be unsinged int");
app.add_option("--enum", ec_opt, "should just work")->transform(CLI::CheckedTransformer(ecm));
CLI11_PARSE(app, argc, argv);
if (ec_opt)
std::cout << uint32_t(*ec_opt) << std::endl;
else
std::cout << "ec_opt not set" << std::endl;
return 0;
} and it compiles, and works as expected
|
Good to know it works for you. I suspect it could work with master using the two argument template for add_option
which definitely isn't as convenient but should work. Also what drove #285. |
Will this branch be merged before next release? This feature is really nice |
I'm going to be reviewing and merging things somewhat soon. Everything is likely to go in. I'm not currently sure if I'm going to try to make a 1.10 release before 2.0 - I've got two key changes planned for 2.0 that are going to take some time (optional compile ahead and no-exception-catching support). Behavior changing changes will be 2.0 only as well. I think this is one of them. |
For code:
compiled with
g++ -std=c++17 test.cpp
the output is:
It also has problems with parsing optional class enum with mapping for the enum (it does not find how to parse it)
For testing I've used g++ 7.5 and clang 8 with libcxx 8
Library 1.9.0
I think #285 had a negative impact on option parsing.
The text was updated successfully, but these errors were encountered: