index-sequence

Expand std::vector into parameter pack

北城以北 提交于 2020-01-16 01:15:29
问题 I have methods with the following signature: void DoStuff(int i); void DoStuff(int i, k); void DoStuff(int i, int k, int l); I have a method from where I would like to call the DoStuff methods as follows: void CallDoStuff(const std::vector<int>& vElements) { // What magic is supposed to happen here to make vElements an expandable pack? DoStuff(vElemets...); } Is there any chance to achieve this? Is using std::index_sequence the right way? If yes, could you please provide me a simple example

How to iterate over std::index_sequence

旧街凉风 提交于 2019-12-22 09:49:00
问题 I have this code in my source: template <std::size_t... Dims> class DimensionPack { public: using Dimensions = std::index_sequence<Dims...>; static const std::size_t total_dimensions = sizeof...(Dims); std::vector<unsigned int> even_or_odd; public: DimensionPack() { unsigned idx = 0; for ( ; idx < total_dimensions; idx++ ) { //MatrixDimensionOddOrEven mdoe( Dimensions[idx] ); //unsigned int val = mdoe.even_or_odd; //even_or_odd.push_back( val ); } } }; The commented lines of code is the code