Forum: PC-Programmierung C++17: Typ-List in Matrix expanden und an template Funktion


von cppbert (Gast)


Lesenswert?

C++17 VStudio 2017/oder gcc/clang
1
  template <typename First, typename Second>
2
  void test_combination( void* data_ )
3
  {
4
     //test code
5
  }
6
7
  void test_combinations(void* data_)
8
  {
9
    //muss kein tuple sein - koennte auch direkt als
10
    //Variadic hier drin stehen
11
    using All_types = std::tuple<int,Test,float,Blub/*,...*/>;
12
13
    test_combination(...)
14
  }

jetzt wuerde ich gerne die test_combination so instanzieren das ich alle 
Typ -Kombinationen durchlaufen

also

test_combinations(...)

  expandiert zu

test_combination<int,int>(data)
test_combination<int,Test>(data)
test_combination<int,float>(data)
test_combination<int,Blub>(data)
test_combination<int,...>(data)
test_combination<Test,int>(data)
test_combination<Test,Test>(data)
test_combination<Test,float>(data)
test_combination<Test,Blub>(data)
test_combination<Test,...>(data)
...

von cppbert (Gast)


Lesenswert?

habs so geloest - geht das noch kuerzer?
1
template <typename First, typename Second>
2
void test_combination( void* data_ )
3
{
4
   //test code
5
}
6
7
template <typename First, typename... Types>
8
void test_combination_helper2( void* data_ )
9
{
10
  ( ( test_combination<First, Types>( data_ ) ), ... );
11
}
12
13
template <typename... Types>
14
void test_combination_helper1( void* data_ )
15
{
16
  ( ( test_combination_helper2<Types, Types...>(data_) ), ... );
17
}
18
19
void test_combinations( void* data_ )
20
{
21
  test_combination_helper1<int,Test,float,Blub/*,...*/>( data_ );
22
}

von Hannes W. (hannes_w129)


Lesenswert?

Ich denke nicht, dass das kürzer geht. So habe ich das damals (C++14?) 
gelöst: 
https://github.com/hannesweisbach/atlas-rt/blob/master/atlas/tests/interface/type_list.h

Ich würde vermutlich die Testmatrix nicht mehr generieren lassen; das 
ist einfach nicht wartbar.

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.