1
0
mirror of https://github.com/CLIUtils/CLI11.git synced 2025-05-01 13:13:53 +00:00

Factoring out C++ version check to Macros file

This commit is contained in:
Henry Fredrick Schreiner 2018-04-03 09:31:58 +02:00 committed by Henry Schreiner
parent bea833bbcd
commit db202b831e
4 changed files with 35 additions and 2 deletions

View File

@ -19,6 +19,7 @@
// CLI Library includes // CLI Library includes
#include "CLI/Error.hpp" #include "CLI/Error.hpp"
#include "CLI/Ini.hpp" #include "CLI/Ini.hpp"
#include "CLI/Macros.hpp"
#include "CLI/Option.hpp" #include "CLI/Option.hpp"
#include "CLI/Split.hpp" #include "CLI/Split.hpp"
#include "CLI/StringTools.hpp" #include "CLI/StringTools.hpp"
@ -447,7 +448,7 @@ class App {
return opt; return opt;
} }
#if __cplusplus >= 201402L #ifdef CLI11_CPP14
/// Add option for callback (C++14 or better only) /// Add option for callback (C++14 or better only)
Option *add_flag(std::string name, Option *add_flag(std::string name,
std::function<void(size_t)> function, ///< A function to call, void(size_t) std::function<void(size_t)> function, ///< A function to call, void(size_t)

View File

@ -8,6 +8,8 @@
#include "CLI/Version.hpp" #include "CLI/Version.hpp"
#include "CLI/Macros.hpp"
#include "CLI/StringTools.hpp" #include "CLI/StringTools.hpp"
#include "CLI/Error.hpp" #include "CLI/Error.hpp"

29
include/CLI/Macros.hpp Normal file
View File

@ -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

View File

@ -13,6 +13,7 @@
#include <vector> #include <vector>
#include "CLI/Error.hpp" #include "CLI/Error.hpp"
#include "CLI/Macros.hpp"
#include "CLI/Split.hpp" #include "CLI/Split.hpp"
#include "CLI/StringTools.hpp" #include "CLI/StringTools.hpp"
@ -299,7 +300,7 @@ class Option : public OptionBase<Option> {
return needs(opt1, args...); return needs(opt1, args...);
} }
#if __cplusplus <= 201703L #ifndef CLI11_CPP17
/// Sets required options \deprecated /// Sets required options \deprecated
Option *requires(Option *opt) { return needs(opt); } Option *requires(Option *opt) { return needs(opt); }