bfgroup / Lyra

A simple to use, composable, command line parser for C++ 11 and beyond
https://bfgroup.github.io/Lyra/
Boost Software License 1.0
471 stars 56 forks source link

Constructing `arg` with a callable sometimes picks the wrong overload #94

Open mknejp opened 3 months ago

mknejp commented 3 months ago

The constraints put on the constructors of bound_parser seem to be different from opt, as the latter works in all these scenarios.

Works:

lyra::arg([](std::string) {}, "hint");

Does not work:

auto f = [](std::string) {};
lyra::arg(f, "hint");
auto f = std::function<void(std::string)>{};
lyra::arg(f, "hint");

They both cause compile errors as they attempt to stream into/out of the function object.

https://godbolt.org/z/W8M7Tb687

mknejp commented 3 months ago

Update: it seems to be related to the value category of the callable as

auto f = std::function<void(std::string)>{};
lyra::arg(std::move(f), "hint");

works.