diff --git a/include/CLI/App.hpp b/include/CLI/App.hpp index 82c0fed27..19da30245 100644 --- a/include/CLI/App.hpp +++ b/include/CLI/App.hpp @@ -655,13 +655,15 @@ class App { Option *add_flag(std::string flag_name) { return _add_flag_internal(flag_name, CLI::callback_t(), std::string{}); } /// Add flag with description but with no variable assignment or callback - /// takes a constant string, if a variable string is passed that variable will be assigned the results from the - /// flag + /// takes a constant string or a rvalue reference to a string, if a variable string is passed that variable will be + /// assigned the results from the flag template ::value && std::is_constructible::value, detail::enabler> = - detail::dummy> - Option *add_flag(std::string flag_name, T &flag_description) { - return _add_flag_internal(flag_name, CLI::callback_t(), flag_description); + enable_if_t<(std::is_const::type>::value || + std::is_rvalue_reference::value) && + std::is_constructible::type>::value, + detail::enabler> = detail::dummy> + Option *add_flag(std::string flag_name, T &&flag_description) { + return _add_flag_internal(flag_name, CLI::callback_t(), std::forward(flag_description)); } /// Other type version accepts all other types that are not vectors such as bool, enum, string or other classes