Boost logo

Boost :

From: Arkadiy Vertleyb (vertleyb_at_[hidden])
Date: 2004-07-22 21:46:39


"Jody Hagins" <jody-boost-011304_at_[hidden]> wrote
> Matt Hurd <matt.hurd_at_[hidden]> wrote:
>
> > Yes it is when you call it a UUID.
> >
> > Here is an example of a somewhat portable one:
> >
http://www.dre.vanderbilt.edu/Doxygen/Current/html/ace/UUID_8h-source.html
> >
> > Certainly clumsier than a size_t.
>
>
> There are many portable versions of creating a UUID, but I would imagine
> that one would have to be available at compile time to make use of it in
> templates. I think M$ compilers provide this as a preprocessor
> extension, but I am not sure about any others.

What I rally meant was to piggiback on the tool. Recall guidgen, that MS
provides, can generate something like this:

// {DCC34F20-AEE3-4e2f-B2CE-A6FA9ED6AE05}
DEFINE_GUID(<<name>>,
0xdcc34f20, 0xaee3, 0x4e2f, 0xb2, 0xce, 0xa6, 0xfa, 0x9e, 0xd6, 0xae, 0x5);

Every MS programmer is used to doing this to create COM objects.

The compile-time version can be easily implemented, something like:

template<long, short, short, char, char, char, char, char, char, char, char>
struct uuid;

The user then would instantiate it just copy-pasting the stuff generated by
the tool:

uuid<0xdcc34f20, 0xaee3, 0x4e2f, 0xb2, 0xce, 0xa6, 0xfa, 0x9e, 0xd6, 0xae,
0x5>,

and here we have a unique type.

Now, this is not a brainer to create a unique type, and everybody is used to
doing this, but the advantage of this one is in that it can be split into
four integers, and later re-created. Therefore it can be passed via sizeof,
and therefore it can be used in the typeof implementation.

Having said all this, I don't actually believe it's a good idea to make poor
compilers operate on four integers where one is enough. The compilers are
already stressed beyond any reasonable measure by all our meta-programming
excersises. And I believe this particular place is kind of bottleneck in my
implementation...

Arkadiy


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk