Hi,
Ok, here's the context. The main purpose is to optimize our processing in an observer pattern. We wanted to have a mechanism to avoid doing costly searches in a map of observers. As you know, searching in a map costs O

. Upon modification of a variable we need to look in the map to see if there is observers for this variable and then notify them. Since we can afford space but need to achieve high performance, we thought we could put a boolean field for each of our variables. Also do macros that would automatically create this boolean field, check and set its value without the developer coding it. But to do it automatically you need to know where it is. So writing the following:
struct myStruct
{
int DEFVAR(iField1);
double DEFVAR(dField2);
int DEFVAR(iField3);
};
would create:
struct myStruct
{
bool b_iField1;
int iField1;
bool b_iField2;
double dField2;
bool b_iField3;
int iField3;
};
So with a macro SET(var, value) I can check automatically if the bool is true and then call inform other observers. That way, I managed to save processing time because the majority of the time, there will be no observers.
The problem is that you can`t only do &iField1 - sizeof(bool) to automatically reference the boolean field because of alignment issues. You cannot be sure if it will be just beside. And using the PACKED keyword is very unefficient since the processor needs more instructions to load the data. And the keyword here is performance...
So this takes us to the typelists. Using typelists we could define something like...
// Create a holder
template <class T>
struct Holder
{
T value;
bool b_observed;
};
// Create a typelist.
typedef GenScatterHierarchy<
TYPELIST_4(int,double,int),
Holder>
VariablesList;
VariableList myList;
So when we modify the value of a variable we automatically have the bool associated with it. So the SET macro would create something like
Field<0>(l_myList).value = 4;
if (Field<0>(l_myList).b_observed == true)
{
inform(.....);
}
This actually works until you want to have variable indexes like
void foo(int variableNumberToModify)
{
Field<variableNumberToModify>(l_myList).value = 4;
if (Field<variableNumberToModify>(l_myList).b_observed == true)
{
inform(.....);
}
}
So that`s why we would need to have the possibility to have variable indexes. In fact, we only want to create a container for values of different types.
I thought it could be possible. I've looked into loki`s code but I have limited capability with template programming.

( And besides, if someone knows somebody of code provide an advance templated/meta-programming course I would like to know. Are currently seeking a C++ template specialist to give my team a training.
If you have an idea, feel free to send it, I'd be more than glad to discuss it. ;o)
Have a nice day.
Frank