From 018673a0a4061a87c50bd40856106afe55f3c6e9 Mon Sep 17 00:00:00 2001 From: neargye Date: Sat, 9 Oct 2021 02:22:59 +0300 Subject: [PATCH] add tests constexpr_for --- test/test.cpp | 22 ++++++++++++++++++++++ test/test_flags.cpp | 18 ++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/test/test.cpp b/test/test.cpp index a464f05..dd8b54d 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -973,3 +973,25 @@ TEST_CASE("cmp_less") { REQUIRE(cmp_less(-1, false)); } } + +// from https://artificial-mind.net/blog/2020/10/31/constexpr-for +template +constexpr void constexpr_for(F&& f) { + if constexpr (Start < End) { + f(std::integral_constant()); + constexpr_for(f); + } +} + +template +struct Foo {}; + +TEST_CASE("constexpr_for") { + constexpr_for<0, magic_enum::enum_count(), 1>([](auto i) { + [[maybe_unused]] Foo()> bar{}; + }); + + constexpr_for<0, magic_enum::enum_count(), 1>([](auto i) { + [[maybe_unused]] Foo()> bar{}; + }); +} diff --git a/test/test_flags.cpp b/test/test_flags.cpp index a3f8ea8..f6be44c 100644 --- a/test/test_flags.cpp +++ b/test/test_flags.cpp @@ -690,3 +690,21 @@ TEST_CASE("bitwise_operators") { #endif } } + +// from https://artificial-mind.net/blog/2020/10/31/constexpr-for +template +constexpr void constexpr_for(F&& f) { + if constexpr (Start < End) { + f(std::integral_constant()); + constexpr_for(f); + } +} + +template +struct Foo {}; + +TEST_CASE("constexpr_for") { + constexpr_for<0, magic_enum::enum_count(), 1>([](auto i) { + [[maybe_unused]] Foo()> bar{}; + }); +} \ No newline at end of file