Commit ed382bff authored by Michaël Roynard's avatar Michaël Roynard
Browse files

Implement tool + doc

parent dd014585
Pipeline #1941 passed with stage
in 1 minute and 38 seconds
[![pipeline status](https://gitlab.lrde.epita.fr/mroynard/gtest-constexpr-ext/badges/master/pipeline.svg)](https://gitlab.lrde.epita.fr/mroynard/gtest-constexpr-ext/commits/master) [![coverage report](https://gitlab.lrde.epita.fr/mroynard/blackmagic/badges/master/coverage.svg)](https://gitlab.lrde.epita.fr/mroynard/gtest-constexpr-ext/commits/master)
Add macro to detect whether an expression is compile-time.
Add and integrate macros to gtest detect whether an expression is compiletime or runtime.
Example :
```cpp
#include <gtest-constexpr-ext/gtest-constexpr-ext.hpp>
template <auto B>
constexpr void f(int b) {
if (!B && b != 0) {
throw "Runtime!"
} else {
return 42; // Compiletime!
}
}
TEST(MyTestSuite, MyTest) {
ASSERT_COMPILETIME_EXPR(f<true>, 1);
ASSERT_RUNTIME_EXPR(f<false>, 1);
ASSERT_RUNTIME_EXPR(f<true>, 0);
}
```
......@@ -6,16 +6,27 @@ constexpr int f(int a) {
if (a == 0) {
throw "Runtime!";
} else {
return a;
return a; // Compiletime!
}
}
template <auto V>
constexpr int ft(int a) {
if (V) {
return a; // Compiletime!
} else {
throw "Runtime!";
}
}
TEST(Gtest_Constexpr_Ext, Compiletime)
{
ASSERT_COMPILETIME_EXPR(f, 1);
ASSERT_COMPILETIME_EXPR(ft<true>, 1);
}
TEST(Gtest_Constexpr_Ext, Runtime)
{
ASSERT_RUNTIME_EXPR(f, 0);
ASSERT_RUNTIME_EXPR(ft<false>, 1);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment