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

Gast #6798148
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)
...
Gast #6798498
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
}

Antwort schreiben

Hinweis: der ursprüngliche Beitrag ist mehr als 6 Monate alt. Bitte hier nur auf die ursprüngliche Frage antworten, für neue Fragen einen neuen Beitrag erstellen.

Formatierung
  • [c]C-Code[/c]
  • [code]Code in anderen Sprachen, ASCII-Zeichnungen[/code]
  • [math]Formel in LaTeX-Syntax[/math]
  • [[Titel]] – Link zu einem Artikel
  • Verweis auf einen anderen Beitrag: Rechtsklick auf dessen Beitrags-ID (#8078628), „Adresse kopieren“, in den Text einfügen

Mehr zur Formatierung

Längeren Sourcecode als Anhang, nicht in den Text. JPG nur für Fotos und Scans; Zeichnungen und Screenshots als PNG oder GIF. Siehe Bildformate.

Schon registriert? Anmelden

Wird nicht angezeigt. Wir schicken dir einen Link; sobald du damit bestätigst, erscheint dein Beitrag.

Mit dem Abschicken legst du einen kostenlosen Account an und erkennst die Nutzungsbedingungen und die Datenschutzerklärung an.