Skip to content

Commit

Permalink
detect C++17 mode in MSVC (#3555)
Browse files Browse the repository at this point in the history
  • Loading branch information
conradsnicta committed Oct 29, 2023
1 parent 5e8a27d commit 4df75cc
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
2 changes: 2 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

* Use HTTPS for all auto-downloaded dependencies (#3550).

* More robust detection of C++17 mode in the MSVC "compiler" (#3555).

### mlpack 4.2.1
###### 2023-09-05
* Reinforcement Learning: Gaussian noise (#3515).
Expand Down
37 changes: 25 additions & 12 deletions src/mlpack/base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,23 +68,36 @@
#define mlpack_force_inline __forceinline
#endif
// Backport std::any from C+17 to C++11 to replace boost::any.
// Use mnmlstc backport implementation only if compiler does not
// support C++17.
#if __cplusplus < 201703L && !defined(_MSC_VER)
#include <mlpack/core/std_backport/any.hpp>
#include <mlpack/core/std_backport/string_view.hpp>
#define MLPACK_ANY core::v2::any
#define MLPACK_ANY_CAST core::v2::any_cast
#define MLPACK_STRING_VIEW core::v2::string_view
#elif __cplusplus < 201703L && defined(_MSC_VER)
#error "When using Visual Studio, mlpack should be compiled with /Zc:__cplusplus and /std:c++17 or newer."
#else
// detect C++17 mode
#if (__cplusplus >= 201703L)
#undef MLPACK_HAVE_CXX17
#define MLPACK_HAVE_CXX17
#endif
#if defined(_MSVC_LANG)
#if (_MSVC_LANG >= 201703L)
#undef MLPACK_HAVE_CXX17
#define MLPACK_HAVE_CXX17
#endif
#endif
#if defined(MLPACK_HAVE_CXX17)
#include <any>
#include <string_view>
#define MLPACK_ANY std::any
#define MLPACK_ANY_CAST std::any_cast
#define MLPACK_STRING_VIEW std::string_view
#elif defined(_MSC_VER)
#error "When using Visual Studio, mlpack should be compiled with /std:c++17 or newer."
#else
// Backport std::any from C+17 to C++11 to replace boost::any.
// Use mnmlstc backport implementation only if compiler does not
// support C++17.
#include <mlpack/core/std_backport/any.hpp>
#include <mlpack/core/std_backport/string_view.hpp>
#define MLPACK_ANY core::v2::any
#define MLPACK_ANY_CAST core::v2::any_cast
#define MLPACK_STRING_VIEW core::v2::string_view
#endif
// Now include Armadillo through the special mlpack extensions.
Expand Down

0 comments on commit 4df75cc

Please sign in to comment.