mirror of
https://github.com/CLIUtils/CLI11.git
synced 2025-04-30 04:33:53 +00:00
C++11 compliance on older compilers
This commit is contained in:
parent
8b224fa7a9
commit
955dd950f0
@ -603,24 +603,22 @@ protected:
|
||||
bool parsed{false};
|
||||
App* subcommand = nullptr;
|
||||
|
||||
std::function<void(App*)> app_callback;
|
||||
std::function<void()> app_callback;
|
||||
|
||||
public:
|
||||
/// Set a callback to run at the end of parsing
|
||||
App* set_callback(std::function<void(App*)> callback) {
|
||||
app_callback = callback;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// Don't have to worry about explicit App* in argument
|
||||
/// Set a callback for the end of parsing. Due to a bug in c++11,
|
||||
/// it is not possible to overload on std::function (fixed in c++14
|
||||
/// and backported to c++11 on newer compilers). Use capture by reference
|
||||
/// to get a pointer to App if needed.
|
||||
App* set_callback(std::function<void()> callback) {
|
||||
app_callback = [callback](App*){callback();};
|
||||
app_callback = callback;
|
||||
return this;
|
||||
}
|
||||
|
||||
void run_callback() {
|
||||
if(app_callback)
|
||||
app_callback(this);
|
||||
app_callback();
|
||||
}
|
||||
|
||||
/// Reset the parsed data
|
||||
|
@ -383,7 +383,7 @@ TEST_F(TApp, BasicSubcommands) {
|
||||
|
||||
TEST_F(TApp, Callbacks) {
|
||||
auto sub1 = app.add_subcommand("sub1");
|
||||
sub1->set_callback([](CLI::App*){
|
||||
sub1->set_callback([](){
|
||||
throw CLI::Success();
|
||||
});
|
||||
auto sub2 = app.add_subcommand("sub2");
|
||||
|
Loading…
x
Reference in New Issue
Block a user