11#include < catch.hpp>
22#include < ut/pack_loops/pack_loops.hpp>
33
4+ #include < type_traits>
5+
46template <typename ... T>
57void loopOverArgs (T... args) {
68 int count = 0 ;
@@ -65,6 +67,52 @@ void loopOverParameterPackContinue() {
6567 REQUIRE (count == 4 );
6668}
6769
70+ template <typename ... Ts>
71+ void loopOverTypes () {
72+ int count = 0 ;
73+ int float_count = 0 ;
74+ UT_PACK_FOR_T (I, Ts, {
75+ count++;
76+ if constexpr (std::is_same_v<I, float >) {
77+ float_count++;
78+ }
79+ });
80+ REQUIRE (count == 4 );
81+ REQUIRE (float_count == 2 );
82+ }
83+
84+ template <typename ... Ts>
85+ void loopOverTypesBreak () {
86+ int count = 0 ;
87+ int float_count = 0 ;
88+ UT_PACK_FOR_T (I, Ts, {
89+ count++;
90+ if constexpr (std::is_same_v<I, float >) {
91+ float_count++;
92+ } else if constexpr (std::is_same_v<I, double >) {
93+ UT_PACK_BREAK;
94+ }
95+ });
96+ REQUIRE (count == 4 );
97+ REQUIRE (float_count == 2 );
98+ }
99+
100+ template <typename ... Ts>
101+ void loopOverTypesContinue () {
102+ int count = 0 ;
103+ int float_count = 0 ;
104+ UT_PACK_FOR_T (I, Ts, {
105+ if constexpr (std::is_same_v<I, float >) {
106+ float_count++;
107+ } else if constexpr (std::is_same_v<I, double >) {
108+ UT_PACK_CONTINUE;
109+ }
110+ count++;
111+ });
112+ REQUIRE (count == 4 );
113+ REQUIRE (float_count == 2 );
114+ }
115+
68116template <typename ... T>
69117int indexArgs (T... args) {
70118 return UT_PACK_IDX (args, 2 );
@@ -90,6 +138,12 @@ TEST_CASE("pack for loop", "[pack_loops]") {
90138 loopOverParameterPackContinue<0 , -100 , 1 , -100 , 2 , -100 , 3 >();
91139}
92140
141+ TEST_CASE (" type pack for loop" , " [pack_loops]" ) {
142+ loopOverTypes<int , float , double , float >();
143+ loopOverTypesBreak<int , float , float , double , float , int >();
144+ loopOverTypesContinue<int , float , double , float , int >();
145+ }
146+
93147TEST_CASE (" pack index" , " [pack_loops]" ) {
94148 REQUIRE (indexArgs (0 , 0 , 3 , 0 ) == 3 );
95149 REQUIRE (indexAndModifyArgs (0 , 0 , 3 , 0 ) == 4 );
0 commit comments