Commit db202b831e286153fb020d1d78053b758bff730a
Committed by
Henry Schreiner
1 parent
bea833bb
Factoring out C++ version check to Macros file
Showing
4 changed files
with
35 additions
and
2 deletions
include/CLI/App.hpp
| ... | ... | @@ -19,6 +19,7 @@ |
| 19 | 19 | // CLI Library includes |
| 20 | 20 | #include "CLI/Error.hpp" |
| 21 | 21 | #include "CLI/Ini.hpp" |
| 22 | +#include "CLI/Macros.hpp" | |
| 22 | 23 | #include "CLI/Option.hpp" |
| 23 | 24 | #include "CLI/Split.hpp" |
| 24 | 25 | #include "CLI/StringTools.hpp" |
| ... | ... | @@ -447,7 +448,7 @@ class App { |
| 447 | 448 | return opt; |
| 448 | 449 | } |
| 449 | 450 | |
| 450 | -#if __cplusplus >= 201402L | |
| 451 | +#ifdef CLI11_CPP14 | |
| 451 | 452 | /// Add option for callback (C++14 or better only) |
| 452 | 453 | Option *add_flag(std::string name, |
| 453 | 454 | std::function<void(size_t)> function, ///< A function to call, void(size_t) | ... | ... |
include/CLI/CLI.hpp
include/CLI/Macros.hpp
0 → 100644
| 1 | +#pragma once | |
| 2 | + | |
| 3 | +// Distributed under the 3-Clause BSD License. See accompanying | |
| 4 | +// file LICENSE or https://github.com/CLIUtils/CLI11 for details. | |
| 5 | + | |
| 6 | +namespace CLI { | |
| 7 | + | |
| 8 | +// Note that all code in CLI11 must be in a namespace, even if it just a define. | |
| 9 | + | |
| 10 | +// The following version macro is very similar to the one in PyBind11 | |
| 11 | + | |
| 12 | +#if !defined(_MSC_VER) && !defined(__INTEL_COMPILER) | |
| 13 | +# if __cplusplus >= 201402L | |
| 14 | +# define CLI11_CPP14 | |
| 15 | +# if __cplusplus > 201402L /* Temporary: should be updated to >= the final C++17 value once known */ | |
| 16 | +# define CLI11_CPP17 | |
| 17 | +# endif | |
| 18 | +# endif | |
| 19 | +#elif defined(_MSC_VER) | |
| 20 | +// MSVC sets _MSVC_LANG rather than __cplusplus (supposedly until the standard is fully implemented) | |
| 21 | +# if _MSVC_LANG >= 201402L | |
| 22 | +# define CLI11_CPP14 | |
| 23 | +# if _MSVC_LANG > 201402L && _MSC_VER >= 1910 | |
| 24 | +# define CLI11_CPP17 | |
| 25 | +# endif | |
| 26 | +# endif | |
| 27 | +#endif | |
| 28 | + | |
| 29 | +} // namespace CLI | ... | ... |
include/CLI/Option.hpp
| ... | ... | @@ -13,6 +13,7 @@ |
| 13 | 13 | #include <vector> |
| 14 | 14 | |
| 15 | 15 | #include "CLI/Error.hpp" |
| 16 | +#include "CLI/Macros.hpp" | |
| 16 | 17 | #include "CLI/Split.hpp" |
| 17 | 18 | #include "CLI/StringTools.hpp" |
| 18 | 19 | |
| ... | ... | @@ -299,7 +300,7 @@ class Option : public OptionBase<Option> { |
| 299 | 300 | return needs(opt1, args...); |
| 300 | 301 | } |
| 301 | 302 | |
| 302 | -#if __cplusplus <= 201703L | |
| 303 | +#ifndef CLI11_CPP17 | |
| 303 | 304 | /// Sets required options \deprecated |
| 304 | 305 | Option *requires(Option *opt) { return needs(opt); } |
| 305 | 306 | ... | ... |