#include "catch_tmp.h" #include using namespace tmp; namespace { template struct UInt { static constexpr unsigned value = N; }; template struct IdentityImpl { using type = T; }; template using Identity = typename IdentityImpl::type; template struct UnpackImpl; template struct UnpackImpl> { using type = T; }; template using Unpack = typename UnpackImpl::type; template struct SizeofImpl { using type = UInt; }; template using Sizeof = typename SizeofImpl::type; template using Merge = PackCat; template struct USumImpl { using type = UInt; }; template using USum = typename USumImpl::type; template struct IsEven: std::integral_constant {}; } TEST_CASE("Transform") { SECTION("empty input") { using Result = Transform, Identity>; REQUIRE_SAME(Pack<>, Result); } using Input0 = Pack, Pack, Pack>; using Input1 = Pack; SECTION("Identity") { REQUIRE(std::is_same>{}); REQUIRE(std::is_same>{}); } SECTION("Unpack") { using Expected = Pack; using Result = Transform; REQUIRE_SAME(Expected, Result); } SECTION("Sizeof") { using Expected = Pack, UInt, UInt, UInt, UInt, UInt>; using Result = Transform; REQUIRE_SAME(Expected, Result); } } TEST_CASE("Accumulate") { SECTION("empty input") { using Result = Accumulate, PackCat, void>; REQUIRE_SAME(void, Result); } using Input0 = Pack, Pack, Pack>; using Input1 = Pack; SECTION("PackCat") { using Expected = Pack; using Result = Accumulate>; REQUIRE_SAME(Expected, Result); } SECTION("USum") { using Expected = UInt; using Result = Accumulate, USum, UInt<>>; REQUIRE_SAME(Expected, Result); } } TEST_CASE("Filter") { SECTION("empty input") { using Expected = Pack<>; using Result = Filter, IsEven>; REQUIRE_SAME(Expected, Result); } SECTION("empty output") { using Input = Pack, UInt<3>, UInt<3>, UInt<5>, UInt<5>, UInt<7>>; using Expected = Pack<>; using Result = Filter; REQUIRE_SAME(Expected, Result); } SECTION("general case") { using Input = Pack, UInt<2>, UInt<3>, UInt<4>, UInt<5>, UInt<6>>; using Expected = Pack, UInt<4>, UInt<6>>; using Result = Filter; REQUIRE_SAME(Expected, Result); } } TEST_CASE("Cut") { SECTION("empty input") { using Expected = Pack, Pack<>>; using Result = Cut, IsEven>; REQUIRE_SAME(Expected, Result); } SECTION("empty left output") { using Input = Pack, UInt<3>, UInt<3>, UInt<5>, UInt<5>, UInt<7>>; using Expected = Pack, Input>; using Result = Cut; REQUIRE_SAME(Expected, Result); } SECTION("empty right output") { using Input = Pack, UInt<4>, UInt<4>, UInt<6>, UInt<6>, UInt<8>>; using Expected = Pack>; using Result = Cut; REQUIRE_SAME(Expected, Result); } SECTION("general case") { using Input = Pack, UInt<2>, UInt<3>, UInt<3>, UInt<5>, UInt<7>>; using Expected = Pack, UInt<2>>, Pack, UInt<3>, UInt<5>, UInt<7>>>; using Result = Cut; REQUIRE_SAME(Expected, Result); } } TEST_CASE("Reverse") { SECTION("empty input") { REQUIRE_SAME(Pack<>, Reverse>); } SECTION("one element") { REQUIRE_SAME(Pack, Reverse>); } SECTION("general case") { using Input = Pack; using Expected = Pack; using Result = Reverse; REQUIRE_SAME(Expected, Result); } }