Skip to content

Commit

Permalink
Merge pull request #4 from zeus-cpp/fix-msvc
Browse files Browse the repository at this point in the history
Drop the requirement of `/Zc:__cplusplus`
  • Loading branch information
X1aomu authored Apr 18, 2024
2 parents c66b443 + 6d7de9c commit f0c070d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ Feedbacks are welcome.

Table of known compiler status.

| Planned | Status | Note |
| ------------------- | --------------- | ----------------------------- |
| MSVC v142 and later | Fully tested | `/Zc:__cplusplus` is required |
| GCC 8 and later | Slightly tested | |
| Planned | Status |
| ------------------- | --------------- |
| MSVC v142 and later | Fully tested |
| GCC 8 and later | Slightly tested |

## Building and testing

Expand Down
12 changes: 9 additions & 3 deletions include/zeus/expected.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,17 @@
#define ZEUS_EXPECTED_VERSION_MINOR 0
#define ZEUS_EXPECTED_VERSION_PATCH 2

#if __cplusplus < 201'703L
#if defined(_MSVC_LANG)
#define ZEUS_EXPECTED_CPLUSPLUS _MSVC_LANG
#else
#define ZEUS_EXPECTED_CPLUSPLUS __cplusplus
#endif

#if ZEUS_EXPECTED_CPLUSPLUS < 201'703L
static_assert(false, "This expected variant requires C++17");
#endif

#if __cplusplus >= 202'002L
#if ZEUS_EXPECTED_CPLUSPLUS >= 202'002L
#define ZEUS_EXPECTED_CONSTEXPR_DTOR constexpr
#else
#define ZEUS_EXPECTED_CONSTEXPR_DTOR
Expand Down Expand Up @@ -53,7 +59,7 @@ namespace expected_detail
template<class T, class... Args>
constexpr T *construct_at(T *p, Args &&...args) noexcept(noexcept(::new (static_cast<void *>(p)) T(std::forward<Args>(args)...)))
{
#if __cplusplus >= 202'002L
#if ZEUS_EXPECTED_CPLUSPLUS >= 202'002L
return std::construct_at(p, std::forward<Args>(args)...);
#else
return ::new (static_cast<void *>(p)) T(std::forward<Args>(args)...);
Expand Down
5 changes: 0 additions & 5 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,2 @@
if (MSVC)
add_compile_options(/Zc:__cplusplus)
add_compile_options(/W4)
endif ()

add_subdirectory(test_expected)
add_subdirectory(third_party)
1 change: 1 addition & 0 deletions tests/test_expected/base_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <string>
#include <optional>

#include <catch2/catch_all.hpp>

Expand Down

0 comments on commit f0c070d

Please sign in to comment.