L
Leon
Hi all.
I'm using a thrid-party software library that uses two tag classes (Tag_true
and Tag_false) to flag if certain operations are available in a (template)
class.
Now I think the idea behind them is to be able to perform compile-time
checks, but I don't understand how...
These tag classes are defined as empty structs, i.e.:
struct Tag_true {};
struct Tag_false {};
Now, in a class definition they use the following construction:
class Fixed_precision_nt{
public:
typedef Tag_false Has_gcd;
typedef Tag_true Has_division;
typedef Tag_false Has_sqrt;
//<snip>
};
indicating that this class supports division, but not square root or gcd
calculation. In my application, I want to be able to perform compile-time
tests on these tags, something like this:
#define Fixed_precision_nt scalar
//<snip>
#if scalar::Has_gcd == Tag_true
//...
#endif
What is the proper way of doing this? When I try to compile the above code,
it
complains on the '#if' line with "unexpected tokens following preprocessor
directive - expected a newline". What am I doing wrong?
Thanks,
Leon.
I'm using a thrid-party software library that uses two tag classes (Tag_true
and Tag_false) to flag if certain operations are available in a (template)
class.
Now I think the idea behind them is to be able to perform compile-time
checks, but I don't understand how...
These tag classes are defined as empty structs, i.e.:
struct Tag_true {};
struct Tag_false {};
Now, in a class definition they use the following construction:
class Fixed_precision_nt{
public:
typedef Tag_false Has_gcd;
typedef Tag_true Has_division;
typedef Tag_false Has_sqrt;
//<snip>
};
indicating that this class supports division, but not square root or gcd
calculation. In my application, I want to be able to perform compile-time
tests on these tags, something like this:
#define Fixed_precision_nt scalar
//<snip>
#if scalar::Has_gcd == Tag_true
//...
#endif
What is the proper way of doing this? When I try to compile the above code,
it
complains on the '#if' line with "unexpected tokens following preprocessor
directive - expected a newline". What am I doing wrong?
Thanks,
Leon.