-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi,
On a project I'm working on we need a few of ID classes for various sub
systems. Each ID class (e.g. EntityID, ClassID, PhysicsID, AnimationID)
does exactly the same thing, but we would like to prevent conversion
from different types of IDs (e.g. boost::is_convertible< EntityID,
ClassID >::value is false), to avoid stupid errors.
So far we have come up with to methods for achieving this.
Method 1:
Create a macro called ORG_CREATE_ID_TYPE which takes a class name as an
argument, then when you need a new ID class, you just include the header
where the macro is defined and add
ORG_CREATE_ID_TYPE( MyID )
where you need MyID defined
Method 2:
enum IDTag { EntityIDTag, ClassIDTag, ..., MyIDTag };
template< IDTag T >
class BaseID
{
....
};
typedef BaseID< EntityIDTag > EntityID;
typedef BaseID< ClassIDTag > ClassID;
....
typedef BaseID< MyIDTag > MyID;
The template method is preferred but it is 17% slower to compile, which
given the size of the project and the number of developers is going to
add up to too much time over the next couple of years.
Is there another option I'm overlooking or some techniques you can think
of to make the template method faster?
Thanks in advance.
Cheers,
Tom Howard
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (MingW32)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
iD8DBQFCB++5w1G4ZUM7KZoRArioAJ9ypL+ABKdb4zMeEgfjbb 0VpftgEQCfQKXD
gCi//HEnMUDEkqjC0XWLYs0=
=NEZj
-----END PGP SIGNATURE-----