Question: I am trying to implement this summation, any help, please?
[enter image description here](https://i.stack.imgur.com/Arfdl.png)

Answer: 
As I understand, you might have:

```
template <typename... Ts>
void parseData(const std::string& data, Ts&... args)
{
    [[maybe_unused]]std::size_t idx = 0;
    ((cpMemReadback(args, data, idx), idx += sizeof (Ts)), ...);
}

```

and then replace

```
cpMemReadback(cmdReadback, data, 0);
cpMemReadback(Speed, data, 4);
cpMemReadback(uSpeed, data, 8);
cpMemReadback(Accel, data, 9);
cpMemReadback(Decel, data, 11);
cpMemReadback(AntiplaySpeed, data, 13);
cpMemReadback(uAntiplaySpeed, data, 17);

```

by

```
parse_data(data,
           cmdReadback,
           Speed,
           uSpeed,
           Accel,
           Decel,
           AntiplaySpeed,
           uAntiplaySpeed);

```
> 
> I know that I'd want to use variadic templates, I presumably need a template parameter to track the index and then a parameter pack for my variables and then recursively execute the code, incrementing my index tracking template parameter.
> 
> 
> 

That's a perfectly valid way to approach this, although tracking `idx` in a template parameter is a bit overkill. Doing it as a regular parameter would be fine as well.

Here's what you had in mind looks like:

```cpp
template<std::size_t idx=0, typename First, typename... Rest>
void parse_data(const std::string& data, First& first, Rest&... rest) {
    // Handle the first element in the list
    cpMemReadback(first, data, idx);

    // Recurse with the rest if there are any
    if constexpr(sizeof...(Rest) > 0) {
      parse_data<idx + sizeof(First)>(data, rest...);
    }
}

```

The only drawback that this has over the other answer's fold-expression + comma operator approach is that it can *theoretically* lead to deeper stacks and slightly larger executable sizes.

I say theoretically because any modern compiler would almost certainly optimise these away in non-0 optimisation levels. So this would only really be a factor if you run this code in debug mode on architectures with aggressive memory constraints.

You can find a demonstration of the difference, and lack thereof in `-O1` here: <https://gcc.godbolt.org/z/xbn35ecc8>