Comments (4)
Everything works without fault on my Linux machine, so this might be windows specific.
from args.
I debugged the case to find the exact cause. Finally I found that this lambda expression can`t capture the variables correctly in windows.
[&, this](auto&& attribute) -> decltype(attribute(x, *this, arg), void()) { attribute(x, *this, arg); }
template<class T, class... Ts>
void parse(T&& x, Ts&&... xs)
{
argument arg;
arg.write_value = [&x](const std::string& s) { args::write_value_to(x, s); };
arg.type = args::get_argument_type(x);
arg.metavar = args::type_to_help(x);
args::each_arg(args::overload(
[&](const std::string& name) { arg.flags.push_back(name); },
[&, this](auto&& attribute) -> decltype(attribute(x, *this, arg), void()) { attribute(x, *this, arg); }
), std::forward<Ts>(xs)...);
this->add(std::move(arg));
}
By the way, I can`t compile the "args.hpp" file directly at vs2019.
vs2019 compile output show as below.
1>------ Build started: Project: TestArg, Configuration: Debug x64 ------
1>TestArg.cpp
1>C:\Users\weifeiyu\source\repos\TestArg\args.hpp(344,1): error C3861: '__this': identifier not found
...
from args.
I think this is a problem with handling expression SFINAE in MSVC. I've never tested this on windows. If there is some workarounds to make this work on MSVC, please let me know.
from args.
I'm newbie here of c++, so the root cause I can't figure out. In my test, this issue just happen in the "--help" parser. Cause of the project limit, I have to do some ugly modification, but work.
In order to avoid compile error, I use local variable to instead of this pointer.
template<class T, class... Ts> |template<class T, class... Ts>
void parse(T&& x, Ts&&... xs) |void parse(T&& x, Ts&&... xs)
{ |{
context* cxt = this; |-------------------------------------------------------------------------------------------------------------------------------------
argument arg; | argument arg;
arg.write_value = [&x](const std::string& s) { args::write_value_to(x, s); }; | arg.write_value = [&x](const std::string& s) {args::write_value_to(x, s); };
arg.type = args::get_argument_type(x); | arg.type = args::get_argument_type(x);
arg.metavar = args::type_to_help(x); | arg.metavar = args::type_to_help(x);
args::each_arg(args::overload( | args::each_arg(args::overload(
[&](const std::string& name) { arg.flags.push_back(name); }, | [&, this](const std::string& name) { arg.flags.push_back(name); },
[&, cxt](auto&& attribute) -> decltype(attribute(x, *cxt, arg), void()) { attribute(x, *cxt, arg); }| [&, this](auto&& attribute) -> decltype(attribute(x, *this, arg), void()) { attribute(x, *this, arg); }
), std::forward<Ts>(xs)...); | ), std::forward<Ts>(xs)...);
this->add(std::move(arg)); | this->add(std::move(arg));
} |}
Then, Using the 'ctx' variable captured by copy to support show "--help" information.
template<class... Ts, class T> | template<class... Ts, class T>
context<T&, Ts...> build_context(T& cmd) | context<T&, Ts...> build_context(T& cmd)
{ | {
context<T&, Ts...> ctx; | context<T&, Ts...> ctx;
args::assign_subcommands(rank<1>{}, ctx, cmd); | args::assign_subcommands(rank<1>{}, ctx, cmd);
| ctx.parse(nullptr, "--help", "-h", args::help("Show help."),
----------------------------------------------------------------------------------| args::eager_callback([](std::nullptr_t, const auto& c, const argument&)
----------------------------------------------------------------------------------| {
----------------------------------------------------------------------------------| c.show_help(get_name<T>(), get_help<T>(), get_options_metavar<T>());
----------------------------------------------------------------------------------| }));
args::try_parse(rank<1>{}, cmd, [&](auto&&... xs) | args::try_parse(rank<1>{}, cmd, [&](auto&&... xs)
{ | {
ctx.parse(std::forward<decltype(xs)>(xs)...); | ctx.parse(std::forward<decltype(xs)>(xs)...);
}); | });
ctx.parse(nullptr, "--help", "-h", args::help("Show help."), | -------------------------------------------------------------------------------
args::eager_callback([ctx](std::nullptr_t, const auto& c, const argument&)| -------------------------------------------------------------------------------
{ | -------------------------------------------------------------------------------
ctx.show_help(get_name<T>(), get_help<T>(), get_options_metavar<T>()); | -------------------------------------------------------------------------------
})); | -------------------------------------------------------------------------------
return ctx; | return ctx;
} | }
Hope someone can solve this problem really.
from args.
Related Issues (5)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from args.