catchorg / Clara

A simple to use, composable, command line parser for C++ 11 and beyond
Boost Software License 1.0
649 stars 67 forks source link

Support for calling a std::function when an option is chosen #1

Closed jh3141 closed 7 years ago

jh3141 commented 9 years ago

The above would be very helpful, as it would allow C++11 lambda functions and/or the results of std::bind to be used as option handlers, rather than just member or free functions, which as far as I see are the only options at present.

philsquared commented 8 years ago

It would certainly be useful - and is something I've been intending to do. Clara primarily targets C++03 as a base, so anything C++11/14/17 related needs to be properly guarded. I've just ported over the compiler toggle mechanism from Catch as a step towards making this easier. I'll looking at adding std::function soon.

One question I'm still struggling with, myself, is: should the std::function take only the argument value? Or should it take the config object as well? Both options seen useful in their own way, so I'd probably provide both.

philsquared commented 7 years ago

The new version of Clara has been rewritten as a C++11 library and works natively with lambdas now.