diff --git a/include/CLI/App.hpp b/include/CLI/App.hpp index 255f2728..237aeedc 100644 --- a/include/CLI/App.hpp +++ b/include/CLI/App.hpp @@ -19,6 +19,7 @@ // CLI Library includes #include "CLI/Error.hpp" #include "CLI/Ini.hpp" +#include "CLI/Macros.hpp" #include "CLI/Option.hpp" #include "CLI/Split.hpp" #include "CLI/StringTools.hpp" @@ -447,7 +448,7 @@ class App { return opt; } -#if __cplusplus >= 201402L +#ifdef CLI11_CPP14 /// Add option for callback (C++14 or better only) Option *add_flag(std::string name, std::function function, ///< A function to call, void(size_t) diff --git a/include/CLI/CLI.hpp b/include/CLI/CLI.hpp index 53a0cef2..c8210c20 100644 --- a/include/CLI/CLI.hpp +++ b/include/CLI/CLI.hpp @@ -8,6 +8,8 @@ #include "CLI/Version.hpp" +#include "CLI/Macros.hpp" + #include "CLI/StringTools.hpp" #include "CLI/Error.hpp" diff --git a/include/CLI/Macros.hpp b/include/CLI/Macros.hpp new file mode 100644 index 00000000..dac50226 --- /dev/null +++ b/include/CLI/Macros.hpp @@ -0,0 +1,29 @@ +#pragma once + +// Distributed under the 3-Clause BSD License. See accompanying +// file LICENSE or https://github.com/CLIUtils/CLI11 for details. + +namespace CLI { + +// Note that all code in CLI11 must be in a namespace, even if it just a define. + +// The following version macro is very similar to the one in PyBind11 + +#if !defined(_MSC_VER) && !defined(__INTEL_COMPILER) +# if __cplusplus >= 201402L +# define CLI11_CPP14 +# if __cplusplus > 201402L /* Temporary: should be updated to >= the final C++17 value once known */ +# define CLI11_CPP17 +# endif +# endif +#elif defined(_MSC_VER) +// MSVC sets _MSVC_LANG rather than __cplusplus (supposedly until the standard is fully implemented) +# if _MSVC_LANG >= 201402L +# define CLI11_CPP14 +# if _MSVC_LANG > 201402L && _MSC_VER >= 1910 +# define CLI11_CPP17 +# endif +# endif +#endif + +} // namespace CLI diff --git a/include/CLI/Option.hpp b/include/CLI/Option.hpp index 6525a11d..30391357 100644 --- a/include/CLI/Option.hpp +++ b/include/CLI/Option.hpp @@ -13,6 +13,7 @@ #include #include "CLI/Error.hpp" +#include "CLI/Macros.hpp" #include "CLI/Split.hpp" #include "CLI/StringTools.hpp" @@ -299,7 +300,7 @@ class Option : public OptionBase