I couldn’t find an answer to my problem so I post it as a question. I make a small dummy example to explain it:
enum STORAGE_TYPE
{
CONTIGUOUS,
NON_CONTIGUOUS
};
template <typename T, STORAGE_TYPE type=CONTIGUOUS>
class Data
{
public:
void a() { return 1; }
};
// partial type specialization
template <typename T>
class Data<T, NON_CONTIGUOUS>
{
public:
void b() { return 0; }
};
// this method should accept any Data including specializations…
template <typename T, STORAGE_TYPE type>
void func(Data<T, type> &d)
{
/* How could I determine statically the STORAGE_TYPE? */
#if .. ??
d.a();
#else
d.b();
#endif
}
int main()
{
Data<int> d1;
Data<int, NON_CONTIGUOUS> d2;
func(d1);
func(d2);
return 0;
}
Please note that
(1) I do not want a specialization of “func”, as that could solve it but I just want to have 1 generic method “func” with internal static “if” conditions to execute the code.
(2) and I would prefer solution with standard C++ (not C++0x or boost).
Use traits technique: