Ich versuche gerade den Wert N aus einem Parameter-Pack mit einer
statischen Methode in einem Tuple an Stelle N aufzurufen (siehe
many::xyz) - ich habe aber keine Idee wie ich in C++17 elegant das
Mapping mache
jemand einen Tip?
gcc-godbolt: https://gcc.godbolt.org/z/K4vE4E
1 | #include <tuple>
|
2 |
|
3 | template<typename ValueType>
|
4 | struct single
|
5 | {
|
6 | static int xyz(const ValueType& value_)
|
7 | {
|
8 | // nur als Beispiel, ich habe
|
9 | // Spezialisierungen fuer Typen die
|
10 | // hier Berechnungen,usw. machen
|
11 | return sizeof(value_);
|
12 | }
|
13 | };
|
14 |
|
15 | template <typename... ValueType>
|
16 | class many
|
17 | {
|
18 | public:
|
19 | using Singles = std::tuple<single<ValueType>...>;
|
20 |
|
21 | static int xyz( const ValueType&... value_ )
|
22 | {
|
23 | int result = 0;
|
24 | //for(...)
|
25 | // result += Singles[I]::xyz(value_[I])
|
26 |
|
27 | //Ich vermute das ich was
|
28 | //mit std::integer_sequence machen muss
|
29 |
|
30 | return result;
|
31 | }
|
32 | };
|
33 |
|
34 | using Many = many<int,float,short/*,std::string,....*/>;
|
35 |
|
36 | int main()
|
37 | {
|
38 | int x = Many::xyz(1,3.2f,2/*,"hallo",...*/);
|
39 | // sollte auf meiner Platform gerade 4+4+2 Ergeben
|
40 | return 0;
|
41 | }
|
in einem anderen Test habe ich die Values
direkt mit in dem single, statefull mit Members, nix statisch
1 | int xyz() const
|
2 | {
|
3 | auto sum = []( auto&... single ) { return ( single.xyz() + ... ); };
|
4 | auto result = std::apply( sum, m_singles );
|
5 | return result;
|
6 | }
|
funktioniert auch aber ich moechte das single eigentlich stateless und
voll statisch bekommen