-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
define precondition macro and violation handler
- Loading branch information
Showing
8 changed files
with
124 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#include <stdexcept> | ||
|
||
#define MDSPAN_PRECONDITION_VIOLATION_HANDLER(cond, file, line) \ | ||
do { \ | ||
throw std::logic_error{"precondition failure"}; \ | ||
} while (0); | ||
|
||
#include <mdspan/mdspan.hpp> | ||
#include <gtest/gtest.h> | ||
|
||
TEST(mdspan_macros, alternate_precondition_violation_handler) | ||
{ | ||
ASSERT_THROW(MDSPAN_PRECONDITION(false), std::logic_error); | ||
} | ||
|
||
TEST(mdspan_macros, alternate_precondition_check_constexpr_invocable) | ||
{ | ||
struct fn | ||
{ | ||
constexpr auto operator()() const | ||
{ | ||
MDSPAN_PRECONDITION(1 + 1 == 2); | ||
return 42; | ||
} | ||
}; | ||
|
||
static constexpr auto x = fn{}(); | ||
(void)x; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include <mdspan/mdspan.hpp> | ||
#include <gtest/gtest.h> | ||
|
||
TEST(mdspan_macros, precondition_violation) | ||
{ | ||
constexpr auto msg = "hello, world!"; | ||
|
||
ASSERT_DEATH(MDSPAN_PRECONDITION(false and "hello, world!"), msg); | ||
} | ||
|
||
TEST(mdspan_macros, precondition_check_constexpr_invocable) | ||
{ | ||
struct fn | ||
{ | ||
constexpr auto operator()() const | ||
{ | ||
MDSPAN_PRECONDITION(1 + 1 == 2); | ||
return 42; | ||
} | ||
}; | ||
|
||
static constexpr auto x = fn{}(); | ||
(void)x; | ||
} |