Re: how to compare the sizes of 2 structures at compile time
From: Victor Bazarov (v.Abazarov_at_comAcast.net)
Date: 07/09/04
- Next message: Victor Bazarov: "Re: why the compiler gives me this warning"
- Previous message: Irish4Arm: "Re: class template member functions"
- In reply to: paul_at_slowmind.com: "how to compare the sizes of 2 structures at compile time"
- Next in thread: Norm Dresner: "Re: how to compare the sizes of 2 structures at compile time"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 09 Jul 2004 14:38:01 -0400
paul@slowmind.com wrote:
> I have 2 structures _test1 and _test2. At compile time, I want the compiler to issue an error if
> sizeof( _test1 ) != sizeof( _test2)
You can probably do it using templates:
template<bool trueorfalse> struct If;
template<> struct If<true> { enum { satisfied }; };
template<> struct If<false> { enum { notsatisfied }; };
int a, b;
double c, d;
int main()
{
If<sizeof(a) == sizeof(b)>::satisfied;
If<sizeof(c) == sizeof(a)>::satisfied; // will get "satisfied" is not
// a member" error message
return 0;
}
Should work for structs just as well.
Victor
- Next message: Victor Bazarov: "Re: why the compiler gives me this warning"
- Previous message: Irish4Arm: "Re: class template member functions"
- In reply to: paul_at_slowmind.com: "how to compare the sizes of 2 structures at compile time"
- Next in thread: Norm Dresner: "Re: how to compare the sizes of 2 structures at compile time"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|