Extraction from func(char* cfg, ...)

Most of the time I ask for tutorial pages or advice but this time I think I'd learn better from getting a working function and dissecting how it works (I have made an attempt myself but doubt it very much but I'll find out when I can compile tomorrow).
So I want a function which will take 2 format strings, a typename and then anything using the "..." tag. The idea is to supply the function with a full format string, a sub format which indicates the variable to be extracted, the typename to return the variable as, and the dump of data...
My first thoughts are something like this...

template<typename T> T extract(std::string full_cfg, std::string search_cfg, typename type, ...)

I can't upload the body until I'm on the PC tomorrow but the body is mainly my problem, because using ... is rather complicated I wanted a sample if anyone could be so kind?
( This is straight from http://www.cplusplus.com/reference/cstdarg/va_arg/ )

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/* va_arg example */
#include <stdio.h>      /* printf */
#include <stdarg.h>     /* va_list, va_start, va_arg, va_end */

int FindMax (int n, ...)
{
  int i,val,largest;
  va_list vl;
  va_start(vl,n);
  largest=va_arg(vl,int);
  for (i=1;i<n;i++)
  {
    val=va_arg(vl,int);
    largest=(largest>val)?largest:val;
  }
  va_end(vl);
  return largest;
}

int main ()
{
  int m;
  m= FindMax (7,702,422,631,834,892,104,772);
  printf ("The largest value is: %d\n",m);
  return 0;
}


It's pretty simple, really. Include cstdarg, make a va_list variable, call va_start, use va_arg to get the next item. Call va_end before the function exits.

I'm not sure if this is actually what you want to do here though. Would you mind explaining what this function is supposed to be doing a bit more?
Topic archived. No new replies allowed.